-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFifth-LAB: Ansible Playbooks: The Basics
125 lines (78 loc) · 6.33 KB
/
Fifth-LAB: Ansible Playbooks: The Basics
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
Additional Resources
Your company has been increasing the deployment of small broacher-style websites for clients. The head of IT has decided that each client should have their own web servers for better client isolation and has tasked you with creating concept automation to quickly deploy web-nodes with simple static website content.
You have been provided an ansible control node and 2 test lab servers (node1 and node2) that have been preconfigured with the ansible user and key.
You must create an ansible inventory in /home/ansible/inventory containing a host group named web. The web group should contain node1 and node2.
Furthermore, you must design an Ansible playbook that will execute the following tasks on your configured inventory: install httpd, start and enable the httpd service, and install a simple website provided on a repo server. Create the playbook in /home/ansible/web.yml. The simple website may be accessed from http://repo.example.com/website.tgz.
Note: Please wait an extra minute before starting the lab to make sure it is fully provisioned.
Summary tasks list:
Create an inventory in /home/ansible/inventory containing a host group named web. The web group should contain node1 and node2.
Create a playbook in /home/ansible/web.yml.
Configure the playbook to install httpd on the web group.
Configure the playbook to start and enable the httpd service on the web group.
Configure the playbook to retrieve the website from http://repo.example.com/website.tgz on each server in the web group.
Configure the playbook to unarchive the website into /var/www/html on all servers in the web group.
Execute the playbook you created using the inventory you created to verify your work.
Important notes:
For your convenience, Ansible has been installed on the control node.
The user ansible is present 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 7 completed
Create an Inventory in `/home/ansible/inventory `That Contains a Host Group Named `web`. The `web` Group Should Contain `node1` and `node2`
echo "[web]" >> /home/ansible/inventory
echo "node1" >> /home/ansible/inventory
echo "node2" >> /home/ansible/inventory
Create a Playbook in `/home/ansible/web.yml`
echo "---" >> /home/ansible/web.yml
Configure the Playbook to Install `httpd` on the `web` Group
Using a text editor, such as vim, edit /home/ansible/web.yml to contain the following text block below the line containing "---": - hosts: web become: yes tasks: - name: install httpd yum: name=httpd state=latest
Configure the Playbook to Start and Enable the `httpd` Service on the `web` Group
Using a text editor such as vim, edit /home/ansible/web.yml to contain the following task block after the "install httpd task": - name: start and enable httpd service: name=httpd state=started enabled=yes
Configure the Playbook to Retrieve the Website from *http://repo.example.com/website.tgz* on Each Server in the `web` Group
Using a text editor such as vim, edit /home/ansible/web.yml to contain the following task block after the "start and enable httpd" task: - name: retrieve website from repo get_url: url=http://repo.example.com/website.tgz dest=/tmp/website.tgz
Configure the Playbook to Unarchive the Website into `/var/www/html` on All Servers in the `web` Group
Using a text editor such as vim, edit /home/ansible/web.yml to contain the following task block after the "retrieve website from repo" task: - name: install website unarchive: remote_src=yes src=/tmp/website.tgz dest=/var/www/html/
Verify the Work by Executing the Playbook Using the Inventory
ansible-playbook -i /home/ansible/inventory /home/ansible/web.yml
------------------------------------------------------
Ansible Playbooks - the Basics
This course is not approved or sponsored by Red Hat.
The Scenario
Our company has been increasing the deployment of small brochure-style websites for clients. The head of IT has decided that each client should have their own web server, for better client isolation, and has tasked us with creating concept automation to quickly deploy web-nodes with simple static website content.
We have been provided an Ansible control node (control1) and 2 test lab servers (node1 and node2) that have been preconfigured with the ansible user and key.
We must create an Ansible inventory in /home/ansible/inventory containing a host group named web. The web group should contain node1 and node2.
Then we've got to design an Ansible playbook that will execute the following tasks on your configured inventory:
Install httpd
Start and enable the httpd service
Install a simple website provided on a repository server.
The playbook will be in /home/ansible/web.yml. The simple website may be accessed from http://repo.example.com/website.tgz.
Get Logged In
Login credentials are all on the lab overview page. Once we're logged into the control1 server, become the ansible user (su - ansible) and we can get going.
Create an inventory in /home/ansible/inventory That Contains a Host Group Named web. The web Group Should Contain node1 and node2
Use Vim to create the inventory file:
[ansible@control1]$ echo "[web]" >> /home/ansible/inventory
[ansible@control1]$ echo "node1" >> /home/ansible/inventory
[ansible@control1]$ echo "node2" >> /home/ansible/inventory
It should contain this when we're done:
[web]
node1
node2
Create a Playbook in /home/ansible/web.yml
Using Vim, we'll create our web.yml file with these contents:
---
- hosts: web
become: yes
tasks:
- name: install httpd
yum: name=httpd state=latest
- name: start and enable httpd
service: name=httpd state=started enabled=yes
- name: retrieve website from repo
get_url: url=http://repo.example.com/website.tgz dest=/tmp/website.tgz
- name: install website
unarchive: remote_src=yes src=/tmp/website.tgz dest=/var/www/html/
Verify the Work by Executing the Playbook Using the Inventory
[ansible@control1]$ ansible-playbook -i /home/ansible/inventory /home/ansible/web.yml
Conclusion
This new setup is everything we needed. The Ansible playbook installs httpd, starts and enables it, and creates a simple website, all on it's own web node. That's what we needed. Congratulations!