Ansible - Resolve "got an unexpected keyword argument 'workdir'"
by
Jeremy Canfield |
Updated: December 03 2022
| Ansible articles
Let's say something like this is being returned.
TypeError: exec_create() got an unexpected keyword argument 'workdir'
I ran into this problem when using the docker_container_exec module on Amazon Web Services (AWS) EC2 instances running the Amazon Linux Operating System.
---
- hosts: aws
tasks:
- community.docker.docker_container_exec:
container: hello-world
command: df
register: out
- debug:
var: out
...
The Docker system that contains the Docker container will need the Python Docker SDK (Software Development Kit). The Python Docker SDK is used to run Docker commands using Python. To ensure the AWS EC2 Instance had the latest Docker SDK for pip (Python version 2.6) and pip2 (Python version 2.7 and above) and pip3 (Python version 3) I used the shell module.
---
- hosts: aws
tasks:
- shell: "{{ item }}"
with_items:
- yes | sudo pip uninstall docker
- yes | sudo pip2 uninstall docker
- yes | sudo pip3 uninstall docker
- yes | sudo pip uninstall docker-py
- yes | sudo pip2 uninstall docker-py
- yes | sudo pip3 uninstall docker-py
- yes | sudo pip install docker
- yes | sudo pip2 install docker
- yes | sudo pip3 install docker
- community.docker.docker_container_exec:
container: hello-world
command: df
register: out
- debug:
var: out
...
Did you find this article helpful?
If so, consider buying me a coffee over at