diff --git a/README.md b/README.md index a31968b..b1d7c08 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Ansible Role: Docker +Forked by Catalina Sindrilaru (Eau de Web) to allow the creation of volumes using the docker_volumes variable (see defaults/main.yml for an example). + [![CI](https://github.com/geerlingguy/ansible-role-docker/workflows/CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-role-docker/actions?query=workflow%3ACI) An Ansible Role that installs [Docker](https://www.docker.com) on Linux. diff --git a/defaults/main.yml b/defaults/main.yml index ccc3b1c..db1a9f6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -56,3 +56,16 @@ docker_users: [] # Docker daemon options as a dict docker_daemon_options: {} + +# A list of docker volumes that will be created +docker_volumes: [] + +# Example: + +# --- +# docker_volumes: +# - name: data +# driver_options: +# type: nfs +# o: addr=10.0.2.2,rw,nfsvers=4 +# device: ":/data/" \ No newline at end of file diff --git a/tasks/docker-volumes.yml b/tasks/docker-volumes.yml new file mode 100644 index 0000000..2ade08f --- /dev/null +++ b/tasks/docker-volumes.yml @@ -0,0 +1,9 @@ +--- +- name: Create volumes with options + docker_volume: + name: "{{ item.name }}" + driver_options: + type: "{{ item.driver_options.type }}" + o: "{{ item.driver_options.o | default(omit) }}" + device: "{{ item.driver_options.device }}" + with_items: "{{ docker_volumes }}" diff --git a/tasks/main.yml b/tasks/main.yml index dcd47de..b90fd25 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -96,3 +96,6 @@ - include_tasks: docker-users.yml when: at_least_one_user_to_modify is defined + +- include_tasks: docker-volumes.yml + when: docker_volumes | length > 0 \ No newline at end of file