-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathansible.txt
258 lines (137 loc) · 4.82 KB
/
ansible.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
Part 1 Create 3 ubuntu VM’s or Docker container
step 1 , step 2 and step 3
Part 2 install Ansible and requires tools in ansible_master
step 4 ,
Part 3 Setup n number of target machines (2)/ container(2) configure SSH and allow
PermitRootLogin and change the root password
step 5 , step 6 , step 7, step 8 , step 9
Part 4 Perform the same all steps with target 2 and so on
step 10
Part 5 Find the IP’s of all targets container for adding in ansible host file
step 11
Part 6 setup ansible_master for ssh connectivity and adding IP’s in hostfile
step 12 , step 13 , step 14
Part 7 copy the generated ssk keys from ansible_master to target machine and check the connectivity
step 15 , step 16
Part 8 create a ansible playbook and run
step 17
Part 9 Login to the target machine / Container and verify is nginx installed or not
---------------
Step 1 Go to docker playground create an instance / node and create 3 Ubuntu container
1st - ansible_master
2nd target 1
3rd target 2
Step 2 create containers
docker run -itd --name ansible_master ubuntu /bin/bash
docker run -itd --name target1 ubuntu /bin/bash
docker run -itd --name target2 ubuntu /bin/bash
done
Step 3 check the process and name for verification
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
75cb389ef9af ubuntu "/bin/bash" About a minute ago Up About a minute target
2
2ab9d8441caf ubuntu "/bin/bash" About a minute ago Up About a minute target
1
6eb1763de81f ubuntu "/bin/bash" About a minute ago Up About a minute ansibl
e_master
done
Part 2 install Ansible and requies tools in ansible_master
Step 4 go to ansible_master container update the ubuntu and install some dependencies and ansible
docker exec -it ansible_master bash
apt update
apt install python ansible vim iputils-ping openssh-client -y
ansible --version
done
--------------
Part 3 Setup n number of target machines (2)/ container(2)Login to Target and setup target 1
Step 5 Login to target 1
docker exec -it target1 bash
docker exec -it target2 bash
done
Step 6 Update and install SSH and required dependencies
apt update
apt install vim python iputils-ping openssh-client -y
apt-get install openssh-client openssh-server -y
Geographical area 6city 44
done
Step 7 edit sshd_config to allow SSH and root login as ansible requires
cd /etc/ssh
vi sshd_config
uncomment the parameter and modify the permission to yes PermitRootLogin yes and PasswordAuthentication yes
done
Step 8 Start the service ssh if its not running
service ssh status
service ssh start
service ssh status
done taget 2
------------------------------------
Step 9 change the root password to admin
passwd root
admin
admin
root has a passwod admin
done
ansible -- target1 root
done
target 1 and target 2
Part 4 Perform the same all steps with target 2 and so on
Step 10
Part 5 Find the IP’s of all targets container for adding in ansible host file
Come out to docker node and run the command
Step 11
sudo docker inspect target1
sudo docker inspect target2
You will find the IPAddress like 172.17.0.3
"IPAddress": "172.17.0.3", - 1
"IPAddress": "172.17.0.4", - 2
-------------
Part 6 setup ansible_master for ssh connectivity and adding IP’s in hostfile
Step 12 go to ansible_master
docker exec -it ansible_master bash
Step 13 edit ansible host file and provide the target IP’s
cd /etc/ansible/
ls
Go to hosts file
provide the IP of the target machines
done
Step 14 verify as you are able to ping target machine from ansible_master
Ping <Target machine IP>
ping 172.17.0.3
done
go back to master machine
Step 15
generate the ssh key from the ssh-keygen command
ssh-keygen
provide 3 times enter (1 location verification + 2 time for passwd )
done
generated
----
Part 7 copy the generated ssh keys from ansible_master to target machine and check the connectivity
Step 15 Copy the generated key from ansible_master to remote target
ssh-copy-id [email protected]
yes
target 1
--- 2 will fail --
target 1 -- nginx --
not in target 1
root@2ab9d8441caf:~# service nginx status
nginx: unrecognized service
----------------
Part 8 Now create a ansible playbook and run ansible-playbook
Step 17 :- create a installnginx.yaml file in
cd /etc/ansible
vi installnginx.yaml
---
- hosts: all
tasks:
- name: ensure nginx is at the latest version
apt: name=nginx state=latest
- name: start nginx
service:
name: nginx
state: started
don e_master
Step 18 : Run ansible playbook
ansible-playbook installnginx.yaml