Skip to main content
Bumped by Community user
Adding execution-environment.yml
Source Link

Here is my execution-environment.yml file I'm using to build the Docker image via ansible-builder:

version: 3
images:
  base_image:
    name: quay.io/centos/centos:stream9
dependencies:
  system: |
    git
    python3-devel
    gcc
    iputils  # Added to include the ping command
  ansible_core:
    # Require minimum of 2.15 to get ansible-inventory --limit option
    package_pip: ansible-core>=2.15.0rc2,<2.16
  ansible_runner:
    package_pip: ansible-runner
  galaxy: |
    ---
    collections:
      - name: awx.awx
      - name: community.vmware
      - name: cisco.nxos
      - name: cisco.aci
      - name: kubernetes.core
      - name: ansible.posix
      - name: ansible.windows
      - name: redhatinsights.insights
  python: |
    paramiko
    pymssql

Here is my execution-environment.yml file I'm using to build the Docker image via ansible-builder:

version: 3
images:
  base_image:
    name: quay.io/centos/centos:stream9
dependencies:
  system: |
    git
    python3-devel
    gcc
    iputils  # Added to include the ping command
  ansible_core:
    # Require minimum of 2.15 to get ansible-inventory --limit option
    package_pip: ansible-core>=2.15.0rc2,<2.16
  ansible_runner:
    package_pip: ansible-runner
  galaxy: |
    ---
    collections:
      - name: awx.awx
      - name: community.vmware
      - name: cisco.nxos
      - name: cisco.aci
      - name: kubernetes.core
      - name: ansible.posix
      - name: ansible.windows
      - name: redhatinsights.insights
  python: |
    paramiko
    pymssql
Source Link

Ansible AWX issue - Ping module fails in my custom Execution Environment pod when running Jobs, but not when I start the Pod manually

I built a Docker image from CentOS 9 Stream via Ansible-Builder. When I spin up the Docker container I can ping VMs in my network. Also when I run a Playbook to manually create a K8s Pod from the Docker image ping works fine. However, when I use the EE for my Template, ping fails inside the Job. Even when I test pinging 127.0.0.1 or localhost it still fails.

I have used this exact same Docker image in a work lab and ping works fine, so I know the issue is related to my home K8s and/or AWX environment.

When I kubectl exec -it into the running EE pod, I see no output from ping:

root@ansible-ubuntu-1:~# kubectl exec -it automation-job-239-5dft4 -- /bin/bash
bash-5.1$ ping 127.0.0.1
bash-5.1$
bash-5.1$ ping 192.168.1.1
bash-5.1$
bash-5.1$ ping 192.168.3.1

Perhaps this is a Kubernetes issue? If so I would also expect the pings from inside the EE pod I spin up to fail, however.

Here is my Playbook:

---
- name: Ping Localhost and 127.0.0.1
  hosts: localhost
  gather_facts: false

  tasks:
    - name: Show the location of the ping command using 'command -v'
      ansible.builtin.command:
        cmd: command -v ping
      register: command_v_ping_result

    - name: Display the location of the ping command using 'command -v'
      ansible.builtin.debug:
        var: command_v_ping_result.stdout

    - name: Show the location of the ping command using 'type'
      ansible.builtin.shell:
        cmd: type ping
      register: type_ping_result

    - name: Display the location of the ping command using 'type'
      ansible.builtin.debug:
        var: type_ping_result.stdout

    - name: Wait for 30 minutes
      ansible.builtin.pause:
        minutes: 30
        prompt: "Pausing for 30 minutes. You can kubectl exec -it into the pod during this time."

    - name: Ping localhost
      ansible.builtin.ping:
      delegate_to: localhost

    - name: Ping 127.0.0.1
      ansible.builtin.command:
        cmd: ping -c 2 127.0.0.1
      register: ping_result

    - name: Display ping result
      ansible.builtin.debug:
        var: ping_result.stdout

Here is the job output:

[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'

PLAY [Ping Localhost and 127.0.0.1] ********************************************

TASK [Show the location of the ping command using 'command -v'] ****************
changed: [localhost]

TASK [Display the location of the ping command using 'command -v'] *************
ok: [localhost] => {
    "command_v_ping_result.stdout": "/usr/sbin/ping"
}

TASK [Show the location of the ping command using 'type'] **********************
changed: [localhost]

TASK [Display the location of the ping command using 'type'] *******************
ok: [localhost] => {
    "type_ping_result.stdout": "ping is /usr/sbin/ping"
}

TASK [Ping localhost] **********************************************************
ok: [localhost]

TASK [Ping 127.0.0.1] **********************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["ping", "-c", "2", "127.0.0.1"], "delta": "0:00:00.009202", "end": "2024-07-24 15:19:28.971365", "msg": "non-zero return code", "rc": 2, "start": "2024-07-24 15:19:28.962163", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0