geerlingguy / docker-debian11-ansible

Debian 11 (Bullseye) Docker container for Ansible playbook and role testing.
https://hub.docker.com/r/geerlingguy/docker-debian11-ansible
MIT License
40 stars 20 forks source link

Container is missing iproute2 for gathering network facts #1

Closed maxhoesel closed 3 years ago

maxhoesel commented 3 years ago

I'm trying to use this container as part of my molecule tests for a role. When this role tries to access the ansible_default_ipv4 host fact (after gathering facts of course), I get hit with a 'ansible_default_ipv4' is undefined error.

Running Ansible directly from the container produces the same result:

$ docker run geerlingguy/docker-debian11-ansible bash -c 'ansible -m setup localhost | grep -A 10 ansible_default_ipv4
$ echo $?
1

Meanwhile, the same command works fine for all of the other images I am using (Debian 10/Ubuntu, etc.):

$ docker run geerlingguy/docker-debian10-ansible bash -c 'ansible -m setup localhost | grep -A 10 ansible_default_ipv4'
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the 
controller starting with Ansible 2.12. Current version: 3.7.3 (default, Jan 22 
2021, 20:04:44) [GCC 8.3.0]. This feature will be removed from ansible-core in 
version 2.12. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
        "ansible_default_ipv4": {
            "address": "172.17.0.2",
            "alias": "eth0",
            "broadcast": "172.17.255.255",
            "gateway": "172.17.0.1",
            "interface": "eth0",
            "macaddress": "02:42:ac:11:00:02",
            "mtu": 1500,
            "netmask": "255.255.0.0",
            "network": "172.17.0.0",
            "type": "ether"

The source of this problem appears to be the missing iproute2 package, which is required by Ansibles gather_facts mechanism. Manually installing the package before running Ansible fixes this issue:

$ docker run geerlingguy/docker-debian11-ansible bash -c 'apt update && apt install -y iproute2 && ansible -m setup localhost | grep -A 10 ansible_default_ipv4'

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Get:1 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:2 http://deb.debian.org/debian bullseye InRelease [113 kB]

[APT output truncated]

Setting up iproute2 (5.10.0-4) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Processing triggers for libc-bin (2.31-12) ...
        "ansible_default_ipv4": {
            "address": "172.17.0.7",
            "alias": "eth0",
            "broadcast": "172.17.255.255",
            "gateway": "172.17.0.1",
            "interface": "eth0",
            "macaddress": "02:42:ac:11:00:07",
            "mtu": 1500,
            "netmask": "255.255.0.0",
            "network": "172.17.0.0",
            "type": "ether

I suggest adding iproute2 to the list of packages in the Dockerfile to address this.

My environment: