Is it possible to defer action resolution to run time?

I have a role that can be run against both WIndows and Linux hosts. It has a handler for restarting a service on windows using win_service. This is breaking ansible-pull for us:

ansible-pull[7939]: ERROR! couldn't resolve module/action 'win_service'. This often indicates a misspelling, missing collection, or incorrect module path.
ansible-pull[7939]: The error appears to be in 'roles/ups/handlers/main.yml': line 11, column 3, but may
Sep 12 09:16:51 ansible-pull[7939]: be elsewhere in the file depending on the exact syntax problem.
Sep 12 09:16:51 ansible-pull[7939]: The offending line appears to be:
Sep 12 09:16:51 ansible-pull[7939]:   become: yes
Sep 12 09:16:51 ansible-pull[7939]: - name:  "windows restart nut service"
Sep 12 09:16:51 ansible-pull[7939]:   ^ here

because we do not install the ansible windows collection on the Linux hosts, and I would prefer not to. Is there any way I can avoid the need to resolve the win_service action on the Linux hosts?

Yes. I don’t feel like reformatting it for the forum since I just answered this in IRC, but the two approaches that immediately come to mind are to use the old action: syntax, or make the handler an include_tasks: task.

0_test.yml · GitHub and
handler_include.md · GitHub

1 Like

I went with action: and that worked nicely. Thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.