Are Tags from the dark side ???

53 views
Skip to first unread message

akazi...@gmail.com

unread,
Nov 21, 2017, 2:53:12 AM11/21/17
to Ansible Project
Hello 

I have been reading squilions of articles but I am still unsure if the usage of tags is a good practice. It seems to me that adding tags to tasks quickly leads to a cumbersome situation. How ever a tag on a role might be ok?

I think of having a main yaml like sites.yml which includes  all needed playbooks e.g. webservers.yml and dbservers.yml
The playbooks e.g. webservers.yml  define the hosts to act on and the roles to run. 
The roles should self standing and independent, I think of tagging the role with its own name. eg. javajdk gets tag: javajdk

so I can run 
       ansible-playbook -i inventory/staging webservers     
to do a complet setup or
       so I can run ansible-playbook -i inventory/staging webservers -t javajdk 
to only setup javajdk on the webservers
 
.
├── inventories
│   ├── production
│   └── staging
├── roles
│   ├── tomcat
│   └── javajdk
├── site.yml
├── dbservers.yml
└── webservers.yml


What do you think? Did I got it correct? Is there a better approach ?

Thanks a lot :-)
Michael

akazi...@gmail.com

unread,
Nov 21, 2017, 4:32:28 AM11/21/17
to Ansible Project
Here is a littel edit:
I struggle to find the correct place where I would add the tag for the role. I do not want to tag the role in webservers.yml since this would not be a global definition. But I failed to find the correct place in roles/javajdk - is there any?
Other option: assuming i have many roles included in werbservers.yml - is there an other option to run only one of the roles ? 

Kai Stian Olstad

unread,
Nov 22, 2017, 10:26:05 AM11/22/17
to ansible...@googlegroups.com
On Tuesday, 21 November 2017 10.32.27 CET akazi...@gmail.com wrote:
> Here is a littel edit:
> I struggle to find the correct place where I would add the tag for the
> role. I do not want to tag the role in webservers.yml since this would not
> be a global definition. But I failed to find the correct place in
> roles/javajdk - is there any?

You would need to tag every task in the role.


> Other option: assuming i have many roles included in werbservers.yml - is
> there an other option to run only one of the roles ?

Options as on ansible-playbook command line, then the answer is no.
You could use extra vars on the command line and have when on roles the roles.


--
Kai Stian Olstad

Josh Smift

unread,
Nov 22, 2017, 10:43:37 AM11/22/17
to ansible...@googlegroups.com
As a new feature, you could imagine being able to put something like

tags:
- javajdk

into .../roles/javajdk/meta/defaults.yml, but I don't think there's
currently a way to tell a role "add this tag to all your tasks", inside
the role itself, other than adding the tag explicitly to all the tasks.

-Josh (j...@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

Brian Coca

unread,
Nov 22, 2017, 11:48:23 AM11/22/17
to Ansible Project
tasks/main.yml:

- tags: x, y z
block:
- rest of tasks
...





--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages