Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker_Container_Exec - TypeError: exec_create() got an unexpected keyword argument 'workdir' #242

Closed
linuxtek-canada opened this issue Nov 22, 2021 · 6 comments · Fixed by #243

Comments

@linuxtek-canada
Copy link

SUMMARY

Ansible Playbook using community.docker.docker_container_exec throws TypeError: exec_create() got an unexpected keyword argument 'workdir'

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_container_exec

ANSIBLE VERSION
ansible [core 2.11.6] 
  config file = /home/pjason/Ansible/jira-work/SITEOPS-1822/ansible.cfg
  configured module search path = ['/home/pjason/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/pjason/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True
COLLECTION VERSION
# /usr/lib/python3/dist-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 1.10.0 

# /home/pjason/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 2.0.1  
CONFIGURATION
No output
OS / ENVIRONMENT
  • Executing script on Linux Mint 20.2 (Uma)
  • Ansible version ansible/focal,focal,now 4.8.0-1ppa~focal all
  • Target machine is running Ubuntu 18.04.3 LTS
  • Target machine Docker version 19.03.1, build 74b1e89
  • Target machine running container built on ubuntu:focal-20211006
STEPS TO REPRODUCE

Execute Playbook using docker_container_exec module. For example:

    - name: Update S1 Tag inside Docker Image
      community.docker.docker_container_exec:
        container: securityagent
        command: echo "hello world"
        chdir: /root
EXPECTED RESULTS

Playbook executes the remote command inside the Docker image.

ACTUAL RESULTS

Playbook will fail with the following traceback:

The full traceback is:
Traceback (most recent call last):
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1637590867.7734087-7907-175183625764238/AnsiballZ_docker_container_exec.py", line 100, in <module>
    _ansiballz_main()
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1637590867.7734087-7907-175183625764238/AnsiballZ_docker_container_exec.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1637590867.7734087-7907-175183625764238/AnsiballZ_docker_container_exec.py", line 41, in invoke_module
    run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.6/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.docker.docker_container_exec_payload_fcqwgb95/ansible_community.docker.docker_container_exec_payload.zip/ansible_collections/community/docker/plugins/modules/docker_container_exec.py", line 258, in <module>
  File "/tmp/ansible_community.docker.docker_container_exec_payload_fcqwgb95/ansible_community.docker.docker_container_exec_payload.zip/ansible_collections/community/docker/plugins/modules/docker_container_exec.py", line 200, in main
  File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 34, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
TypeError: exec_create() got an unexpected keyword argument 'workdir'
fatal: [testqaops-ext-green-va-b_i-0bcede82671dab363]: FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 10.195.10.81 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1637590867.7734087-7907-175183625764238/AnsiballZ_docker_container_exec.py\", line 100, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1637590867.7734087-7907-175183625764238/AnsiballZ_docker_container_exec.py\", line 92, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1637590867.7734087-7907-175183625764238/AnsiballZ_docker_container_exec.py\", line 41, in invoke_module\r\n    run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.6/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.6/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib/python3.6/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.docker.docker_container_exec_payload_fcqwgb95/ansible_community.docker.docker_container_exec_payload.zip/ansible_collections/community/docker/plugins/modules/docker_container_exec.py\", line 258, in <module>\r\n  File \"/tmp/ansible_community.docker.docker_container_exec_payload_fcqwgb95/ansible_community.docker.docker_container_exec_payload.zip/ansible_collections/community/docker/plugins/modules/docker_container_exec.py\", line 200, in main\r\n  File \"/usr/lib/python3/dist-packages/docker/utils/decorators.py\", line 34, in wrapper\r\n    return f(self, *args, **kwargs)\r\n  File \"/usr/lib/python3/dist-packages/docker/utils/decorators.py\", line 19, in wrapped\r\n    return f(self, resource_id, *args, **kwargs)\r\nTypeError: exec_create() got an unexpected keyword argument 'workdir'\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

By comparison, calling docker exec, and passing the command to the container works properly. For example:

docker exec -d securityagent echo "hello world"
@felixfontein
Copy link
Collaborator

Which version of Docker SDK for Python do you have installed on the target machine for the target Python? (pip show docker / pip show docker-py)

@felixfontein
Copy link
Collaborator

Support for workdir was added in Docker SDK for Python 3.0.0 (according to https://docker-py.readthedocs.io/en/stable/change-log.html).

@felixfontein
Copy link
Collaborator

#243 should fix this.

@linuxtek-canada
Copy link
Author

The target machines don't have PIP, but I believe based on this, it's 2.5.1-1:
https://packages.ubuntu.com/bionic/python3-docker

@felixfontein
Copy link
Collaborator

In that case it's not surprising that it fails, and #243 should fix it.

@linuxtek-canada
Copy link
Author

Thanks for confirming. I can't update the python package on all the target machines right now, so I'll use my workaround in the meantime until #243 is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants