# How to call roles & specify tags for those roles

**URL:** <https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274>\
**Category:** Ansible Project\
**Created:** [August 17, 2017, 1:17am UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274 "2017-08-17T01:17:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [August 17, 2017, 1:17am UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/1 "2017-08-17T01:17:37Z")

</div>

Trying to run an example from the ansible docs, and it seems to always run both the tagged portions of the playbook…

Am I missing how calling a role with tags is supposed to be used?

Ansible docs -

[http://docs.ansible.com/ansible/latest/playbooks\_tags.html](http://docs.ansible.com/ansible/latest/playbooks_tags.html)

```auto
roles:
  - { role: webserver, port: 5000, tags: ['web', 'foo'] }

```

`My playbook and role call below ->`

```auto

```

```auto
Role call

```

```auto

---
- hosts: 10.10.0.5
  become: yes
  roles:
    - {role: apache, tags: ['config_apache']}

```

`tasks/main.yml`

`- name: Install apache`  
`yum:`  
`name: httpd`  
`state: latest`  
`tags: apache_install`

`- name: Config apache`  
`lineinfile:`  
`path: /etc/httpd/conf/httpd.conf`  
`line: penguin`  
`tags: config_apache`

```auto

```

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [August 17, 2017, 8:07pm UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/2 "2017-08-17T20:07:31Z")

</div>

If you are adding a tag to a role, there is no need to use the same tag on any of the tasks within the role.

So running your playbook with -t config\_apache will include both tasks. Running it with -t apache\_install will only run the Install apache task.

[http://docs.ansible.com/ansible/latest/playbooks\_tags.html#tag-inheritance](http://docs.ansible.com/ansible/latest/playbooks_tags.html#tag-inheritance)

---

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [August 17, 2017, 8:21pm UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/3 "2017-08-17T20:21:36Z")

</div>

Ok…Not sure I follow. So what would be the point then in calling a role with tags at all, if you cannot define which tag to use?

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [August 17, 2017, 8:33pm UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/4 "2017-08-17T20:33:04Z")

</div>

I use tags at the role level when I have a play that contains multiple roles. If all you’re wanting to do is run the config apache task, remove the config\_apache tag from the role and leave it on the task. Hopefully I’m understanding your question correctly.

```auto
---
- hosts: 10.10.0.5
  become: yes
  roles:
    - {role: test1, tags: ['test1']}

```

---

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [August 18, 2017, 3:13pm UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/5 "2017-08-18T15:13:20Z")

</div>

If I remove the tag from the role and leave it on the task, then it will run both tasks? Both tasks are tagged

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [August 18, 2017, 3:26pm UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/6 "2017-08-18T15:26:25Z")

</div>

What is your desired result from using the tags?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 18, 2017, 8:55pm UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/7 "2017-08-18T20:55:51Z")

</div>

I guess you did not read that link carefully enough 🙂

From the link:  
"You can ONLY filter tasks based on tags from the command line with –tags or –skip-tags."

---

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [August 22, 2017, 3:45pm UTC](https://forum.ansible.com/t/how-to-call-roles-specify-tags-for-those-roles/25274/8 "2017-08-22T15:45:44Z")

</div>

Good question Mike, no requirement, just learning this incase it comes up in the cert. exam. Based on that link from the docs I still dont know why you would call a role with tags
