Bootstrap FreeKB - Ansible - Create Docker Volume using the docker_volume module
Ansible - Create Docker Volume using the docker_volume module

Updated:   |  Ansible articles

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

docker_volume 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 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 docker_volume could be used to create a volume named volume_one. This would be like issuing the docker volume create volume_one command.

---
- hosts: all
  tasks:
  - name: create volume_one
    docker_volume:
      name: volume_one
...

 

As a bit of a more practial example, here is how to create a volume that points to an Amazon Web Services (AWS) Elastic File System (EFS) NFS share.

---
- hosts: all
  tasks:
  - name: create docker volume
    docker_volume:
      name: my_images
      driver: local
      driver_options:
        type: nfs
        o: "addr=10.11.12.13,rw"
        device: :/
...

 




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 c16be2 in the box below so that we can be sure you are a human.