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
Copy file name to clipboardExpand all lines: content/modules/ROOT/pages/03-vm-management.adoc
+23-60Lines changed: 23 additions & 60 deletions
Original file line number
Diff line number
Diff line change
@@ -50,19 +50,9 @@ $ cd collections/ansible_collections/redhatone/vm_management/roles/vm_management
50
50
This Ansible playbook dynamically calls the role and executes the appropriate
51
51
task based on the `task_file` variable given.
52
52
53
-
. Navigate to your `virt-aap-day2` directory
53
+
. Within your VSCode editor, right click `virt-aap-day2` and create a New File labeled `manage_vm_playbook.yml`
54
54
+
55
-
----
56
-
$ cd /home/lab-user/virt-aap-day2
57
-
----
58
-
+
59
-
. Create a manage_vm_playbook.yml file
60
-
+
61
-
----
62
-
$ touch manage_vm_playbook.yml
63
-
----
64
-
+
65
-
. Using your favorite editor, create the following Ansible Playbook:
55
+
. Add the following content to the `manage_vm_playbook.yml`
66
56
+
67
57
----
68
58
---
@@ -72,7 +62,7 @@ $ touch manage_vm_playbook.yml
72
62
- redhatone.vm_management.vm_management
73
63
----
74
64
+
75
-
. After making and saving the changes, ensure you commit and push them to your Gitea repository.
65
+
. After making and saving the changes, ensure you commit and push them to your Gitea repository. For detailed instructions, refer to xref:appendix-vscode-commit-push.adoc[].
76
66
77
67
=== Stop a VM Task
78
68
@@ -81,21 +71,11 @@ included in the `vm_management` role, specifically under the `tasks` directory,
81
71
in a file named `stop_vm.yml`. Later in the lab, you will call this task from an
82
72
Ansible playbook to demonstrate its capability.
83
73
84
-
. Navigate to the Tasks Directory:
74
+
. Within your VSCode editor, right click `tasks` of the `vm_management` collection and create a New File labeled `stop_vm.yml`
85
75
+
86
-
* Inside your `vm_management` role directory, go to the `tasks` folder:
$ cd collections/ansible_collections/redhatone/vm_management/roles/vm_management/tasks/
90
-
----
91
-
+
92
-
. Create the `stop_vm.yml` file
93
-
+
94
-
----
95
-
touch stop_vm.yml
96
-
----
97
-
+
98
-
. Open the `stop_vm.yml` file with your favorite editor and add the following task
78
+
. Add the following content to the `stop_vm.yml`
99
79
+
100
80
----
101
81
---
@@ -114,7 +94,7 @@ Explanation of the Task:
114
94
* The `running: false` ensures the VM is not running
115
95
* The `wait: true` ensures the next Ansible task isn't triggered until the stop is complete
116
96
+
117
-
. After making and saving the changes, ensure you commit and push them to your Gitea repository.
97
+
. After making and saving the changes, ensure you commit and push them to your Gitea repository. For detailed instructions, refer to xref:appendix-vscode-commit-push.adoc[].
118
98
119
99
=== Create & Run a Job Template with Ansible Automation Platform
120
100
@@ -164,11 +144,9 @@ Virtual Machines that reside within the `vms-aap-day2` namespace and learn how
164
144
to use the debug task to understand the structure of the VM resource `vm_info`
165
145
to identify key fields required to create dynamic Ansible tasks.
166
146
167
-
. Access the `stop_vm.yml` file using your favorite editor
168
-
+
169
-
----
170
-
$ cd collections/ansible_collections/redhatone/vm_management/roles/vm_management/tasks/
171
-
----
147
+
148
+
149
+
. Head back to the VSCode editor to Access the `stop_vm.yml` file
172
150
+
173
151
. Modify the existing `stop_vm.yml` content with the following:
174
152
+
@@ -238,8 +216,10 @@ vm_name: rhel9-vm1
238
216
----
239
217
+
240
218
. Re-run via the `Launch Template` button.
241
-
219
+
+
242
220
image::stop_vms_multiple.png[title='Stopping the VMs', link=self, window=blank]
221
+
+
222
+
. Heading to the OpenShift UI dashboard, you can verify the VMs are stopped within the Virtualization -> Virtual Machines section.
243
223
244
224
=== Start VM Task
245
225
@@ -249,19 +229,9 @@ will be added to the tasks directory in a file named `start_vm.yml`.
249
229
250
230
The following steps will guide you in creating the `start_vm.yml` file.
251
231
252
-
. Inside your `vm_management` role directory, go to the `tasks` folder:
253
-
+
254
-
----
255
-
$ cd collections/ansible_collections/redhatone/vm_management/roles/vm_management/tasks/
256
-
----
257
-
+
258
-
. Create the `start_vm.yml` file
259
-
+
260
-
----
261
-
$ touch start_vm.yml
262
-
----
232
+
. Within your VSCode editor, right click `tasks` of the `vm_management` collection and create a New File labeled `start_vm.yml`
263
233
+
264
-
. Open the `start_vm.yml` file with your favorite editor and add the following task:
234
+
. Add the following content to the `start_vm.yml`
265
235
+
266
236
----
267
237
---
@@ -292,7 +262,7 @@ $ touch start_vm.yml
292
262
293
263
To execute the `manage_vm_playbook.yml` within Ansible Automation Platform, create a Job Template as follows:
294
264
295
-
. Navigate to **Automation Execution → Templates**, click the **Create template** button, and choose **Create job template**.
265
+
. Head to the AAP UI dashboard, navigate to **Automation Execution → Templates**, click the **Create template** button, and choose **Create job template**.
296
266
+
297
267
. Fill out the following details:
298
268
+
@@ -313,26 +283,18 @@ To execute the `manage_vm_playbook.yml` within Ansible Automation Platform, crea
313
283
. Click **Create job template**.
314
284
+
315
285
. Once the `Start VMs` Job Template is created, select the **Launch Template** button on the top right corner to run the job.
286
+
+
287
+
. Head to the OpenShift UI dashboard, you can verify the VMs are running within the Virtualization -> Virtual Machines section.
316
288
317
289
=== Restart VM Task
318
290
319
291
In this lab exercise, you will focus on managing multiple VMs by creating a task to reboot your VMs. This task will be added to the `tasks` directory in a file named `restart_vm.yml`.
320
292
321
293
The following steps will guide you in creating the `restart_vm.yml` file.
322
294
323
-
. Inside your `vm_management` role directory, go to the `tasks` folder:
324
-
+
325
-
----
326
-
$ cd collections/ansible_collections/redhatone/vm_management/roles/vm_management/tasks/
327
-
----
328
-
+
329
-
. Create the `restart_vm.yml` file
330
-
+
331
-
----
332
-
$ touch restart_vm.yml
333
-
----
295
+
. Within your VSCode editor, right click `tasks` of the `vm_management` collection and create a New File labeled `restart_vm.yml`
334
296
+
335
-
. Open the `restart_vm.yml` file with your favorite editor and add the following task:
297
+
. Add the following content to the `restart_vm.yml`
336
298
+
337
299
----
338
300
---
@@ -380,7 +342,7 @@ $ touch restart_vm.yml
380
342
381
343
To execute the `manage_vm_playbook.yml` within Ansible Automation Platform, create a Job Template as follows:
382
344
383
-
. Navigate to **Automation Execution → Templates**, click the **Create template** button, and choose **Create job template**.
345
+
. Head to the AAP UI Dashboard, navigate to **Automation Execution → Templates**, click the **Create template** button, and choose **Create job template**.
384
346
+
385
347
. Fill out the following details:
386
348
+
@@ -401,6 +363,7 @@ To execute the `manage_vm_playbook.yml` within Ansible Automation Platform, crea
401
363
. Click **Create job template**.
402
364
+
403
365
. Once the `Restart VMs` Job Template is created, select the **Launch Template** button on the top right corner to run the job.
366
+
. Head to the OpenShift UI Dashboard to view the changes of the VMs.
404
367
405
368
== Conclusion
406
369
@@ -416,7 +379,7 @@ By the end of this lab, you should now understand:
416
379
417
380
* How to dynamically retrieve and process VM information using the `ansible.builtin.debug` module
418
381
* How to modify a collection and role for starting, stopping, and restarting VMs.
419
-
* How to integrate the `redhatone.vm_managemenet` collection into an Ansible playbook and run it using the Ansible Automation Platform.
382
+
* How to integrate the `redhatone.vm_management` collection into an Ansible playbook and run it using the Ansible Automation Platform.
420
383
421
384
These foundational skills set the stage for further automation, enabling you to
422
385
automate new tasks and optimize resource usage in your environment. In
0 commit comments