Ansible — TAGS

Khemnath chauhan
1 min readNov 16, 2022

--

TAGS- Is one of the Ansible feature that may be handy when running large playbook. It will allow you to run only specific parts of it instead of running the entire playbook.

Using tags to execute or skip selected tasks is a two-step process-:

  • Add tags to your tasks, either individually or with tag inheritance from a block, play, role, or import.
  • Select or skip tags when you run your playbook.

Adding tags with the tags keyword:

We can add tags to a single task or include. We can also add tags to multiple tasks by defining them at the level of a block, play, role, or import. The tags keyword always defines tags and adds them to tasks; it does not select or skip tasks for execution. You can only select or skip tasks based on tags at the command line when you run a playbook.

#Adding tags to individual tasks

tasks:
- name: Install the servers
yum:
name:
- httpd
- memcached
state: present
tags:
- packages
- webservers

- name: Configure the service
template:
src: templates/src.j2
dest: /etc/foo.conf
tags:
- configuration

--

--

Khemnath chauhan
Khemnath chauhan

No responses yet