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?
APT stands for "Advanced Packaging Tool" is the preferred package management toolset in Ubuntu. It allows us to install new packages, update them, and remove the packages from Ubuntu or Debian systems.
Ansible will automatically detect and use Python 3 on many platforms that ship with it. To explicitly configure a Python 3 interpreter, set the ansible_python_interpreter inventory variable at a group or host level to the location of a Python 3 interpreter, such as /usr/bin/python3.
Most Ansible modules that execute under a POSIX environment require a Python interpreter on the target host. Unless configured otherwise, Ansible will attempt to discover a suitable Python interpreter on each target host the first time a Python module is executed for that host.
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
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 controlled 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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With