1
0
IaC/ansible/roles/docker/tasks/main.yaml

83 lines
2.6 KiB
YAML
Raw Normal View History

2024-04-24 05:40:00 -04:00
---
- name: Install Docker on Archlinux
when: ansible_facts['os_family'] == "Archlinux"
community.general.pacman:
name: docker
state: present
update_cache: true
- name: Add users to docker group
ansible.builtin.user:
name: "{{ item }}"
groups: docker
append: true
loop: "{{ docker_users }}"
- name: Start and enable Docker
ansible.builtin.systemd:
name: docker
state: started
enabled: true
- name: Create Docker networks
when:
- docker_networks is defined
- docker_networks | length > 0
community.docker.docker_network:
attachable: "{{ item.attachable | default(true) }}"
driver: "{{ item.driver | default('bridge') }}"
driver_options: "{{ item.driver_options | default(omit) }}"
enable_ipv6: "{{ item.enable_ipv6 | default(false) }}"
internal: "{{ item.internal | default(false) }}"
ipam_config: "{{ item.ipam | default(omit) }}"
name: "{{ item.name }}"
state: "present"
loop: "{{ docker_networks }}"
- name: Create Docker volumes
when:
- docker_volumes is defined
- docker_volumes | length > 0
community.general.docker_volume:
driver: "{{ item.driver | default('local') }}"
# driver_options: "{{ item.driver_options | default({}) }}"
recreate: "never"
state: "present"
volume_name: "{{ item.name }}"
loop: "{{ docker_volumes }}"
- name: Pull Docker images
when:
- docker_images is defined
- docker_images | length > 0
community.docker.docker_image_pull:
name: "{{ item.name }}"
pull: "always"
tag: "{{ item.tag | default('latest') }}"
loop: "{{ docker_images }}"
- name: Create Docker containers
when:
- docker_containers is defined
- docker_containers | length > 0
community.general.docker_container:
auto_remove: "{{ item.auto_remove | default(false) }}"
capabilities: "{{ item.capabilities | default(omit) }}"
command: "{{ item.command | default(omit) }}"
detach: true
domainname: "{{ item.domainname | default(omit) }}"
entrypoint: "{{ item.entrypoint | default(omit) }}"
env: "{{ item.env | default({}) }}"
etc_hosts: "{{ item.etc_hosts | default({}) }}"
hostname: "{{ item.hostname | default(item.name) }}"
image: "{{ item.image }}"
name: "{{ item.name }}"
networks: "{{ item.networks | default(omit) }}"
published_ports: "{{ item.ports | default([]) }}"
restart_policy: "{{ item.restart_policy | default('unless_stopped') }}"
state: 'started'
sysctls: "{{ item.sysctls | default({}) }}"
volumes: "{{ item.volumes | default([]) }}"
loop: "{{ docker_containers }}"