Search code examples
dockeransible

Docker failed to find required executable "%s"


What I am trying to do:

  • Create a docker image so that I can use docker to run playbooks.

What my problem is:

  • Ansible cannot find the executable for the ansible.posix.synchronize module I am using in my playbook. Note, I have confirmed the module exists by running ansible-galaxy collection list

Error:

<10.16.29.75> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-local-1d52bc7yn/ansible-tmp-1738185054.6606917-31-140162884904275/AnsiballZ_synchronize.py && sleep 0'
marios_spaghetti  | <10.16.29.75> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-1d52bc7yn/ansible-tmp-1738185054.6606917-31-140162884904275/ > /dev/null 2>&1 && sleep 0'
marios_spaghetti  | The full traceback is:
marios_spaghetti  |   File "/tmp/ansible_ansible.posix.synchronize_payload__jvn6z1c/ansible_ansible.posix.synchronize_payload.zip/ansible/module_utils/basic.py", line 1421, in get_bin_path
marios_spaghetti  |     bin_path = get_bin_path(arg=arg, opt_dirs=opt_dirs)
marios_spaghetti  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
marios_spaghetti  |   File "/tmp/ansible_ansible.posix.synchronize_payload__jvn6z1c/ansible_ansible.posix.synchronize_payload.zip/ansible/module_utils/common/process.py", line 44, in get_bin_path
marios_spaghetti  |     raise ValueError('Failed to find required executable "%s" in paths: %s' % (arg, os.pathsep.join(paths)))
marios_spaghetti  | fatal: [airflowdev]: FAILED! => {
marios_spaghetti  |     "changed": false,
marios_spaghetti  |     "invocation": {
marios_spaghetti  |         "module_args": {
marios_spaghetti  |             "_local_rsync_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
marios_spaghetti  |             "_local_rsync_path": "rsync",
marios_spaghetti  |             "_substitute_controller": false,
marios_spaghetti  |             "archive": true,
marios_spaghetti  |             "checksum": false,
marios_spaghetti  |             "compress": true,
marios_spaghetti  |             "copy_links": false,
marios_spaghetti  |             "delay_updates": true,
marios_spaghetti  |             "delete": true,
marios_spaghetti  |             "dest": "[email protected]:/home/infogrid/cp_test_ansible",
marios_spaghetti  |             "dest_port": null,
marios_spaghetti  |             "dirs": false,
marios_spaghetti  |             "existing_only": false,
marios_spaghetti  |             "group": null,
marios_spaghetti  |             "link_dest": null,
marios_spaghetti  |             "links": null,
marios_spaghetti  |             "mode": "push",
marios_spaghetti  |             "owner": null,
marios_spaghetti  |             "partial": false,
marios_spaghetti  |             "perms": null,
marios_spaghetti  |             "private_key": null,
marios_spaghetti  |             "recursive": true,
marios_spaghetti  |             "rsync_opts": [],
marios_spaghetti  |             "rsync_path": null,
marios_spaghetti  |             "rsync_timeout": 0,
marios_spaghetti  |             "set_remote_user": true,
marios_spaghetti  |             "src": "/fake_dags",
marios_spaghetti  |             "ssh_args": null,
marios_spaghetti  |             "ssh_connection_multiplexing": false,
marios_spaghetti  |             "times": null,
marios_spaghetti  |             "verify_host": false
marios_spaghetti  |         }
marios_spaghetti  |     },
marios_spaghetti  |     "msg": "Failed to find required executable \"rsync\" in paths: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
marios_spaghetti  | }

Here is how my docker image is defined:

FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN apt install -y openssh-client
RUN apt install -y sshpass
RUN apt install -y python3 ansible

Here is how my playbook is configured:

- name: fakedagdeployment
  hosts: airflowdev
  become: true
  tasks:
    - name: deploy fake dags
      ansible.posix.synchronize:
        src:  /fake_dags
        dest: /home/infogrid/cp_test_ansible
        delete: true
        recursive: true

Here is my docker compose file:

services:
  ansible_poc:
    container_name: marios_spaghetti
    environment:
      ANSIBLE_HOST_KEY_CHECKING: False
    image: ansible-poc
    command: ansible-playbook -vvv -i ./inventory/hosts.yml --user infogrid ./playbooks/fakedagdeploy.yml
    volumes:
      - ./fake_dags:/fake_dags
      - ./inventory:/inventory
      - ./playbooks:/playbooks

Thank you for your help!


Solution

  • I have confirmed the module exists by running ansible-galaxy collection list

    An Ansible module can be present, but it doesn't mean that its external dependencies are installed.

    From the ansible.posix.synchronize documentation:

    rsync must be installed on both the local and remote host.

    Therefore you'll need to add

    RUN apt-get install -y rsync