3

I'm having trouble getting a task within an ansible role to trigger handlers. Here are the files I'm using:

roles/services/tasks/postgresql.yml shows

- name: install postgresql packages
  apt: name={{ item }} state=present
  sudo: yes
  with_items:
  - postgresql
  - libpq-dev
  - python-psycopg2
  notify:
  - set postgres password
  - configure md5 security
  - restart postgres server

roles/services/handlers/main.yml shows

- name: set postgres password 
  sudo: yes
  sudo_user: postgres
  postgresql_user: name=postgres password=newpass

- name: configure md5 security
  sudo: yes
  copy: src=pg_hba.conf dest=/etc/postgresql/9.3/main/pg_hba.conf group=postgres owner=postgres backup=yes

- name: restart postgres server
  sudo: yes
  service: name=postgresql enabled=yes state=restarted

When I run the playbook, the task succeeds and acknowledges that it changed state, but it does not trigger the handlers. This is the last task in that role, and when it's done, ansible moves on to the first task in the next role in my playbook:

TASK: [services | install postgresql packages] ******************************** 
changed: [IP.REMOVED.##] => (item=postgresql,libpq-dev,python-psycopg2)

TASK: [passenger | install passenger gem] ************************************* 

I've tried changing the indentation in various ways, without success. I hope someone with fresh eyes will see what I'm missing.

1 Answer 1

3

You may not be waiting long enough. Ansible will wait for the handlers as long as possible. If you want to to do all of the handlers that are already queued try

 - meta: flush_handlers

which I find very handy. For instance, after I install a debian package I want it to kill the daemons right then so I add the meta command right after the package install and ansible doesn't make me wait.

1
  • 1
    Thanks! Adding the meta task below the 'install postgresql packages' task triggered the handlers. Jun 21, 2015 at 16:10

You must log in to answer this question.

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