Anfield
(Anfield)
August 17, 2017, 1:17am
1
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
roles:
- { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }
My playbook and role call below ->
Role call
---
- 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
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
Anfield
(Anfield)
August 17, 2017, 8:21pm
3
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?
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.
---
- hosts: 10.10.0.5
become: yes
roles:
- {role: test1, tags: [ 'test1']}
Anfield
(Anfield)
August 18, 2017, 3:13pm
5
If I remove the tag from the role and leave it on the task, then it will run both tasks? Both tasks are tagged
What is your desired result from using the tags?
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."
Anfield
(Anfield)
August 22, 2017, 3:45pm
8
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