Hi,

only the name seems to change. You could try to list the names of your
services and then use a loop. See
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html
for examples.

Best regards
Pierre


On Thu, Aug 24, 2023 at 5:47 PM Dick Visser <[email protected]> wrote:

> Hii,
>
> I have a lot of handlers to restart services, like this:
>
>    - name: smbd_restart
>       ansible.builtin.service:
>         name: smbd
>         state: restarted
>
>     - name: chronyd_restart
>       ansible.builtin.service:
>         name: chronyd
>         state: restarted
>
>     - name: udhcpd_restart
>       ansible.builtin.service:
>         name: udhcpd
>         state: restarted
>
>     - name: dhcpcd_restart
>       ansible.builtin.service:
>         name: dhcpcd
>         state: restarted
>
>     - name: lighttpd_restart
>       ansible.builtin.service:
>         name: lighttpd
>         state: restarted
>
>     - name: sshd_restart
>       ansible.builtin.service:
>         name: sshd
>         state: restarted
>
>     - name: networking_restart
>       ansible.builtin.service:
>         name: networking
>         state: restarted
>
>     - name: hostapd_restart
>       ansible.builtin.service:
>         name: hostapd
>         state: restarted
>
> etc etc
>
> Another pile of them are there for the 'reload' state.
>
> According to
> https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_handlers.html#using-variables-with-handlers
> variables in handler names will likely not work, and variable in listen
> topic for sure don't work.
>
> Is there perhaps another way to avoid having a ton of very similar)
> handlers?
>
> thx
>
> Dick
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLZrDQMwq6HnJssyZhAWXMP526_PtvfS8aE_m2Xpx_WUsg%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAF8BbLZrDQMwq6HnJssyZhAWXMP526_PtvfS8aE_m2Xpx_WUsg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFkBxkqvbGAh0vkmMgP9jyudbzGSPW1DCpNh9FbpXMcK%2Bi%3DdpQ%40mail.gmail.com.

Reply via email to