forked from discover-devops/my_ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwam playbook.txt
35 lines (31 loc) · 1.1 KB
/
Swam playbook.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
- hosts: docker-manager-first
remote_user: root
become: yes
tasks:
- name: "create primary swarm manager"
shell: docker swarm init --advertise-addr {{ipaddress }}
- name: "get docker swarm manager token"
shell: docker swarm join-token -q manager
register: manager_token
- name: "get docker swarm worker token"
shell: docker swarm join-token -q worker
register: worker_token
- hosts: docker-managers
remote_user: root
become: yes
tasks:
- name: "join as a manager"
shell: "docker swarm join --token {{ hostvars['manager1']['manager_token']['stdout'] }} {{ hostvars['manager1']['ansible_eth0']['ipv4']['address'] }}:2377"
when: docker_info.stdout.find("Swarm{{':'}} inactive") != -1
retries: 3
delay: 20
- hosts: docker-workers
remote_user: root
become: yes
become_method: sudo
tasks:
- name: "join as a worker"
shell: "docker swarm join --token {{ hostvars['manager1']['worker_token']['stdout'] }} {{ hostvars['manager1']['ansible_eth0']['ipv4']['address'] }}:2377"
when: "docker_info.stdout.find('Swarm: inactive') != -1"
retries: 3
delay: 20