Skip to content

Commit

Permalink
pip3 for redhat and centos
Browse files Browse the repository at this point in the history
  • Loading branch information
neillturner committed Jun 17, 2020
1 parent d16b813 commit fa49cae
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kitchen-ansible/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
module Kitchen
module Ansible
VERSION = '0.51.0'.freeze
VERSION = '0.52.0'.freeze
end
end
7 changes: 7 additions & 0 deletions lib/kitchen/provisioner/ansible/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Config
default_config :require_ruby_for_busser, false
default_config :require_windows_support, false
default_config :require_pip, false
default_config :require_pip3, false
default_config :requirements_path, false
default_config :requirements_collection_path, false
default_config :ssh_known_hosts, nil
Expand Down Expand Up @@ -104,6 +105,12 @@ class Config
fail('No roles_path detected. Please specify one in .kitchen.yml')
end

default_config :ansible_binary_path do |provisioner|
if provisioner[:require_pip3]
fail('No ansible_binary_path detected. Please specify one in .kitchen.yml')
end
end

default_config :group_vars_path do |provisioner|
provisioner.calculate_path('group_vars', :directory)
end
Expand Down
33 changes: 33 additions & 0 deletions lib/kitchen/provisioner/ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def install_command
elsif config[:require_pip]
info('Installing ansible through pip')
cmd = install_ansible_from_pip_command
elsif config[:require_pip3]
info('Installing ansible through pip3')
cmd = install_ansible_from_pip3_command
elsif config[:require_ansible_repo]
if !@os.nil?
info("Installing ansible on #{@os.name}")
Expand Down Expand Up @@ -562,6 +565,36 @@ def install_ansible_from_pip_command
INSTALL
end

def install_ansible_from_pip3_command
if config[:ansible_version]=='latest' or config[:ansible_version].nil?
ansible_version = ''
else
ansible_version = "==#{config[:ansible_version]}"
end
<<-INSTALL
if [ ! $(which ansible) ]; then
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
#{Kitchen::Provisioner::Ansible::Os::Redhat.new('redhat', config).install_epel_repo}
#{update_packages_redhat_cmd} > #{detect_debug}
#{sudo_env('yum')} -y install python3-libselinux python3-devel python3-pip git libffi-devel openssl-devel gcc > #{detect_debug}
else
if [ -f /etc/SUSE-brand ] || [ -f /etc/SuSE-release ]; then
#{sudo_env('zypper')} ar #{python_sles_repo} > #{detect_debug}
#{update_packages_suse_cmd} > #{detect_debug}
#{sudo_env('zypper')} --non-interactive install python python-devel git python-setuptools python-pip python-six libyaml-devel libffi-devel libopenssl-devel > #{detect_debug}
else
#{update_packages_debian_cmd} > #{detect_debug}
#{sudo_env('apt-get')} -y install git python python-pip python-setuptools build-essential python-dev libffi-dev libssl-dev > #{detect_debug}
fi
fi
#{export_http_proxy}
#{sudo_env('pip3')} install -U setuptools > #{detect_debug}
#{sudo_env('pip3')} install ansible#{ansible_version} > #{detect_debug}
fi
INSTALL
end

def install_omnibus_command
info('Installing ansible using ansible omnibus')

Expand Down
20 changes: 20 additions & 0 deletions provisioner_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ It installs it in the following order:

Install require packages and then installs ansible using the python pip command and ansible version must be specified. This allows a specific version of ansible to be installed.

* if require_pip3 is set to true

Install require packages and then installs ansible using the python pip3 command and ansible version must be specified. This allows a specific version of ansible to be installed.

Currently only works for Redhat/Centos.

* if require_ansible_repo is set to true (the default)

Installs from the operation system repository only with the ansible version that is in the particular repository and will use the ansible_version in the package name where appropriate.
Expand Down Expand Up @@ -95,6 +101,7 @@ require_ansible_repo | true | Set if installing Ansible from a `yum` or `apt` re
require_ansible_source | false | Install Ansible from source using method described [here](http://docs.ansible.com/intro_installation.html#running-from-source). Only works on Debian/Ubuntu at present
require_chef_for_busser | true | Install Chef to run Busser for tests. NOTE: kitchen 1.4 only requires Ruby to run Busser so this is not required.
require_pip | false | Set to `true` if Ansible is to be installed through `pip`).
require_pip3 | false | Set to `true` if Ansible is to be installed through `pip3`).
require_ruby_for_busser | false | Install Ruby to run Busser for tests
require_windows_support | false | Install [Windows support](http://docs.ansible.com/ansible/intro_windows.html)
requirements_path | | Path to Ansible Galaxy requirements
Expand All @@ -110,6 +117,19 @@ update_package_repos | true | Update OS repository metadata
wait_for_retry | 30 | number of seconds to wait before retrying converge command
ignore_ansible_cfg | false | If true, values from ansible.cfg file will not be loaded.

## require_pip3

if using python 3 and wish to install via pip specify
```yaml
ansible_binary_path: /usr/local/bin
require_pip3: true
```
you must specify ansible_binary_path as well.
Currently this only works for Centos and Redhat
## Ansible Inventory
Ansible has the concept of an [inventory](http://docs.ansible.com/ansible/latest/intro_inventory.html).
Expand Down

0 comments on commit fa49cae

Please sign in to comment.