First ansible run:
[51/5036]mh@drop:~/git/zgansibletest (master * u+1) (crm) $ ansible-playbook --ask-become-pass --inventory=hosts.yml site.yml
<snip />
TASK [common : zda-sid-mc.list] *********************************************************************************************************************
changed: [sid01]
changed: [sid02]
RUNNING HANDLER [common : apt update] ***************************************************************************************************************
changed: [sid01]
Here is the problem, the task zda-sid-mc.list is changed on both host but only one of them run the handler.
Why this happen i don't know but at fist glance it looks like a bug.
What is your Ansible version?
You could also try more detailed logging to see if that gives more info:
ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -vvv --ask-become-pass --inventory=hosts.yml site.yml
PLAY [clean up after apt configuration] *************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************
ok: [sid01]
Since the handler didn't run you only have one host in the second play.
The first host is fine, but the -stretch- file is not removed on the second host.
Second ansible run:
[52/5037]mh@drop:~/git/zgansibletest (master * u+1) (crm) $ ansible-playbook --ask-become-pass --inventory=hosts.yml site.yml
<snip />
TASK [common : zda-sid-mc.list] *********************************************************************************************************************
ok: [sid01]
ok: [sid02]
[WARNING]: Could not match supplied host pattern, ignoring: apt_action_hosts
PLAY [clean up after apt configuration] *************************************************************************************************************
skipping: no hosts matched
PLAY RECAP ******************************************************************************************************************************************
sid01 : ok=7 changed=0 unreachable=0 failed=0
sid02 : ok=7 changed=0 unreachable=0 failed=0
This is an obvious no-op, with ansible not doing anything on the second host,
but I would have expected it to remove the -stretch- file anyway
You have linked the removal of the files on the creating of zda-sid-mc.list, since this was created in you first run it's not created now, as you can see the ok status on zda-sid-mc.list task.
And because of that the handler will not be called so you second play doesn't run since there are no hosts in the group.
However, the way to get there is unsatisfactory. Can somebody explain
what is happening and tell me how to do things right? If inserting debug
code helps, I'll happily do this, but I do not yet know too well how to
do this, so please suggest pasteable things. Thanks in advance!
A mention above, it might be a bug in the notify/handler.
You could just run everything on all hosts all the time, and not create a runtime group that you later run a play against.
Because your solution now is not idempotent as you see on your second run when something fails in the play before.