feat: replace docker variable to swarm

This commit is contained in:
Adrien Waksberg 2021-11-22 11:43:06 +01:00
parent 8a95fc66e5
commit 66ac6e704a
6 changed files with 24 additions and 24 deletions

View file

@ -1,4 +1,5 @@
---
docker_swarm_manager: false
docker_repo_distribution: '{{ ansible_distribution_release }}'
docker_services: []
swarm_manager: false
swarm_advertise_addr: 127.0.0.1
swarm_services: []
swarm_networks: []

View file

@ -4,11 +4,10 @@
roles:
- swarm
vars:
docker_swarm_manager: true
docker_advertise_addr: 127.0.0.1
docker_networks:
swarm_manager: true
swarm_networks:
- name: proxy
docker_services:
swarm_services:
- name: traefik
image: traefik:1.7
networks:

View file

@ -1,16 +1,16 @@
---
- name: init swarm cluster
community.docker.docker_swarm:
advertise_addr: '{{ docker_advertise_addr }}'
advertise_addr: '{{ swarm_advertise_addr }}'
state: present
when: docker_swarm_manager
tags: docker
when: swarm_manager
tags: swarm
- name: join swarm cluster
community.docker.docker_swarm:
advertise_addr: '{{ docker_advertise_addr }}'
join_token: '{{ docker_join_token }}'
remote_addrs: '{{ docker_remote_addrs }}'
advertise_addr: '{{ swarm_advertise_addr }}'
join_token: '{{ swarm_join_token }}'
remote_addrs: '{{ swarm_remote_addrs }}'
state: join
when: not docker_swarm_manager
tags: docker
when: not swarm_manager
tags: swarm

View file

@ -5,8 +5,8 @@
driver: '{{ item.driver|default("bridge") }}'
scope: swarm
state: '{{ item.state|default("present") }}'
loop: '{{ docker_networks }}'
tags: docker
loop: '{{ swarm_networks }}'
tags: swarm
- name: manage services
community.docker.docker_swarm_service:
@ -22,16 +22,16 @@
env: '{{ item.env|default({}) }}'
container_labels: '{{ item.labels|default({}) }}'
state: present
loop: '{{ docker_services }}'
loop: '{{ swarm_services }}'
when: '"state" not in item or item.state != "absent"'
no_log: false
tags: docker
tags: swarm
- name: remove services
community.docker.docker_swarm_service:
name: '{{ item.name }}'
state: absent
loop: '{{ docker_services }}'
loop: '{{ swarm_services }}'
when: '"state" in item and item.state == "absent"'
no_log: true
tags: docker
tags: swarm

View file

@ -4,10 +4,10 @@
name:
- docker.io
- python3-docker
tags: docker
tags: swarm
- name: enable and start service
ansible.builtin.service:
name: docker
state: started
tags: docker
tags: swarm

View file

@ -2,4 +2,4 @@
- import_tasks: install.yml
- import_tasks: cluster.yml
- import_tasks: config.yml
when: docker_swarm_manager
when: swarm_manager