If you are not familiar with modules, check out Ansible - Getting Started with Modules.
The docker_exec module is used to execute a command in a Docker container, just like using the docker exec command. Typically, this module is not included in the default Ansible collections, thus you will probably need to install the community.docker collection.
ansible-galaxy collection install community.docker
Here is how you would issue the df command in the hello-world Docker container.
--- - hosts: all tasks: - name: execute df command in hello-world Docker container community.docker.docker_container_exec: container: hello-world command: df register: out - name: print out debug: var: out ...