(2.9) [zaki@cloud-dev ansible]$ ansible --version
ansible 2.9.10
config file = /home/zaki/tmp/ansible/ansible.cfg
configured module search path = ['/home/zaki/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/zaki/ansible/2.9/lib/python3.6/site-packages/ansible
executable location = /home/zaki/ansible/2.9/bin/ansible
python version = 3.6.8 (default, Apr 2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
(2.9) [zaki@cloud-dev ansible]$ ansible-config dump --only-changed
DEFAULT_STDOUT_CALLBACK(/home/zaki/tmp/ansible/ansible.cfg) = yaml
(2.9) [zaki@cloud-dev ansible]$ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
(2.9) [zaki@cloud-dev ansible]$ which ansible
~/ansible/2.9/bin/ansible
※ Ansibleはpip3でインストールしまいます。
(2.9) [zaki@cloud-dev ansible]$ cat playbook.yml
- hosts: localhost
become: true
tasks:
- name: install sl
yum:
name: sl
state: present
(2.9) [zaki@cloud-dev ansible]$ ansible-playbook playbook.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] *********************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************
ok: [localhost]
TASK [install sl] ********************************************************************************************************************
fatal: [localhost]: FAILED! => changed=false
msg: The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.
PLAY RECAP ***************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
(2.9) [zaki@cloud-dev ansible]$ ansible-playbook playbook.yml -vvv
ansible-playbook 2.9.10
config file = /home/zaki/tmp/ansible/ansible.cfg
configured module search path = ['/home/zaki/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/zaki/ansible/2.9/lib/python3.6/site-packages/ansible
executable location = /home/zaki/ansible/2.9/bin/ansible-playbook
python version = 3.6.8 (default, Apr 2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /home/zaki/tmp/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAYBOOK: playbook.yml ***************************************************************************************************************
1 plays in playbook.yml
PLAY [localhost] *********************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************
task path: /home/zaki/tmp/ansible/playbook.yml:1
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: zaki
<127.0.0.1> EXEC /bin/sh -c 'echo ~zaki && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/zaki/.ansible/tmp `"&& mkdir /home/zaki/.ansible/tmp/ansible-tmp-1598277955.9973943-72218-259628780768095 && echo ansible-tmp-1598277955.9973943-72218-259628780768095="` echo /home/zaki/.ansible/tmp/ansible-tmp-1598277955.9973943-72218-259628780768095 `" ) && sleep 0'
Using module file /home/zaki/ansible/2.9/lib/python3.6/site-packages/ansible/modules/system/setup.py
<127.0.0.1> PUT /home/zaki/.ansible/tmp/ansible-local-721898r5yvgls/tmprme3x2ny TO /home/zaki/.ansible/tmp/ansible-tmp-1598277955.9973943-72218-259628780768095/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/zaki/.ansible/tmp/ansible-tmp-1598277955.9973943-72218-259628780768095/ /home/zaki/.ansible/tmp/ansible-tmp-1598277955.9973943-72218-259628780768095/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-dibomficdxgyzvvfkvqhipizugjvrfyb ; /home/zaki/ansible/2.9/bin/python /home/zaki/.ansible/tmp/ansible-tmp-1598277955.9973943-72218-259628780768095/AnsiballZ_setup.py'"'"' && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/zaki/.ansible/tmp/ansible-tmp-1598277955.9973943-72218-259628780768095/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers
TASK [install sl] ********************************************************************************************************************
task path: /home/zaki/tmp/ansible/playbook.yml:4
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: zaki
<127.0.0.1> EXEC /bin/sh -c 'echo ~zaki && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/zaki/.ansible/tmp `"&& mkdir /home/zaki/.ansible/tmp/ansible-tmp-1598277956.9452167-72316-60467475322013 && echo ansible-tmp-1598277956.9452167-72316-60467475322013="` echo /home/zaki/.ansible/tmp/ansible-tmp-1598277956.9452167-72316-60467475322013 `" ) && sleep 0'
Using module file /home/zaki/ansible/2.9/lib/python3.6/site-packages/ansible/modules/packaging/os/yum.py
<127.0.0.1> PUT /home/zaki/.ansible/tmp/ansible-local-721898r5yvgls/tmp5hjyyubu TO /home/zaki/.ansible/tmp/ansible-tmp-1598277956.9452167-72316-60467475322013/AnsiballZ_yum.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/zaki/.ansible/tmp/ansible-tmp-1598277956.9452167-72316-60467475322013/ /home/zaki/.ansible/tmp/ansible-tmp-1598277956.9452167-72316-60467475322013/AnsiballZ_yum.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-rwzgopvvicrcorouodrfagsucewltccr ; /home/zaki/ansible/2.9/bin/python /home/zaki/.ansible/tmp/ansible-tmp-1598277956.9452167-72316-60467475322013/AnsiballZ_yum.py'"'"' && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/zaki/.ansible/tmp/ansible-tmp-1598277956.9452167-72316-60467475322013/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => changed=false
invocation:
module_args:
allow_downgrade: false
autoremove: false
bugfix: false
conf_file: null
disable_excludes: null
disable_gpg_check: false
disable_plugin: []
disablerepo: []
download_dir: null
download_only: false
enable_plugin: []
enablerepo: []
exclude: []
install_repoquery: true
install_weak_deps: true
installroot: /
list: null
lock_timeout: 30
name:
- sl
releasever: null
security: false
skip_broken: false
state: present
update_cache: false
update_only: false
use_backend: auto
validate_certs: true
msg: The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.
PLAY RECAP ***************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
(2.9) [zaki@cloud-dev ansible]$
※ yum
の結果がエラーになっているのは、OS的にPython2ベースのCentOS7ではdnf
が使えず、Python3からはyum
が使えないため、というのは理解しているつもりです。(ターゲット上でyum on Python2で動かせば動作するというか回避できる内容というつもり)
Ansible dnf python3 is not working with Centos 7 · Issue #67083 · ansible/ansible
ここのこの部分
This is a known limitation of the dnf module. The dnf module depends on the underlying python bindings provided by the OS. The only dnf python bindings provided by the OS are those for the default python, which is /usr/bin/python (python2).
It is not possible or feasible to use a non-default python to manage dnf.
As such, you will have to ensure that you set ansible_python_interpreter: /usr/bin/python for any task which needs to interact with things like dnf or selinux. This is a limitation of the underlying operating system and the packages it provides.