17

I'm learning ansible and wrote simple playbook, but I don't understand or what I'm doing wrong that handler not working! Please, help me.

My playbook:

- hosts: HA
  gather_facts: False
  tasks:
    - name: Installs pacemaker
      yum: pkg=pacemaker,pcs,resource-agents state=latest
      notify:
         - pcsd start

  handlers:
    - name: pcsd start
      systemd: name=pcsd state=started

He skipped notify:

PLAY [HA] **********************************************************************

TASK [Installs pacemaker] ******************************************************
ok: [test-ha2]
ok: [test-ha1]

PLAY RECAP *********************************************************************
test-ha1                   : ok=1    changed=0    unreachable=0    failed=0
test-ha2                   : ok=1    changed=0    unreachable=0    failed=0

1 Answer 1

28

Handlers will only be fired for tasks which report a changed state. In the output of your play you can see the status is ok, which in this case means no new packages have been installed or updated (since state=latest)

So it would work, if any of the packages would not have been installed already.

Though, instead of state started I would use state restarted, since you're always upgrading to the latest packages in your task (state=latest) If a package gets updated, you also should restart the service.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .