-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-swarm.yml
44 lines (35 loc) · 1 KB
/
docker-swarm.yml
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
36
37
38
39
40
41
42
43
---
- name: Set up Docker Swarm
hosts: localhosts
become: true
tasks:
- name: Install Docker
apt:
name: docker.io
state: present
- name: Initialize Swarm
command: docker swarm init --advertise-addr {{ 192.168.43.34}}
register: swarm_init
changed_when: "'already exists' not in swarm_init.stdout"
- name: Retrieve join token
command: docker swarm join-token -q worker
register: join_token
handlers:
- name: Save join token
copy:
content: "{{ join_token.stdout }}"
dest: /tmp/join_token.txt
- name: Join Swarm as worker
hosts: swarm_workers
become: true
tasks:
- name: Install Docker
apt:
name: docker.io
state: present
- name: Retrieve join token
fetch:
src: /tmp/join_token.txt
dest: /tmp/join_token.txt
- name: Join Swarm
command: docker swarm join --token {{ lookup('file', '/tmp/join_token.txt') }} {{ hostvars['swarm_manager']['ansible_host'] }}