I have encountered some unexpected ansible-playbook behavior with respect to play tags and role tags. I’m trying to understand if this is an Ansible bug or this is a limitation of using tags, so I followed the recommendation to ask in the forums first.
I am using tags in order to quickly run a single role without (1) running the other roles in the play and (2) running other plays in the same playbook. But I am finding that handlers are not executed when they should be executed.
Consider this simplified playbook (our playbooks have more plays and use more roles):
[Edit: @flowerysong saw the relevant bit. Nice work. I didn’t see your post when I started composing mine.]
I’m unable to reproduce your results, having tried to reproduce your given input playbook, role, and handler files. (Thanks, btw, for including all the files! That really helps us help you.)
Here’s my exact file contents, my playbook invocation, and results, copy-n-pasted from my terminal.
utoddl@tango:~/ansible/alphabetical$ while read f ; do printf "### %s ###\n" "$f" ; cat "$f" ; echo ; done < <(find . -type f)
### ./roles/role1/tasks/main.yml ###
---
# ./roles/role1/tasks/main.yml
- name: Role 1 Task
ansible.builtin.debug:
# msg: "role1/tasks/main.yml notifying 'Role 1 Handler'"
changed_when: true
notify:
- Role 1 Handler
### ./roles/role1/handlers/main.yml ###
---
# ./roles/role1/handlers/main.yml
- name: Role 1 Handler
ansible.builtin.debug:
msg: "Role 1 Handler ran."
### ./site.yml ###
---
# ./site.yml
- name: Plays with roles and tags
hosts: all
tags: [play1]
roles:
- role: role1
tags: [role1]
utoddl@tango:~/ansible/alphabetical$ ansible-playbook site.yml -i localhost, --tags role1
PLAY [Plays with roles and tags] *********************************************************************
TASK [role1 : Role 1 Task] ***************************************************************************
changed: [localhost] => {
"msg": "Hello world!"
}
RUNNING HANDLER [role1 : Role 1 Handler] *************************************************************
ok: [localhost] => {
"msg": "Role 1 Handler ran."
}
PLAY RECAP *******************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Thanks @flowerysong for linking to a bug report that is the exact issue I am seeing! From the issue, I can see that a fix is being implemented so I will look forward to that. Not sure if I should mark this discussion thread as resolved, or wait until the fix is out.
I also appreciate @utoddl trying to reproduce the issue. Could it be that your ansible core is at 2.18.x or earlier ?