Hey;
I'm having difficulty coming up with the right syntax to add/include roles, with tags, from a loop such that I can limit execution to specific tags.
In the tasks section, this syntax works:
############################################################
# This syntax works but isn't very flexible. It does, however,
# allow us to select specific tasks to run.
- name: include root role
include_role:
name: root
tags:
- rootpwd
- rootbin
- rootkeys
- drex
- name: include commone role
include_role:
name: common
and I can limit execution by running 'ansible-playbook ./pb.yml -l grp -l rootpwd' for instance. That's not very flexible; however, as I'd like to avoid having to edit the playbook every time a role gets a new tag.
I have a structure in my group_vars/all file thusly:
commonroles:
- { n: common, t: [ 'nil' ] }
- { n: root, t: [ 'rootpwd', 'rootbin', 'rootkeys', 'drex' ] }
Debug tasks show I have the syntax the way I expect; however, I can't seem to get the include_role module to use the structure
For example, this syntax, in the tasks section, results in no tags::
- name: include common roles
include_role:
name: "{{rolename.n}}"
apply:
tags: "{{rolename.t}}"
loop: "{{commonroles}}"
loop_control:
loop_var: rolename
$ ansible-playbook ./configmgmt.yml -l amwtest --list-tags
playbook: ./configmgmt.yml
play #1 (all): Main configuration management playbook TAGS: []
TASK TAGS: []
Without the --ilst-tags, this results in an error:
FAILED! => {"msg": "the field 'tags' should be a list of ((<class 'str'>,), <class 'int'>), but the item '['nil']' is a <class 'list'>
So, it seems my issue is how I'm trying to present the tags...
Any ideas on how I can create a data structure of roles and tags that's usable by include_role via a loop?
Thanks for any hints/tips/suggestions.
Doug O'Leary