How can I require caller is using tag directives, where tags are actively defined (not inherited)?

Hi all,

I posted the following in IRC to no avail. Please let me know if this is possible and/or desired.

[02:39] hello… odd question, i suppose, but: suppose i want to disable the default behavior of running all tags in a given yml playbook, instead requiring the playbook call to include the tags requesting execution in a deterministic order… can this be done? perhaps, via an ansible.cfg switch?
[02:40] reason being, i want to have a book of plays.yml which include tag actions such as install and uninstall, yet i don’t want them both to run on accident…

The desired effect is to always crash the ansible-playbook command (or perhaps elsewhere) when tag(s) are not specified but are required per Ansible configuration, without breaking out into a new role. I suppose I can do something with conditionals in each of the playbooks, but this seems like it would be a ansible.cfg type of thing.

How about an option in ansible.cfg called:

require_caller_tags: True

hmm… in pseudo code:

if require_caller_tags=True in ansible.cfg (or equiv)

if caller is “ansible-playbook” or “role” directive:

if target playbook contains “- tags” line definitions

(which are functionally different than inherited tags)

if caller did not specify “tags” directive(s)

error

endif

endif

endif

endif

It’s probably better to just split into separate roles for drastically different tags. Please let me know your thoughts. This could well be majorly off the wall, given it’s 3:18 AM. :slight_smile:

Thanks,
Joshua

I’m ok with making the tags used accessible as a variable like ansible_tags_used, something you might want to attempt a PR for?

You could use “when” and the “fail” module but I do not think we want to bloat the language just for this.

– Michael