class Kitchen::Yansible::Tools::Install

Constants

BINARY_DEFAULT_PREFIX
BINARY_INSTALL_PREFIX

Public Class Methods

make(config, platform) click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 47
def self.make(config, platform)

  case platform.downcase
  when /.*(debian|ubuntu).*/
    return Debian.new(config, platform)
  when /.*(redhat|centos|oracle).*/
    return RHEL.new(config, platform)
  when /.*fedora.*/
    return Fedora.new(config, platform)
  when /.*amazon.*/
    return Amazon.new(config, platform)
  # when 'suse', 'opensuse', 'sles'
  #   return Suse.new(platform, config)
   when 'darwin', 'mac', 'macos', 'macosx'
     return Darwin.new(config, platform)
  # when 'alpine'
  #   return Alpine.new(config, platform)
  # when 'openbsd'
  #   return Openbsd.new(config, platform)
  # when 'freebsd'
  #   return Freebsd.new(config, platform)
  when /.*windows.*/
    return Windows.new(config, platform)
  else
    raise "Unsupported platform - '#{platform.to_s}'!"
  end
end
new(config, platform) click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 42
def initialize(config, platform)
  @config = config
  @platform = platform
end

Public Instance Methods

alternatives_command() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 150
def alternatives_command
  "#{sudo('alternatives')}"
end
ansible_alternatives(install_prefix, sandbox_path) click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 154
def ansible_alternatives(install_prefix, sandbox_path)
  """
    #{command_exists("#{sandbox_path}/venv/bin/ansible")} && {
      #{alternatives_command} --install #{install_prefix}/ansible ansible #{sandbox_path}/venv/bin/ansible 100 \\
        --slave #{install_prefix}/ansible-config ansible-config #{sandbox_path}/venv/bin/ansible-config \\
        --slave #{install_prefix}/ansible-connection ansible-connection #{sandbox_path}/venv/bin/ansible-connection \\
        --slave #{install_prefix}/ansible-console ansible-console #{sandbox_path}/venv/bin/ansible-console \\
        --slave #{install_prefix}/ansible-doc ansible-doc #{sandbox_path}/venv/bin/ansible-doc \\
        --slave #{install_prefix}/ansible-galaxy ansible-galaxy #{sandbox_path}/venv/bin/ansible-galaxy \\
        --slave #{install_prefix}/ansible-inventory ansible-inventory #{sandbox_path}/venv/bin/ansible-inventory \\
        --slave #{install_prefix}/ansible-playbook ansible-playbook #{sandbox_path}/venv/bin/ansible-playbook \\
        --slave #{install_prefix}/ansible-pull ansible-pull #{sandbox_path}/venv/bin/ansible-pull \\
        --slave #{install_prefix}/ansible-test ansible-test #{sandbox_path}/venv/bin/ansible-test \\
        --slave #{install_prefix}/ansible-vault ansible-vault #{sandbox_path}/venv/bin/ansible-vault
    } || {
      echo '===> Ansible is not installed, exiting now. <==='
      exit 1
    }

    echo 'Check alternatives validity'
    #{command_exists("#{install_prefix}/ansible")} || {
      echo '===> Ansible alternative is incorrectly installed, exiting now. <==='
      exit 1
    }
  """
end
ansible_version() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 107
def ansible_version
  (@config[:ansible_version] && @config[:ansible_version] != 'latest') ? @config[:ansible_version].to_s : ''
end
get_python_version() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 121
def get_python_version
  "python -c 'import sys; print(\"\".join(map(str, sys.version_info[:#{python_version_size}])))'"
end
install_ansible_pip(sandbox_path) click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 137
def install_ansible_pip(sandbox_path)
  """
    installAnsiblePip () {
      echo \"Installing Ansible via Pip\"

      virtualenv #{sandbox_path}/venv
      #{sandbox_path}/venv/bin/pip install $PIP_ARGS --upgrade pip setuptools
      #{sandbox_path}/venv/bin/pip install $PIP_ARGS #{pip_required_packages.join(' ')}
      #{ansible_alternatives(BINARY_INSTALL_PREFIX, sandbox_path)}
    }
  """
end
install_package() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 133
def install_package
  "#{package_manager} install -y"
end
local_install() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 94
def local_install
  """
    #{preinstall_command}
    #{search_alternatives}
    #{install_python}
    #{install_ruby}

    preInstall
    installPython
    installRuby
  """
end
package_manager() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 125
def package_manager
  "#{sudo_env('yum')}"
end
pip_required_packages() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 115
def pip_required_packages
  [
    "ansible#{pip_version(ansible_version)}",
  ]
end
pip_version(version) click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 111
def pip_version(version)
  version.empty? ? '' : "==#{version}"
end
python_version_size() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 38
def python_version_size
  1
end
remote_install() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 75
def remote_install
  """
    #{preinstall_command}
    #{search_alternatives}
    #{install_python}
    #{install_virtualenv}
    #{install_ruby}
    #{install_ansible_pip('/tmp/ansible')}

    preInstall
    installPython
    installVirtualenv
    installRuby
    #{command_exists('ansible')} && {
      ansible --version|head -n1|grep -i 'ansible #{ansible_version}' &>/dev/null || installAnsiblePip
    } || installAnsiblePip
  """
end
ruby_alternatives(install_prefix, alternative_path) click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 181
def ruby_alternatives(install_prefix, alternative_path)
  """
    #{command_exists("#{alternative_path}/ruby")} && {
      #{alternatives_command} --install #{install_prefix}/ruby ruby #{alternative_path}/ruby 100 \\
        --slave #{install_prefix}/erb erb #{alternative_path}/erb \\
        --slave #{install_prefix}/gem gem #{alternative_path}/gem \\
        --slave #{install_prefix}/irb irb #{alternative_path}/irb \\
        --slave #{install_prefix}/rdoc rdoc #{alternative_path}/rdoc \\
        --slave #{install_prefix}/ri ri #{alternative_path}/ri

      #{alternatives_command} --set ruby #{alternative_path}/ruby
    } || {
      echo '===> Ruby is not installed, exiting now. <==='
      exit 1
    }

    echo 'Check alternatives validity'
    #{command_exists("#{install_prefix}/ruby")} || {
      echo '===> Ruby alternative is incorrectly installed, exiting now. <==='
      exit 1
    }
  """
end
search_alternatives() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 205
def search_alternatives
  """
    searchAlternatives() {
      binaryCmd=$1
      #{command_exists("${binaryCmd}")} || {
        alternateCmd=$(ls -1A #{BINARY_DEFAULT_PREFIX}/${binaryCmd}*|grep -v \"${binaryCmd}$\"|sort|head -n1)
        test -n \"${alternateCmd}\" && {
          echo \"Attempt to install '${alternateCmd}' as an alternative.\"
          #{command_exists("${alternateCmd}")} && {
            #{alternatives_command} --install #{BINARY_DEFAULT_PREFIX}/${binaryCmd} ${binaryCmd} $(#{check_command("${alternateCmd}")}) 100
            #{alternatives_command} --set ${binaryCmd} $(#{check_command("${alternateCmd}")})
          }
        }
      }
    }
  """
end
update_cache() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 129
def update_cache
  "#{package_manager} makecache"
end
update_path() click to toggle source
# File lib/kitchen-yansible/tools/install.rb, line 223
def update_path
  """
    updatePath () {
      #{sudo('grep')} secure_path /etc/sudoers.d/ansible &> /dev/null || {
        #{sudo('echo')} 'Defaults    secure_path = /usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin' | #{sudo('tee')} -a /etc/sudoers.d/ansible
      }
    }
  """
end