geerlingguy/ansible-role-postgresql

Postgres doesn't restart automatically

marasiali opened this issue · 3 comments

Hi, I set postgresql_hba_entries incorrectly, so I got an error in task TASK [geerlingguy.postgresql : Ensure PostgreSQL users are present.] that said unable to connect to database: FATAL: no pg_hba.conf entry for host.
I corrected it by changing postgresql_hba_entries. but the error remains. It seems pg_hba.conf not updated.
The reason is that postgres service doesn't restart automatically. It fixed by manually restarting postgres service.

If you see configure task, restart postgresql handler called after configuring pg_hba.conf.

- name: Configure host based authentication (if entries are configured).
  template:
    src: "pg_hba.conf.j2"
    dest: "{{ postgresql_config_path }}/pg_hba.conf"
    owner: "{{ postgresql_user }}"
    group: "{{ postgresql_group }}"
    mode: 0600
  notify: restart postgresql
  when: postgresql_hba_entries | length > 0

But according to Ansible Docs:

By default, handlers run after all the tasks in a particular play have been completed.

and when TASK [geerlingguy.postgresql : Ensure PostgreSQL users are present.] failed, playbook running terminated, and restart postgresql never called.

@marasiali , maybe the docs is little bit misleading,
By default, handlers run after all the tasks in a particular play have been completed.
what is meant, is that no handler will run unless all the play tasks have been completed that's clear, but what is missing, is that a given handler won't be "scheduled" unless it's respective Task has a changed state (marked as changed).

To put it simple in your case the "template" module applied no change on the underlying resource "pg_hba.conf.j2" therefor it's handler "restart postgresql" won't be scheduled for execution rigth after all the play tasks finish.

stale commented

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale commented

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.