Tagging tasks in Playbook

Tagging tasks in playbooks 

Ansible “tags:” is an 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.

Let's see an example,

Here I create a playbook for MySQL install and start running it using tags in this playbook,

[ansible@ansible1 ~]$ cat mysqld.yml

---

- hosts: single

  become: yes

  tasks:

    - name: install mariadb-server

      yum: name=mariadb-server state=latest

      ignore_errors: yes

      register: there

      tags:

       - packages

    - name: start mariadb if there

      service: name=mariadb state=started

      register: running

      tags:

       - startup   


My playbook is mysqld.yml, here I can use yum to install the 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 the 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, it's started, running successfully!!.  




Relevant Blogs:

Ansible Install MSI in windows  

Ansible Vault 

Nagios threshold configuration 

AWS Elastic Container Service

Recent Comments

No comments

Leave a Comment