I suspect that this is trying to be too clever (and failing), but - especially in development of a PB, it's really useful to use tags to limit the roles which are run - so for example we have: (snippet of the playbook) ...
- { role: yum, tags: [ 'yum' ] }
- { role: proxy, tags: [ 'proxy' ] }
- { role: firewall, tags: [ 'firewall' ] }
Now occasionally, I run with a misspelled tag - eg
$ ansible-playbook servername, user=fred my_playbook --tags=firewal
And pre-tasks get run, as do post tasks, which makes it appear that something is happening, but of course, no task matches the incorrectly-entered tag. I do pick this up in logging ( every role does this:
- include_tasks: includes/log_role_completion.yml this_role={{ role_name }}
which resolves to this:
- name: "Setup completed_roles list"
set_fact:
completed_roles: "{{ this_role }}"
changed_when: false
when: completed_roles is not defined
- name: "Add role to list of completed roles"
set_fact:
completed_roles: "{{ completed_roles }} {{ this_role }}"
changed_when: false
when: completed_roles != this_role
Then, a post_tasks role writes the list of completed roles - or a message saying that none were run possibly because of a misspelt tag. This works nicely - and I know that ansible writes logs, but they are either verbose, or cryptic, and I like to have /var/log/ansible on the target with something like this:
Ansible version 2.6.2 run commenced at 2018-08-31: 20:23:40 GMT using account vmw-user
Ansible version 2.6.2 run completed at 2018-08-31: 20:23:40 GMT for roles chrony, proxy, and log_complete
That's really useful, BUT (and here's the question,finally) I'd rather have the playbook check if a tag is supplied which doesn't match any tag used in the playbook, and stop - thus warning me that I've misspelt something. this would also prevent a playbook from being incompletely run - the role with the misspelled tag would not run at all, which could cause a problem.
The variable vars.ansible_run_tags contains the user-supplied tags: is there some way of seeing which tags are set in a playbook? I don't want to run in check-mode first, and manually parse the output - I'd like it to be automatic.
ansible-playbook
that pulled out the tags lists passed in to--tags
or--skip-tags
and then verified they appeared in the list reported by--list-tags
, only if all are present would it make the real call. But I'm busy and I bet that will come back to bite me. I just feel there should be a--strict
option that does this kind of check.