-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForth-LAB:Working with Ansible Inventories
193 lines (104 loc) · 4.92 KB
/
Forth-LAB:Working with Ansible Inventories
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
Additional Resources
Your company decided that their backup software license was frivolous and unnecessary. Because of this, the license was not renewed. As a stopgap measure, your supervisor has created a simple script and an Ansible playbook to create an archive of select files, depending on pre-defined Ansible host groups. You will create the inventory file to complete the backup strategy.
Important notes:
For your convenience, Ansible has been installed on the control node.
The user ansible has already been created on all servers with appropriate shared keys for access to managed servers from the control node.
The ansible user has the same password as cloud_user.
/etc/hosts entries have been made on control1 for the managed servers.
Learning Objectives
0 of 6 completed
Create the inventory File in /home/ansible/
Create the inventory file in /home/ansible/.
Configure the media Host Group to Contain media1 and media2
Use an editor, such as Vim, to configure the media host group to contain media1 and media2.
Define Variables for media with Their Accompanying Values
Define the following variables for media with their accompanying values:
media_content should be set to /tmp/var/media/content/.
media_index should be set to /tmp//opt/media/mediaIndex.
Configure the webservers Host Group to Contain the Hosts web1 and web2
Configure the webservers host group to contain the hosts web1 and web2.
Define Variables for webservers with Their Accompanying Values
Define the following variables for webservers with their accompanying values:
httpd_webroot should be set to /var/www/.
httpd_config should be set to /etc/httpd/.
Define the script_files Variable for web1 and Set Its Value to /usr/local/scripts
Define the variable script_files specifically for web1. The value of script_files should be set to /tmp/usr/local/scripts.
To test your inventory, run /home/ansible/scripts/backup.sh.
If you have correctly configured the inventory, it should not error.
Note: Do not edit anything in /home/ansible/scripts/.
-------------------------------------
Working with Ansible Inventories
This course is not approved or sponsored by Red Hat.
Introduction
Your company decided that their backup software license was frivolous and unnecessary. Because of this, the license was not renewed. As a stopgap measure, your supervisor has created a simple script and an Ansible playbook to create an archive of select files, depending on pre-defined Ansible host groups. You will create the inventory file to complete the backup strategy.
Solution
Log in to the server using the provided lab credentials:
ssh ansible@<PUBLIC_IP_ADDRESS>
If you are logged in as cloud_user, switch to ansible using the same password provided for cloud_user:
su - ansible
Configure the media Host Group to Contain media1 and media2
Create the inventory file:
touch /home/ansible/inventory
Edit the inventory file:
vim /home/ansible/inventory
Paste in the following:
[media]
media1
media2
To save and exit the file, press ESC, type :wq, and press Enter.
Define Variables for media with Their Accompanying Values
Create a group_vars directory:
mkdir group_vars
Move into the group_vars directory:
cd group_vars/
Create a media file:
touch media
Edit the media file:
vim media
Paste in the following:
media_content: /tmp/var/media/content/
media_index: /tmp/opt/media/mediaIndex
To save and exit the file, press ESC, type :wq, and press Enter.
Configure the webservers Host Group to Contain the Hosts web1 and web2
Move into the home directory:
cd ~
Edit the inventory file:
vim inventory
Beneath media2, paste in the following:
[webservers]
web1
web2
To save and exit the file, press ESC, type :wq, and press Enter.
Define Variables for webservers with Their Accompanying Values
Move into the group_vars directory:
cd group_vars/
Create a webservers file:
touch webservers
Edit the file:
vim webservers
Paste in the following:
httpd_webroot: /var/www/
httpd_config: /etc/httpd/
To save and exit the file, press ESC, type :wq, and press Enter.
Define the script_files Variable for web1 and Set Its Value to /usr/local/scripts
Move into the home directory:
cd ~
Create a host_vars directory:
mkdir host_vars
Move into the host_vars directory:
cd host_vars/
Create a web1 file:
touch web1
Edit the file:
vim web1
Paste in the following:
script_files: /tmp/usr/local/scripts
To save and exit the file, press ESC, type :wq, and press Enter.
Testing
Return to the home directory:
cd ~
Run the backup script:
/home/ansible/scripts/backup.sh
If you have correctly configured the inventory, it should not error.
Conclusion
Congratulations — You've completed this hands-on lab!