Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically set role name as tag #66

Closed
robinro opened this issue Jun 13, 2017 · 8 comments
Closed

Automatically set role name as tag #66

robinro opened this issue Jun 13, 2017 · 8 comments
Projects

Comments

@robinro
Copy link

robinro commented Jun 13, 2017

Proposal: Automatically set role name as tag

Author: Robin Roth <@robinro>

Date: 2016/06/13

Motivation

A common theme is to use the role name also as a tag, e.g.

roles:
  - { role: webserver, tags: [ 'webserver' ] }

With this patch one can instead write

roles:
  - webserver

and have the same result.

Problems

At the moment it's common to repeat the role name in tags. Following DRY this should not be the case.

Solution proposal

See PR ansible/ansible#25132

Testing (optional)

Should be tested. Can be added to the tags test coverage.

Documentation (optional)

Needs to be documented in playbooks_roles.

Possible Drawbacks

This change could lead to unwanted behavior in existing playbooks if a tag is used with the same name as a role AND the role is not tagged with that tag. This usage is rare in my experience and not enough to outweigh the benefits imo.
To mitigate the issue one could have a config setting to toggle this feature and default it to the old behavior.

Alternatives

Add a CLI option --role to ansible-playbook, which limits execution to a specific role in parallel to --tags.

@robinro
Copy link
Author

robinro commented Jun 13, 2017

This idea is originally from @agx

@bcoca in the PR called this

I find this a bit too 'magical' also it might collide with existing tags.

In the core meeting on 2016-06-13 several people agreed with the general idea and suggested to open this proposal.

@geerlingguy
Copy link

+1 to doing this—maybe to avoid the potential collision, we could make it opt-in? E.g. an ansible.cfg flag like role_name_as_tag: False that's disabled by default, and then at some point in the future it would be enabled by default?

@azaghal
Copy link

azaghal commented Jun 13, 2017

How about having role tags with slightly different naming, for example role:database_server. This way it would be clear what you really want to run, and should reduce chance of collisions.

Another thing I would like to point out is maybe some discussion should be made on whether meta deps should be included or not when specifying tag like this. I could easily see that in some cases you just want to run role tasks without meta deps (especially when developing the role), while in other you might want to call the full thing (together with deps). Not sure how this would be handled syntax-wise, though.

@robinro
Copy link
Author

robinro commented Jun 13, 2017

I updated the PR to include the config flag suggested by @geerlingguy. Having this off by default allows people to check for collisions manually and switch it on if they like it. We can then review later whether the default should be True.

@bcoca
Copy link
Member

bcoca commented Jun 13, 2017

Expanding on my previous point, this also affects the exiting tagged/untagged tags .. i really don't want to create an 'autotagged' one. There is also the interaction with include role, which is not static as roles:, it can get very complicated there.

One big issue is that roles also can easily have characters that are not 'valid/legal' for tags, tags need to be 'valid dictionary keys' while role names need to be 'valid filesystem names'. This is easy to solve technically but then you enter the realm of tags not being what the user expected and/or overlapping with other tags.

As for the --role CLI option ... it would be simpler to enable include_role to work with Adhoc mode, it doesn't really seem to make any sense to make it an option of the ansible-plabyook command. Includes don't currently work due to their dual nature (static/dynamic) but that is changing in 2.4.

To the suggestion above, PLEASE don't give yet another special meaning to : there are other characters to abuse.

As for the global flag ... it will also require a keyword directive as people will want to turn on/off by play/block/role. At this point I think that adding a tag entry is about as much work with a lot less magic, less code, less fuss.

Also mentioned above are dependencies .... things really start to get complicated now.

I understand that this is a nice convenience, I just think it adds a lot of complication for a tiny benefit for a particular workflow. As such -1

@geerlingguy
Copy link

geerlingguy commented Jun 13, 2017

I understand that this is a nice convenience, I just think it adds a lot of complication for a tiny benefit for a particular workflow. As such -1

In agreement there—in my case, I've never added a [rolename] tag for each task in a role, because I'd rather my users add a tag in the playbook if they really need to just run one role:

- hosts: all
  roles:
    - role: geerlingguy.apache
      tags: ['apache']

Having tags set on a playbook/integration level means that the tags are actually meaningful. And if you have roles that are complex enough that you have to have different tags for different portions of the role... IMHO that role should be broken up so each role focuses on one smaller thing.

@bcoca
Copy link
Member

bcoca commented Jun 13, 2017

@geerlingguy I don't disagree with 'smaller more focused roles' but I'm not partial to prevent people from doing otherwise, sometimes there is a good reason .. other times it is not optimal, but we should not be imposing workflow where possible.

@bcoca bcoca added this to Initial in Proposals Nov 30, 2021
@bcoca
Copy link
Member

bcoca commented Nov 30, 2021

closing as per above

@bcoca bcoca closed this as completed Nov 30, 2021
Proposals automation moved this from Initial to Done Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

4 participants