Bootstrap FreeKB - Ansible - Get info on Docker container using the docker_container_info module
Ansible - Get info on Docker container using the docker_container_info module

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

docker_container_info is part of the community.docker collection. Typically, the community.docker collection is not included in the default Ansible collections. The ansible-galaxy collection install command can be used to install the community.docker collection.

ansible-galaxy collection install community.docker

 

Before you can use the docker_container_info module, the Python docker module must be installed on the managed node, which can be done using PIP. The dnf module can be used to install PIP and then the pip module can be used to install the Python docker module.

---
- hosts: all
  tasks:
  - name: install pip
    dnf:
      name: pip
      state: present

  - name: pip install docker
    pip:
      name: docker
      state: latest
...

 

Here is how the docker_container_info module could be used to get info on the "nginx" container. This can be very useful in determining if the nginx container exists.

---
- hosts: all
  tasks:
  - name: get info on the container
    docker_container_info:
      name: my_container
    register: out

  - debug:
      var: out
...

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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