community.docker icon indicating copy to clipboard operation
community.docker copied to clipboard

Commands on Docker host fail with "returned empty string"

Open jamesmyatt opened this issue 1 year ago • 14 comments

SUMMARY

I'm unable to run commands on a docker host. This used to work.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker

ANSIBLE VERSION
ansible [core 2.15.0]
  config file = /workspaces/project/ansible.cfg
  configured module search path = ['/home/vscode/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vscode/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/vscode/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/vscode/.local/bin/ansible
  python version = 3.10.10 (main, Mar 23 2023, 17:28:09) [GCC 10.2.1 20210110] (/usr/local/bin/python)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list community.docker

# /home/vscode/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.4.6  

# /home/vscode/.local/lib/python3.10/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 3.4.6  

# /usr/local/lib/python3.10/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 3.4.6  
CONFIGURATION
CONFIG_FILE() = /workspaces/project/ansible.cfg
OS / ENVIRONMENT

Running Ansible in vscode dev container (mcr.microsoft.com/vscode/devcontainers/python:0-3.10). Docker version 24.0.1, build 6802122.

STEPS TO REPRODUCE

I have a role that includes the following tasks:

---
- name: Create temporary container
  community.docker.docker_container:
    name: tmp_data
    image: python:3.10-bullseye
    state: started
    auto_remove: yes
    command: /bin/bash
    interactive: yes
    tty: yes
    volumes_from:
      - "{{ container_name }}"

- name: Add container to inventory
  add_host:
    name: "{{ inventory_hostname }}+tmp_data"
    ansible_connection: community.docker.docker
    ansible_host: tmp_data
    ansible_user: root
    ansible_become: yes
    ansible_remote_tmp: /tmp/.ansible
    ansible_docker_extra_args: "-H=tcp://{{ ansible_host }}:2375"
    ansible_python_interpreter: python

- name: ping
  delegate_to: "{{ inventory_hostname }}+tmp_data"
  ansible.builtin.ping:
EXPECTED RESULTS

I expect this to work.

ACTUAL RESULTS

Running with -vvv, everything works up to the last task, which fails:

<tmp_data> ESTABLISH DOCKER CONNECTION FOR USER: root
<tmp_data> EXEC ['/usr/bin/docker', '-H=tcp://192.168.1.168:2375', b'exec', b'-u', 'root', b'-i', 'tmp_data', '/bin/sh', '-c', '/bin/sh -c \'( umask 77 && mkdir -p "` echo /tmp/.ansible `"&& mkdir "` echo /tmp/.ansible/ansible-tmp-1686177373.2244887-17139-101563472711239 `" && echo ansible-tmp-1686177373.2244887-17139-101563472711239="` echo /tmp/.ansible/ansible-tmp-1686177373.2244887-17139-101563472711239 `" ) && sleep 0\'']
fatal: [windshear-1 -> windshear-1+tmp_data]: FAILED! => {
    "msg": "failed to resolve remote temporary directory from ansible-tmp-1686177373.2244887-17139-101563472711239: `( umask 77 && mkdir -p \"` echo /tmp/.ansible `\"&& mkdir \"` echo /tmp/.ansible/ansible-tmp-1686177373.2244887-17139-101563472711239 `\" && echo ansible-tmp-1686177373.2244887-17139-101563472711239=\"` echo /tmp/.ansible/ansible-tmp-1686177373.2244887-17139-101563472711239 `\" )` returned empty string"
}

Seems odd that the command has '/bin/sh', '-c' twice. Running the same docker command at the command line also doesn't work-it just hangs with no output--but running the command again without the duplicate /bin/sh -c works as I'd expect.

jamesmyatt avatar Jun 08 '23 18:06 jamesmyatt