问题
Prologue: I am just moving first stesp in ansible, so please be patient
Also: I read the answers at 'Ansible demands installing MySQL-python despite it was already installed' but my case is different because locally, on the control machine, is all perfect; thanks to this question I discovered that my problem was in the remote controlled machine. So my questions is the same but the question linked do not contains an answer to resolve my problem.
I'm testing ansible from command line. For example, I succesfully can ping
~/.ssh$ ansible openvpn -C -m "ping"
192.168.1.225 | SUCCESS => {
"changed": false,
"ping": "pong"
}
I tried to launch an apt update
.
I am not sure if this is the right syntax for having the equivalent of
apt-get update
, but this is not the questionI am using
-C
to see what ansible says to me when I ask to do a dry run.
$ ansible openvpn -C -m "apt update-cache=yes"
192.168.1.225 | FAILED! => {
"changed": false,
"msg": "python-apt must be installed to use check mode. If run normally this module can auto-install it."
}
EDIT : As @Davide Maze suggested, it could be due to missing python-apt
. So I checked, but _I have python-apt
$ python -V
Python 2.7.15rc1
$ pip list
... cut ...
python-apt (1.6.2)
... cut ...
$ which python
/usr/bin/python
My question is: why does ansible tell me that python-apt is not installed, and how to fix this?
回答1:
Thanks to @David Maze for pointing me to the right direction
I was checking for python-apt
in the controller machine, not in the controlled machine.
So I installed the package from the controller into the controller machine using
$ ansible openvpn -m "apt name=python-apt state=latest" --become-user realtebo
You can also use the following form, that does sudo apt-get update
and wait for operator to enter the password. The user is the one logged in via ssh; so check your config. In my case, I'm using ssh keys, password login is disabled at all.
$ ansible openvpn -m apt -a "update-cache=yes" --become --ask-become-pass
Tip 1: To avoid this interaction is available the vault, but I've not tried it yet.
Tip 2: Also,
--ask-become-pass
is not in the doc where you're probably looking for, at lettera
; this is because the option is shortened in-K
, uppercase, so look more down See the doc
After ensuring that remotely the package python-apt
is available, then the -C
option started to work, exactly because now python-apt
is available remotely.
ansible openvpn -C -m "apt name=python state=latest"
192.168.1.225 | SUCCESS => {
"cache_update_time": 1533077635,
"cache_updated": false,
"changed": false
}
回答2:
I solved this error by using ansible_python_interpreter
argument while running the ansible-playbook
, like below.
ansible-playbook playbook_name.yml -e ansible_python_interpreter=/usr/bin/python --check
来源:https://stackoverflow.com/questions/51622712/ansible-requires-python-apt-but-its-already-installed