Class: Kitchen::Yansible::Tools::Install::RHEL

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

Direct Known Subclasses

Amazon, Fedora

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

#alternatives_command, #ansible_alternatives, #ansible_version, #get_python_version, #initialize, #install_ansible_pip, #install_package, #local_install, make, #package_manager, #pip_required_packages, #pip_version, #python_version_size, #remote_install, #ruby_alternatives, #search_alternatives, #update_cache, #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

#install_pythonObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/kitchen-yansible/tools/install/rhel.rb', line 125

def install_python
  """
    installPython () {
      echo 'Checking Python installation.'
      searchAlternatives 'python'
      #{command_exists('python')} || {
        echo 'Python is not installed, attempt to use package manager.'
        package=$(#{package_manager} search -q python|grep '^python\\([0-9\\.]\\+\\)\\?\\.'|sort -r|head -n1|awk '{print $1}')
        echo \"Will try to install '${package}' package.\"
        #{install_package} ${package}
        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



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
# File 'lib/kitchen-yansible/tools/install/rhel.rb', line 148

def install_ruby
  """
    installRuby () {
      echo 'Checking Ruby installation.'
      searchAlternatives 'ruby'
      #{command_exists('ruby')} || {
        echo 'Ruby is not installed, attempt to use package manager.'
        package=$(#{package_manager} search -q ruby 2> /dev/null|grep '^ruby\\([0-9\\.]\\+\\)\\?\\.'|sort -r|head -n1|awk '{print $1}')
        echo \"Will try to install '${package}' package.\"
        #{install_package} ${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



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/kitchen-yansible/tools/install/rhel.rb', line 193

def install_virtualenv
  """
    installVirtualenv () {
      echo 'Checking Virtualenv installation.'
      searchAlternatives 'virtualenv'
      #{command_exists('virtualenv')} || {
        echo 'Virtualenv is not installed, will try to guess its name.'
        if [ $(#{package_manager} search virtualenv|grep '^python.*-virtualenv'|wc -l) -gt 1 ]; then
          venvPackage=python$(#{get_python_version})-virtualenv
          echo \"Will try to install '${venvPackage}' package.\"
          #{install_package} ${venvPackage}
        else
          echo \"Installing via virtual package.\"
          #{install_package} python-virtualenv
        fi

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

#preinstall_commandObject



26
27
28
29
30
31
32
33
34
35
36
37
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/kitchen-yansible/tools/install/rhel.rb', line 26

def preinstall_command
  """
    #{update_path}
    #{update_cache}

    installPackage () {
      package=$1
      #{package_manager} -q info ${package} 2>/dev/null|grep installed &>/dev/null || #{install_package} ${package}
    }

    enableSCLPackage () {
      package=$1
      echo \"Enable ${package}\"
      grep \"/opt/rh/${package}/enable\" /etc/profile.d/${package}.sh &> /dev/null || {
        #{sudo('echo')} \"source /opt/rh/${package}/enable\"| #{sudo('tee')} -a /etc/profile.d/${package}.sh
      }
      source /opt/rh/${package}/enable
    }

    installRubySCL () {
      RUBY_PACKAGE=$(#{package_manager} search -q ruby|grep '^rh-ruby\\([0-9\\.]\\+\\)\\?\\.'|sort -r|head -n1|awk '{print $1}'|awk -F'.' '{print $1}')
      installPackage ${RUBY_PACKAGE}
      RUBY_VERSION=\"$(#{package_manager} info ${RUBY_PACKAGE}|grep -i version|awk '{print $3}')\"
      test -L /usr/lib64/libruby.so.${RUBY_VERSION} || {
        #{sudo('ln')} -sf /opt/rh/${RUBY_PACKAGE}/root/usr/lib64/libruby.so.${RUBY_VERSION} \\
          /usr/lib64/libruby.so.${RUBY_VERSION}
      }
      #{ruby_alternatives('/usr/local/bin', "/opt/rh/${RUBY_PACKAGE}/root/usr/bin")}
      enableSCLPackage ${RUBY_PACKAGE}
    }

    installPythonSCL () {
      PYTHON_PACKAGE='python27 python27-python-virtualenv'
      installPackage ${PYTHON_PACKAGE}

      #{alternatives_command} --install /usr/local/bin/python python /opt/rh/python27/root/usr/bin/python 100
      #{alternatives_command} --set python /opt/rh/python27/root/usr/bin/python

      #{sudo('grep')} 'ANSIBLE_PYTHON_INTERPRETER' /etc/profile.d/ansible.sh &> /dev/null || {
        #{sudo('echo')} \"export ANSIBLE_PYTHON_INTERPRETER=/usr/local/bin/python\"| #{sudo('tee')} -a /etc/profile.d/ansible.sh
      }
      #{sudo('grep')} XDG_DATA_DIRS /etc/sudoers.d/ansible &> /dev/null || {
        #{sudo('echo')} 'Defaults    env_keep += \"XDG_DATA_DIRS PKG_CONFIG_PATH ANSIBLE_PYTHON_INTERPRETER\"' | #{sudo('tee')} -a /etc/sudoers.d/ansible
      }

      test -L /usr/lib64/libpython2.7.so.1.0 || {
        #{sudo('ln')} -sf /opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0 \\
          /usr/lib64/libpython2.7.so.1.0
      }
      test -L /usr/lib64/libpython2.7.so || {
        #{sudo('ln')} -sf /usr/lib64/libpython2.7.so.1.0 /usr/lib64/libpython2.7.so
      }

      enableSCLPackage 'python27'
    }

    preInstall () {
      RHEL_VERSION=$(test -f /etc/system-release-cpe && awk -F':' '{print $5}' /etc/system-release-cpe || echo '0')
      RHEL_DISTR=$(test -f /etc/system-release-cpe && awk -F':' '{print $3}' /etc/system-release-cpe || echo '0')

      # Sanitize CPE Info
      case ${RHEL_DISTR} in
        amazon)
          RHEL_VERSION=6
          ;;
        o)
          RHEL_DISTR=amazon
          RHEL_VERSION=7
          ;;
        *)
          ;;
      esac

      if [[ ${RHEL_VERSION} -eq 6 || ${RHEL_VERSION} -eq 7 ]]; then
        echo \"We are going to use SCL repository for Python and Ruby installation\"
        echo \"Working with ${RHEL_DISTR} ${RHEL_VERSION}\"
        case ${RHEL_DISTR} in
          centos)
            installPackage centos-release-scl-rh
            installPythonSCL
            installRubySCL
            ;;
          oracle)
            installPackage oracle-softwarecollection-release-el${RHEL_VERSION}
            installRubySCL
            if [[ ${RHEL_VERSION} -eq 6 ]]; then
              installPythonSCL
            fi
            ;;
          *)
            echo \"Unsupported RHEL SCL family distribution - ${RHEL_DISTR} ${RHEL_VERSION}\"
            ;;
        esac
      fi
      updatePath
    }
  """
end