-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathswarm.yml
51 lines (47 loc) · 1.49 KB
/
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
44
45
46
47
48
49
50
51
- name: Install Ansible Prereqs
hosts: swarm-master:swarm-nodes
gather_facts: no
tasks:
- raw: "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y python-minimal python-pip"
- name: Install Docker Prereqs
hosts: swarm-master:swarm-nodes
gather_facts: yes
tasks:
- package:
name: "{{item}}"
state: latest
with_items:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- apt_key:
url: "https://download.docker.com/linux/ubuntu/gpg"
state: present
- apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
state: present
- name: Install Docker
hosts: swarm-master:swarm-nodes
gather_facts: yes
tasks:
- package:
name: "docker-ce"
state: latest
- user:
name: "{{ ansible_ssh_user }}"
groups: docker
append: yes
- name: Initialize Swarm Master
hosts: swarm-master
gather_facts: yes
tasks:
- command: "docker swarm init --advertise-addr {{inventory_hostname}}"
- command: "docker swarm join-token -q worker"
register: swarm_token
- set_fact: swarmtoken="{{swarm_token.stdout}}"
- name: Join Swarm Nodes
hosts: swarm-nodes
gather_facts: yes
tasks:
- command: "docker swarm join --advertise-addr {{inventory_hostname}} --token {{hostvars[groups['swarm-master'][0]].swarmtoken}} {{hostvars[groups['swarm-master'][0]].inventory_hostname}}:2377"