-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible_lab_master_slave.yml
116 lines (104 loc) · 3.67 KB
/
ansible_lab_master_slave.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
- name: Start Master Container (CLI)
command: docker run -d -P --name=master-{{ master_name }} -h master-{{ master_name }} ansible_lab/master:latest
register: run_master
failed_when:
- "'Conflict' not in run_master.stderr"
- "run_master.rc != 0"
changed_when:
- "'No such container' not in run_master.stderr"
- "run_master.rc == 0"
tags:
- cli_startup
- name: Start Master Container (Module)
docker_container:
name: master-{{ master_name }}
hostname: master-{{ master_name }}
image: ansible_lab/master:latest
state: started
published_ports: all
tags:
- m_startup
- name: SSH forwarding into bashrc
command: echo "ssh root@`docker exec master-{{ master_name }} hostname -I`;exit" >> /home/ansiblelabuser{{ master_name }}/.bashrc
tags:
- m_startup
- cli_startup
- name: Start Slave Container (CLI)
command: docker run -d -P --name=master-{{ master_name }}-slave-{{ item }} -h master-{{ master_name }}-slave-{{ item }} ansible_lab/slave:latest
register: run_slave
failed_when:
- "'Conflict' not in run_slave.stderr"
- "run_slave.rc != 0"
changed_when:
- "'No such container' not in run_slave.stderr"
- "run_slave.rc == 0"
with_sequence: start=1 end={{ slaves }}
tags:
- cli_startup
- name: Start Slave Container (Module)
docker_container:
name: master-{{ master_name }}-slave-{{ item }}
hostname: master-{{ master_name }}-slave-{{ item }}
image: ansible_lab/slave:latest
state: started
published_ports: all
register: run_slave
with_sequence: start=1 end={{ slaves }}
tags:
- m_startup
- name: Copy SSH Keys to Master (id_rsa)
command: docker cp /home/ansiblelabuser{{ master_name }}/.ssh/id_rsa master-{{ master_name }}:/root/.ssh/id_rsa
tags:
- m_startup
- cli_startup
- ssh_key_exchange
- name: Copy SSH Keys to Master (public)
command: docker cp /home/ansiblelabuser{{ master_name }}/.ssh/id_rsa.pub master-{{ master_name }}:/root/.ssh/authorized_keys
tags:
- m_startup
- cli_startup
- ssh_key_exchange
- name: Copy SSH Keys to Slaves (id_rsa.pub)
command: docker cp /home/ansiblelabuser{{ master_name }}/.ssh/id_rsa.pub master-{{ master_name }}-slave-{{ item }}:/root/.ssh/authorized_keys
with_sequence: start=1 end={{ slaves }}
tags:
- m_startup
- cli_startup
- ssh_key_exchange
- name: Remove Slave Containers (CLI)
command: docker stop -t=0 master-{{ master_name }}-slave-{{ item }} && docker rm -f master-{{ master_name }}-slave-{{ item }}
register: stop_slave
failed_when:
- "'No such container' not in stop_slave.stderr"
- "stop_slave.rc != 0"
changed_when:
- "'No such container' not in stop_slave.stderr"
- "stop_slave.rc == 0"
with_sequence: start=1 end={{ slaves }}
tags:
- cli_shutdown
- name: Remove Master Containers (CLI)
command: docker stop -t=0 master-{{ master_name }} && docker rm -f master-{{ master_name }}
register: stop_master
failed_when:
- "'No such container' not in stop_master.stderr"
- "stop_master.rc != 0"
changed_when:
- "'No such container' not in stop_master.stderr"
- "stop_master.rc == 0"
tags:
- cli_shutdown
- name: Remove Slave Containers (Module)
docker_container:
name: master-{{ master_name }}-slave-{{ item }}
state: absent
with_sequence: start=1 end={{ slaves }}
tags:
- m_shutdown
- name: Remove Master Containers (Module)
docker_container:
name: master-{{ master_name }}
state: absent
tags:
- m_shutdown