Class: Kitchen::Yansible::Tools::Install::Debian

Inherits:
Kitchen::Yansible::Tools::Install show all
Defined in:
lib/kitchen-yansible/tools/install/debian.rb

Constant Summary

Constants inherited from Kitchen::Yansible::Tools::Install

BINARY_DEFAULT_PREFIX, BINARY_INSTALL_PREFIX

Instance Method Summary collapse

Methods inherited from Kitchen::Yansible::Tools::Install

#ansible_alternatives, #ansible_version, #get_python_version, #initialize, #install_ansible_pip, #install_package, #local_install, make, #pip_required_packages, #pip_version, #python_version_size, #remote_install, #ruby_alternatives, #search_alternatives, #update_path

Methods included from Exec

#check_command, #command_exists, #detect_platform, #execute_local_command, #local_command_exists, #local_command_path, #print_cmd_error, #print_cmd_parameters, #sudo, #sudo_env, #unindent

Constructor Details

This class inherits a constructor from Kitchen::Yansible::Tools::Install

Instance Method Details

#alternatives_commandObject



34
35
36
# File 'lib/kitchen-yansible/tools/install/debian.rb', line 34

def alternatives_command
  "#{sudo('update-alternatives')}"
end

#install_pythonObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/kitchen-yansible/tools/install/debian.rb', line 84

def install_python
  """
    installPython () {
      echo 'Checking Python installation.'
      #{command_exists('python')} || {
        echo 'Python is not installed, attempt to install via virtual packages.'
        #{install_package} python
        echo 'Checking for installed alternatives.'
        #{command_exists('python')} || {
          searchAlternatives 'python'
        }
      }
      #{command_exists('python')} || {
        echo \"===> Couldn't determine Python executable - exiting now! <===\"
        exit 1
      }
    }
  """
end

#install_rubyObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/kitchen-yansible/tools/install/debian.rb', line 128

def install_ruby
  """
    installRuby () {
      echo 'Checking Ruby installation.'
      searchAlternatives 'ruby'
      #{command_exists('ruby')} || {
        RUBY_PACKAGE=$(apt-cache search ruby|grep '^ruby\\([0-9\\.]\\+\\)\\?\\s'|sort -r|head -n1|awk '{print $1}')
        RUBY_VERSION=$(echo ${RUBY_PACKAGE}|grep -o '\\([0-9\\.]\\+\\)')
        dpkg --compare-versions ${RUBY_VERSION} ge 2.2.0 || {
          echo 'Adding ppa:brightbox/ruby-ng'
          #{install_package} ca-certificates
          source /etc/os-release
          if [[ \"${VERSION_ID}\" = \"12.04\" ]]; then
            #{install_package} python-software-properties
          else
            #{install_package} software-properties-common
          fi
          #{sudo('apt-add-repository')} -y ppa:brightbox/ruby-ng
          if [[ \"${VERSION_ID}\" = \"8\" && \"${ID}\" = \"debian\" ]]; then
            #{sudo('sed')} -i 's/jessie/trusty/g' /etc/apt/sources.list.d/brightbox-ruby-ng-jessie.list
          fi
          #{update_cache}
          RUBY_PACKAGE=$(apt-cache search ruby|grep '^ruby\\([0-9\\.]\\+\\)\\?\\s'|sort -r|head -n1|awk '{print $1}')
          RUBY_VERSION=$(echo ${RUBY_PACKAGE}|grep -o '\\([0-9\\.]\\+\\)')
        }
        echo 'Rechecking available versions'
        RUBY_PACKAGE=$(apt-cache search ruby|grep '^ruby\\([0-9\\.]\\+\\)\\?\\s'|sort -r|head -n1|awk '{print $1}')
        RUBY_VERSION=$(echo ${RUBY_PACKAGE}|grep -o '\\([0-9\\.]\\+\\)')
        dpkg --compare-versions ${RUBY_VERSION} ge 2.2.0 || {
          echo \"===> Only ${RUBY_VERSION} which is less than 2.2.0 found. <===\"
          echo \"===> Couldn't find acceptable Ruby version - exiting now! <===\"
          exit 1
        }
        #{install_package} ${RUBY_PACKAGE}

        echo 'Checking for installed alternatives.'
        #{command_exists('ruby')} || {
          searchAlternatives 'ruby'
        }
        grep 'gem: --no-rdoc --no-ri -​-no-document' /etc/gemrc &> /dev/null || {
          #{sudo('echo')} 'gem: --no-rdoc --no-ri -​-no-document' | #{sudo('tee')} /etc/gemrc
        }
      }
      #{command_exists('ruby')} || {
        echo \"===> Couldn't determine Ruby executable - exiting now! <===\"
        exit 1
      }
      echo 'Install Busser'
      #{command_exists('gem')} || {
        #{install_package} rubygems
      }
      #{command_exists('rdoc')} || {
        #{install_package} rubygem-rdoc
      }
      #{sudo('gem')} list | grep busser || {
        #{sudo('gem')} install busser
      }
      test -d /opt/chef/embedded/bin || {
        #{sudo('mkdir')} -p /opt/chef/embedded/bin
      }
      echo 'Making links for Chef'
      for binary in ruby gem busser; do
        test -L /opt/chef/embedded/bin/${binary} || {
          #{sudo('ln')} -sf \"$(command -v ${binary})\" /opt/chef/embedded/bin/${binary}
        }
      done
    }
  """
end

#install_virtualenvObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/kitchen-yansible/tools/install/debian.rb', line 104

def install_virtualenv
  """
    installVirtualenv () {
      echo 'Checking Virtualenv installation.'
      searchAlternatives 'virtualenv'
      #{command_exists('virtualenv')} || {
        echo 'Attempt to guess Virtualenv package.'
        venvPackage=python$(python -c 'import sys; print(\"\".join(map(str, sys.version_info[:#{python_version_size}])))')-virtualenv
        #{install_package} ${venvPackage}||#{install_package} python-virtualenv
        #{install_package} virtualenv

        echo 'Checking for installed alternatives.'
        #{command_exists('virtualenv')} || {
          searchAlternatives 'virtualenv'
        }
      }
      #{command_exists('virtualenv')} || {
        echo \"===> Couldn't install Virtualenv - exiting now! <===\"
        exit 1
      }
    }
  """
end

#package_managerObject



26
27
28
# File 'lib/kitchen-yansible/tools/install/debian.rb', line 26

def package_manager
  "#{sudo_env('apt-get')}"
end

#preinstall_commandObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/kitchen-yansible/tools/install/debian.rb', line 38

def preinstall_command
  """
    preInstall () {
      ## Fix debconf tty warning messages
      export DEBIAN_FRONTEND=noninteractive

      #{update_cache}

      ## https://github.com/neillturner/kitchen-ansible/blob/master/lib/kitchen/provisioner/ansible/os/debian.rb#L43
      ## Install apt-utils to silence debconf warning: http://serverfault.com/q/358943/77156
      ## Install dirmngr to handle GPG key management for stretch,
      ## addressing https://github.com/neillturner/kitchen-ansible/issues/257
      #{install_package} apt-utils dirmngr

      source /etc/os-release
      if [[ \"${ID}\" = \"debian\" && \"${VERSION_ID}\" = \"7\" ]]; then
        echo 'Switching Debian Wheezy to archive repository'
        #{sudo('sed')}  -i -e \"s@deb.\\(debian.org\\)@archive.\\1@g;s@\\(.*updates\\)@#\\1@g\" /etc/apt/sources.list
        PIP_ARGS=\"-i https://pypi.python.org/simple/\"

        #{command_exists('ruby')} || {
          RUBY_VERSION=2.5.7
          echo '============================================================================================'
          echo \"Compiling Ruby ${RUBY_VERSION} because we need Ruby >= 2.2 for Busser\"
          echo \"Please consider custom docker image use with precompiled Ruby for speedup converge actions.\"
          echo '============================================================================================'
          sleep 10
          #{install_package} wget ca-certificates
          #{install_package} --force-yes libssl1.0.0=1.0.1e-2+deb7u20 \\
            libc6=2.13-38+deb7u10 \\
            libc-bin=2.13-38+deb7u10 \\
            zlib1g-dev libssl-dev libreadline-dev libgdbm-dev \\
            patch gcc make libreadline-dev
          mkdir -p /tmp/ruby && cd /tmp/ruby
          wget -qO- https://cache.ruby-lang.org/pub/ruby/$(echo ${RUBY_VERSION}|cut -c 1-3)/ruby-${RUBY_VERSION}.tar.gz|tar -xz \\
            && cd /tmp/ruby/ruby-${RUBY_VERSION}
          ./configure --disable-install-rdoc && make
          #{sudo('make')} install
          #{ruby_alternatives('/usr/bin', "/usr/local/bin")}
          rm -rf /tmp/ruby
        }
      fi
    }
  """
end

#update_cacheObject



30
31
32
# File 'lib/kitchen-yansible/tools/install/debian.rb', line 30

def update_cache
  "#{package_manager} update"
end