Fixing an Ansible Lint No-Handler Error in a Multi-Condition Task
![blog/cards/fixing-an-ansible-lint-no-handler-error-in-a-multi-condition-task.jpg](/assets/blog/cards/fixing-an-ansible-lint-no-handler-error-in-a-multi-condition-task-aaf7baefd3b5fe652740a8db4bb81614526a77858ab724293bbd5104595c499c.jpg)
You may have a more complicated when condition where it's not obvious on how convert it into a handler. Here's what I did.
Quick Jump: Going Over an Example
I ran across this use case the other day where I had a when ... is changed
condition that had an or
condition and it wasn’t really clear on how to convert that into a handler.
What I ended up doing was simplifying the condition by performing one of the conditions in the shell script that I was running in the task. After doing that, converting the single when condition into a handler was easy.
Here’s a video walk through of the exact use case and how I fixed it.
Going Over an Example
Timestamps
- 0:26 – What causes a no-handler linting error and how to fix it usually
- 1:11 – Breaking down the task that caused this error
- 2:02 – How you can normally fix the error with a more simple when condition
- 2:45 – My task was a bit more complicated with its when condition
- 3:23 – Ansible is nice but I don’t use it for everything
- 5:44 – Solving this specific problem by doing the existence check in the shell script
- 8:11 – Maciej was on my podcast to talk about how he’s using Ansible
Reference Links
How would you have solved this problem? Let me know below.