Daenou / ansible-multiroom-audio

9 stars 0 forks source link

Ensure start and enable example.service error is ignored in check mode #27

Closed Daenou closed 2 years ago

Daenou commented 2 years ago

When trying out your new snapclient structure with --check and --diff my playbook cancelled after TASK [snapclient : Enable and start snapclient@ services] as it failed because it couldn't check if it would work as the services don't exist yet:

TASK [snapclient : Enable and start snapclient@ services] ****************************************************************************************************************************************************
failed: [pi2] (item=pi2) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "pi2", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "pidev.example.net"}, "msg": "Could not find the requested service snapclient@pi2.service: host"}
failed: [pi3] (item=pi2) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "pi2", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "pidev.example.net"}, "msg": "Could not find the requested service snapclient@pi2.service: host"}
failed: [pi5] (item=pi2) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "pi2", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "pidev.example.net"}, "msg": "Could not find the requested service snapclient@pi2.service: host"}
failed: [pi4] (item=pi2) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "pi2", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "pidev.example.net"}, "msg": "Could not find the requested service snapclient@pi2.service: host"}

So we should make sure that every task that relies on a file or systemd unit being present either is handled in check mode so the check mode runs through

Daenou commented 2 years ago

See https://github.com/Daenou/ansible-multiroom-audio/blob/2443bae7ce230fbb4aebc72095e4de57569cfaf9/roles/bluetoothd/tasks/main.yml#L36

nis65 commented 2 years ago

I wasn't aware that you fixed this already and tried hard to reproduce :rofl: .

But I actually found a 2nd place to add this. Only now it is ignored twice:

TASK [snapclient : Enable and start snapclient@ services] ****************************************************************************************************************************************************************************
failed: [pidev] (item=pidev) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "pidev", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "pidev"}, "msg": "Could not find the requested service snapclient@pidev.service: host"}
failed: [pidev] (item=hifi) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "hifi", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "hifi"}, "msg": "Could not find the requested service snapclient@hifi.service: host"}
...ignoring

RUNNING HANDLER [snapclient : Restart snapclients] ***********************************************************************************************************************************************************************************
failed: [pidev] (item=pidev) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "pidev", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "pidev"}, "msg": "Could not find the requested service snapclient@pidev.service: host"}
failed: [pidev] (item=hifi) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "hifi", "snapclient_sink": "dmix:CARD=sndrpihifiberry,DEV=0", "snapclient_snapserver": "hifi"}, "msg": "Could not find the requested service snapclient@hifi.service: host"}
...ignoring
nis65 commented 2 years ago

Probably applies to these files too:

roles/acable/tasks/main.yml
roles/acable/handlers/main.yml
nis65 commented 2 years ago

Is fixed in the above files. But today I found out that also e.g. this one gives a fatal error in check mode:

TASK [snapclient : Disable upstream systemd unit] *********************************************************
fatal: [hifi]: FAILED! => {"changed": false, "msg": "Could not find the requested service snapclient.service: host"}

So my assumption above that only "looped" services are affected, was completely wrong. We need to make all ansible.builtin.systemd: occurrences failsafe. :frowning_face:

Daenou commented 2 years ago

Added the ignore_errors to every systemd task.

nis65 commented 2 years ago

Added some more and merged.