HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Is it possible to consolidate notification handlers when they are very similar?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
handlersareconsolidatepossiblewhensimilartheyverynotification

Problem

I have an Ansible role which uses handlers to restart services via the systemd module.

- name: restart ntp
  systemd:
    name: ntp
    enabled: yes
    state: restarted
  become: true

- name: restart web server
  systemd:
    name: nginx
    enabled: yes
    state: restarted
  become: true

- name: restart grafana
  systemd:
    name: grafana
    enabled: yes
    state: restarted
  become: true


Is there a way so I could parameterize the three separate handlers into something like this?:

- name: restart {{svcname}}
  systemd:
    name: '{{svcname}}'
    enabled: yes
    state: restarted
  become: true

Solution

In ansible 2.7 and earlier versions, variables in handlers name are not populated.

This bug was reported and a correction was lately pushed to devel version.

You need to run ansible from devel, and hope they publish this fix in the next release.

Context

StackExchange DevOps Q#5543, answer score: 4

Revisions (0)

No revisions yet.