Hi Elena,

On 20/05/2020 12:46, Elena ``of Valhalla'' wrote:
> Package: ansible
> Version: 2.7.7+dfsg-1
> Severity: important
> 
> Dear Maintainer,
> 
> on a minimal stable (buster) installation, ansible fails to run (at
> least on the machine itself) because of a lack of the python (2)
> interpreter.
> 
> To reproduce, debootstrap an image (but installing from netinst without
> adding things with tasksel also works):
> 
>     # mkdir buster
>     # debootstrap buster buster/
>     # mount -t devtmpfs udev buster/dev/
>     # chroot buster
> 
>     # ansible -i localhost, -m setup -c local all
> 
>     localhost | FAILED! => {
>         "changed": false,
>         "module_stderr": "/bin/sh: 1: /usr/bin/python: not found\n",
>         "module_stdout": "",
>         "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
>         "rc": 127
>     }
> 
> Installing python (2) of course fixes the issue.

Yes, that is correct, and also expected behaviour. Let me elaborate.

The ansible controller (the node you're running the ansible playbook
from) is fully migrated over to python3. This is where you have your
package "ansible" installed, and the dependencies for it are also correct.

The nodes you're managing with ansible (so the hosts you have listed in
your inventory file) don't have the package ansible installed, so we
can't control what's installed there and what isn't through the ansible
package. For this reason many ansible modules have documented which
python modules need to be installed on the nodes for them to work.
You're expected to ensure those packages are installed on the node
before using the ansible module there. For example, to use the ansible
module "apt" you need to have python-apt or python3-apt installed on the
node (not the controller).

In your example the controller and the managed node happen to be the
same machine. You will either need to have both python 2 and 3
installed, or you need to change the interpreter for the node by setting
the "ansible_python_interpreter" var to /usr/bin/python3. This var can
be set globally in ~/.ansible.cfg or per group/host in group_vars/ or
host_vars/. [0]

For historic reasons the interpreter pretty much defaults to python2,
because that is nearly universally installed on any Linux machine of the
last decade.

>From ansible 2.12 and onwards, the heuristic will be a little bit
smarter. [1]

> 
> I've noticed that it seems to be hardcoded as such in quite a few
> modules:
> 
>     # grep -r '/usr/bin/python$' /usr/lib/python3/dist-packages/ansible | wc 
> -l
>     2083
> 
> but I've also checked that in sid the original command is working, while
> those files still have an hardcoded python2 executable, so I'm not sure
> what is going on there.

Yes, this is also expected, as the shebang will be rewritten for those
modules that get run on the controlled nodes.

I'm not sure how to approach this issue the best, it seems as though
some users have stumbled over it in the past.

Greets,
Lee

[0]
https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html
[1]
https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html



> 
> -- System Information:
> Debian Release: bullseye/sid
>   APT prefers stable-updates
>   APT policy: (500, 'stable-updates'), (500, 'testing'), (500, 'stable'), (1, 
> 'experimental')
> Architecture: amd64 (x86_64)
> 
> Kernel: Linux 5.6.0-1-amd64 (SMP w/2 CPU cores)
> Kernel taint flags: TAINT_FIRMWARE_WORKAROUND
> Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8), 
> LANGUAGE=en_IE:en (charmap=UTF-8)
> Shell: /bin/sh linked to /bin/dash
> Init: systemd (via /run/systemd/system)
> LSM: AppArmor: enabled
> 
> Versions of packages ansible depends on:
> ii  openssh-client        1:8.2p1-4
> ii  python3               3.8.2-3
> ii  python3-crypto        2.6.1-13.1+b1
> ii  python3-cryptography  2.8-4
> ii  python3-distutils     3.8.2-2
> ii  python3-dnspython     1.16.0-2
> ii  python3-httplib2      0.14.0-3
> ii  python3-jinja2        2.10.1-2
> ii  python3-netaddr       0.7.19-4
> ii  python3-paramiko      2.6.0-2
> ii  python3-yaml          5.3.1-1+b1
> 
> Versions of packages ansible recommends:
> ii  python3-argcomplete  1.8.1-1.3
> ii  python3-jmespath     0.9.5-1
> ii  python3-kerberos     1.1.14-3.1+b1
> ii  python3-libcloud     2.8.0-1
> ii  python3-selinux      3.0-1+b3
> ii  python3-winrm        0.3.0-2
> ii  python3-xmltodict    0.12.0-2
> 
> Versions of packages ansible suggests:
> ii  cowsay   3.03+dfsg2-7
> ii  sshpass  1.06-1+b1
> 
> -- no debconf information
> 

Reply via email to