Using Tags to Control Task Execution in Ansible Playbooks

preview_player
Показать описание
If we want to create usable Ansible Playbooks then having some control feature such as tags is going to be really useful. For example, we could have one playbook that could be used to create and delete users. But we would need to ensure that the correct tasks, block or plays executed.

We look at tags but see how using the playbooks without tags still cause both tasks to run. The builtin Ansible tag never is the correct way in our case to resolve the issue in a Playbooks

-~-~~-~~~-~~-~-
Please watch: "RHCSA 9 Working With Podman Containers"
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

The best way to use Ansible tags is to not at all. If you need to control task execution do so putting hosts into groups. Using groups not only makes it easier to follow through what is going to be executed, it also consolidates this info within the inventory.

To demonstrate this, let's imagine you have a bunch of Linux servers with standardized hardening settings, firewall rules etc.
You group them all into a host group called linux_servers. Now some of those servers are webservers, some of them are database server, some are app servers.
You group them up into a respective group for each type. What you can then do is have certain roles only be applicable to certain groups.
Now let's assume you want to add a new webserver - you add an entry for that new server in your inventory, add it to the groups for linux_server and webservers.
Bam, you got what a sane person would assume tags would do but without the shenanigans of having to add "always" or "never" tags to random bits and pieces over your roles.

Trust me when I tell you, screw tags, use groups, I've tried using them before learning how to properly utilize groups and they have caused me so many headaches.

Skyfox
Автор

very thorough tutorial. thank you very much.🙂

ajk
welcome to shbcf.ru