Ansible - docker_exec module

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
...

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 58243 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |