Tagging tasks in playbooks
Ansible “tags:” is a attribute in ansible playbook.
If you have a large playbook it may become useful to be able to run a specific part of the configuration without running the whole playbook.
When you execute a playbook, you can filter tasks based on tags.
Lets see example,
Here I create a playbook for mysql install and start running it using tags in this playbook,
[ansible@ansible1 ~]$ vi mysqld.yml
My playbook is mysqld.yml, here I can use yum to install mysql-server latest version and start the service in that.
In that playbook I have added two tags one is ‘package’ and another one is ‘startup’.
Now we can run the playbook using tags command,
[ansible@ansible1 ~]$ ansible-playbook mysqld.yml --tags "package” “startup"
Go back to the node machine and check service active or not.
Sudo systemctl status mysqld
Yes its started, running successfully!!.