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
@@ -15,185 +15,85 @@ This presentation will give a broad overview of Ansible and its architecture and
15
15
16
16
Participants will get first-hand insights into Ansible, its strengths, weaknesses, and the potential of event-driven automation within the DevOps world.
17
17
18
-
## Demos
19
-
20
-
<details>
21
-
22
-
<summary>Prerequisites</summary>
23
-
24
-
### Ansible Inventory
25
-
26
18
> [!NOTE]
27
-
> For this inventory file to work, you need to create VMs accordingly and adjust the IP addresses to fit your lab environment.
28
-
29
-
Ansible utilizes so-called inventories to manage a list of hosts and groups of hosts. Below is the inventory for the demo environment used in this presentation.
30
-
31
-
```yaml
32
-
hosts:
33
-
webservers:
34
-
hosts:
35
-
webshop.example.com: # Ubuntu
36
-
ansible_host: 192.168.1.10
37
-
webserver: apache2
38
-
company.example.com: # Ubuntu
39
-
ansible_host: 192.168.1.11
40
-
webserver: nginx
41
-
internal.example.com: # CentOS Stream
42
-
ansible_host: 192.168.1.12
43
-
webserver: httpd
44
-
```
45
-
46
-
You can copy-paste this inventory into a file called `hosts.yml` and use it for the following demos.
47
-
48
-
</details>
19
+
> The below content is a copy of the [lab repository's] README for convenience.
49
20
50
-
<details>
51
-
52
-
<summary>Lab 1: Ansible Basics</summary>
53
-
54
-
### Demo 1: Ansible Basics
55
-
56
-
#### Ansible from the CLI via `ansible`
57
-
58
-
The first example installs a webserver on all hosts in the `webservers` group. The installed webserver is defined as a **host variable** in the inventory file `hosts.yml` (*see above*).
59
-
60
-
```console
61
-
ansible \
62
-
webservers \
63
-
-i hosts.yml \
64
-
-m package \
65
-
-a 'name="{{ webserver }}"'
66
-
```
67
-
68
-
#### Ansible from the CLI via `ansible-playbook`
69
-
70
-
The second example utilizes the following **playbook** to **install** and **start** the defined webserver on all hosts in the `webservers` group.
71
-
72
-
```yaml
73
21
---
74
-
- name: Install webservers
75
-
hosts: webservers
76
-
vars:
77
-
package: "{{ webserver }}"
78
-
become: true
79
-
tasks:
80
-
- name: Install webserver
81
-
ansible.builtin.package:
82
-
name: "{{ package }}"
83
-
state: present
84
-
85
-
- name: Start webserver
86
-
ansible.builtin.service:
87
-
name: "{{ package }}"
88
-
state: started
89
-
```
90
-
91
-
Save this playbook as `playbook.yml` and run it with the following command.
92
22
93
-
```console
94
-
ansible-playbook \
95
-
-i hosts.yml \
96
-
playbook.yml
97
-
```
23
+
# Event-Driven Ansible Lab
98
24
99
-
You will see a separated output for each task in the playbook. In the end, you should be able to access the webserver on each host in the `webservers` group.
25
+
This is a lab designed to demonstrate Ansible and how Event-Driven Ansible (**EDA**) builds on top of its capabilities.
100
26
101
-
> [!TIP]
102
-
> Ansible is **idempotent** - try running the playbook again and see how the output differs.
27
+
The setup is done with Ansible, too. It will install **Ansible, EDA, Prometheus**, and **Alertmanager** on a VM to demonstrate some of the capabilities of EDA.
103
28
104
-
</details>
29
+
## Prerequisites
105
30
106
-
<details>
31
+
To follow along with this lab in its entirety, you will need four VMs:
107
32
108
-
<summary>Lab 2: Event-driven Ansible and Generic Webhooks</summary>
109
-
110
-
### Demo 2: Event-driven Ansible and Generic Webhooks
33
+
> [!NOTE]
34
+
> If you want to skip Ansible basics and go straight to EDA, you'll need just the `eda-controller.example.com` VM and can skip the others.
111
35
112
-
#### Prerequisites
36
+
| VM name | OS |
37
+
|--------------------|-------------|
38
+
| eda-controller.example.com | CentOS/Rocky 8.9 |
39
+
| company.example.com | CentOS/Rocky 8.9 |
40
+
| internal.example.com | Ubuntu 22.04 |
41
+
| webshop.example.com | OpenSUSE 15.5 |
113
42
114
-
For this demo, we will use `localhost` as the target host. Therefore, we need to adjust our inventory file `hosts.yml` accordingly:
43
+
**You'll need to be able to SSH to each of these VMs as root using SSH keys.**
115
44
116
-
```yaml
117
-
hosts:
118
-
localhost: {}
45
+
## Lab Setup
119
46
120
-
The first demo of event-driven Ansible shows how to use a generic webhook to trigger a playbook run. Copy the following rulebook into a file called `rulebook.yml`.
47
+
### Clone the repository and create a Python virtual environment
To start the EDA server, run the following command.
56
+
### Install Ansible and other dependencies
146
57
147
-
```console
148
-
ansible-rulebook \
149
-
-i hosts.yml \
150
-
--rulebook rulebook.yml
58
+
```bash
59
+
pip install -r requirements.txt
151
60
```
152
61
153
-
#### Trigger the webhook
62
+
###Create the inventory file
154
63
155
-
Once the EDA server is running, we can open a second terminal session and double-check that it is listening on the correct port:
156
-
157
-
```console
158
-
netstat -lntup | grep 5000
159
-
```
160
-
161
-
Now, we can trigger the webhook from our second terminal session using `curl`, first with empty input:
162
-
163
-
```console
164
-
curl \
165
-
-H "Content-Type: application/json" \
166
-
-d '{}' \
167
-
http://localhost:5000/endpoint
64
+
```yaml
65
+
---
66
+
# hosts.yml
67
+
webservers:
68
+
hosts:
69
+
webshop.example.com:
70
+
ansible_host: <ip-address>
71
+
webserver: nginx
72
+
company.example.com:
73
+
ansible_host: <ip-address>
74
+
webserver: httpd
75
+
internal.example.com:
76
+
ansible_host: <ip-address>
77
+
webserver: apache2
78
+
eda_controller:
79
+
hosts:
80
+
eda-controller.example.com:
81
+
ansible_host: <ip-address>
168
82
```
169
83
170
-
If we switch over to the first terminal session, we should see the output of the second rule, which is the default case:
171
-
172
-
```console
173
-
Hello World!
84
+
### Install Needed Roles and Collections
85
+
86
+
```bash
87
+
ansible-galaxy install -r requirements.yml
174
88
```
175
89
176
-
Now, we can trigger the webhook again, this time with a payload:
90
+
### Run the Setup Playbook
177
91
178
-
```console
179
-
curl \
180
-
-H "Content-Type: application/json" \
181
-
-d '{"greeting": "Daniel"}' \
182
-
http://localhost:5000/endpoint
183
-
```
184
-
185
-
If we switch over to the first terminal session again, we should see the output of the first rule, which is the case for a defined `greeting` in the payload:
92
+
After you created the inventory file and filled in the IP addresses, you can run the setup playbook:
0 commit comments