You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Java home = /usr/lib/jvm/java-17-openjdk-17.0.7.0.7-3.el9.x86_64
54
-
Java version = 17.0.7
55
-
Python version = 3.9.16 (main, Dec 8 2022, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)]
56
-
```
57
27
{{% /details %}}
58
28
59
29
### Task 2
60
30
61
-
* Write a playbook `webserver.yml` that installs the servers in group `web` as webservers. See Lab 4.0 for guidelines.
62
-
* Ensure that the playbook also sets a webpage at `/var/www/html/index.html`.
63
-
* Ensure that the inventory file `hosts` in the folder inventory has the group `web` with `node1` and `node2` as members.
64
-
* Run the playbook `webserver.yml` and check that the webservers are up and running.
31
+
* for possible content of the `my_module.py` file, see the [official documentation](https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#creating-a-module)
32
+
*
65
33
66
34
{{% details title="Solution Task 2" %}}
67
35
68
36
```bash
69
-
cat webserver.yml
70
-
```
71
-
```bash
72
-
---
73
-
- hosts: web
74
-
become: true
75
-
tasks:
76
-
- name: install httpd
77
-
ansible.builtin.dnf:
78
-
name:
79
-
- httpd
80
-
- firewalld
81
-
state: installed
82
-
- name: start and enable httpd
83
-
ansible.builtin.systemd_service:
84
-
name: httpd
85
-
state: started
86
-
enabled: true
87
-
- name: put default webpage
88
-
ansible.builtin.copy:
89
-
content: "Ansible Labs by Puzzle ITC"
90
-
dest: /var/www/html/index.html
91
-
owner: root
92
-
group: root
93
-
mode: "0644"
94
-
- name: start and enable firewalld
95
-
ansible.builtin.systemd_service:
96
-
name: firewalld
97
-
state: started
98
-
enabled: true
99
-
- name: open firewall for http
100
-
ansible.posix.firewalld:
101
-
service: http
102
-
state: enabled
103
-
permanent: true
104
-
immediate: true
105
-
```
106
-
```bash
107
-
cat inventory/hosts
108
-
```
109
-
```bash
110
-
[controller]
111
-
control0 ansible_host=<ip-of-control0>
112
-
113
-
[web]
114
-
node1 ansible_host=<ip-of-node1>
115
-
node2 ansible_host=<ip-of-node2>
116
-
```
117
-
```bash
118
-
ansible-playbook -i inventory/hosts webserver.yml
119
-
sudo dnf install -y lynx
120
-
lynx http://<ip-of-node1>
121
-
lynx http://<ip-of-node2>
122
-
```
123
-
{{% /details %}}
124
-
125
-
### Task 3
126
-
127
-
* Write a rulebook `webserver_rulebook.yml` that checks if the webpages on `node1` and `node2` are up and running.
128
-
* If the webpages are not available anymore, the `webserver.yml` playbook should be re-run.
129
-
* Use `url_check` from the `ansible.eda` collection as the source plugin in your rulebook.
130
-
* Check the availability of the websites every 8 seconds.
131
-
132
-
{{% alert title="Note" color="primary" %}}
133
-
If you don't have the `ansible.eda` collection installed yet,
134
-
`ansible-rulebook` would start, but fail because the `url_check` source plugin cannot be found.
135
-
{{% /alert %}}
136
-
137
-
{{% details title="Solution Task 3" %}}
138
-
```bash
139
-
cat webserver_rulebook.yml
140
-
```
141
-
```bash
142
-
---
143
-
- name: rebuild webservers if site down
144
-
hosts: web
145
-
sources:
146
-
- name: check webserver
147
-
ansible.eda.url_check:
148
-
urls:
149
-
- http://<ip-of-node1>:80/
150
-
- http://<ip-of-node2>:80/
151
-
delay: 8
152
-
rules:
153
-
- name: check if site down and rebuild
154
-
condition: event.url_check.status == "down"
155
-
action:
156
-
run_playbook:
157
-
name: webserver.yml
158
-
```
159
-
{{% /details %}}
160
-
161
-
### Task 4
162
-
163
-
* Start `webserver_rulebook.yml`in verbose mode.
164
-
* Stop the httpd service on `node1` with ansible from another terminal on `control0`
165
-
and see how the playbook `webserver.yml` is re-run.
166
-
(You could also just stop the service directly on `node1`.)
0 commit comments