-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathansiblebatch16
More file actions
221 lines (121 loc) · 4.61 KB
/
ansiblebatch16
File metadata and controls
221 lines (121 loc) · 4.61 KB
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
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
==========================
Part 1 Create 3 ubuntu VM’s or Docker container
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
CONTAINER ID IMAGE COMMAND CREATED STATUS PO
RTS NAMES
0a640c65b28f ubuntu "/bin/bash" 4 seconds ago Up 3 seconds
target2
a1218da0535c ubuntu "/bin/bash" 13 seconds ago Up 12 seconds
target1
b40e796c2c56 ubuntu "/bin/bash" 36 seconds ago Up 34 seconds
ansible_master
done
Step 3 check the process and name for verification
docker ps
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
ansible 2.9.6
-- done ------------------
Step 5 Login to target 1
docker exec -it target1 bash
Step 6 Update and install SSH and required dependencies
apt update
apt install vim python iputils-ping openssh-client -y
apt-get install openssh-server -y
Geographical area 6 city 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
Step 8 Start the service ssh if its not running
service ssh status
service ssh start
service ssh status
target 1 ssh service started ---
---------------------------
Step 9 change the root password to admin
passwd root
Admin
Admin
admin for target 1 containet
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 "IPAddress": "172.17.0.3",
sudo docker inspect target2
You will find the IPAddress like 172.17.0.3
--------------
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
Step 14 verify as you are able to ping target machine from ansible_master
Ping <Target machine IP>
yes ping works for me
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
Step 16 You should be able to connect via target machine from ansible_master
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
Step 18 : Run ansible playbook
ansible-playbook installnginx.yaml
Validation :-
You can verify login to target machine and check is Nginx Service is running or not
docker exec -it target1 bash
service nginx status
And
docker exec -it target2 bash
service nginx status
Nginx should be running in both the target machines / containers