ansible-postfix icon indicating copy to clipboard operation
ansible-postfix copied to clipboard

postfix_sender_canonical_maps.db not updated

Open michel-thomas opened this issue 5 years ago • 8 comments

If run the playbook with this:

postfix_sender_canonical_maps:
  - sender:                 "root"
    rewrite:                "[email protected]"

and then run it again with a change in postfix_sender_canonical_maps:

postfix_sender_canonical_maps:
  - sender:                 "postmaster"
    rewrite:                "[email protected]"

the postmap command is not launch again and and /etc/postfix/postfix_sender_canonical_maps.db not updated with new or modified entries. In Postfix logs we can also see

warning: database /etc/postfix/sender_canonical_maps.db is older than source file /etc/postfix/sender_canonical_maps

michel-thomas avatar Apr 20 '21 18:04 michel-thomas

Do you have an idea why?

tersmitten avatar Apr 30 '21 08:04 tersmitten

nope. I did not resolve this, I run manually postmap command :(

michel-thomas avatar May 06 '21 12:05 michel-thomas

Are you able to run the playbook with the -vv verbosity level and inform if ansible reports a change on the configure sender canonical maps task? It should look like changed: [hostname] => {"changed": true, ...}. The handler won't run if a change isn't detected.

ljurgs avatar Aug 11 '21 22:08 ljurgs

Sorry for the delay.

I made some changes in my config to rewrite every sender:

admin_mail: "[email protected]"
postfix_sender_canonical_maps:
  - sender:                 "/.+/"
    rewrite:                "{{ admin_mail }}"
postfix_sender_canonical_maps_database_type:    "regexp"

So, I ran twice:

  1. No changes
TASK [oefenweb.postfix : configure sender canonical maps] *********************
task path: /home/user/Dev/gitlab.com/ansible/.roles_requirements/oefenweb.postfix/tasks/main.yml:127
Friday 17 September 2021  09:48:33 +0200 (0:00:00.029)       0:01:55.283 ****** 
ok: [edsdev] => (item={'sender': '/.+/', 'rewrite': '[email protected]'}) => {"ansible_loop_var": "item", "backup": "", "changed": false, "item": {"rewrite": "[email protected]", "sender": "/.+/"}, "msg": ""}
  1. With a change
TASK [oefenweb.postfix : configure sender canonical maps] *********************
task path: /home/user/Dev/gitlab.com/ansible/.roles_requirements/oefenweb.postfix/tasks/main.yml:127
Friday 17 September 2021  09:52:54 +0200 (0:00:00.026)       0:01:52.695 ****** 
changed: [edsdev] => (item={'sender': '/.+/', 'rewrite': '[email protected]'}) => {"ansible_loop_var": "item", "backup": "", "changed": true, "item": {"rewrite": "[email protected]", "sender": "/.+/"}, "msg": "line replaced"}
NOTIFIED HANDLER oefenweb.postfix : postmap sender_canonical_maps for edsdev

michel-thomas avatar Sep 17 '21 07:09 michel-thomas

I'm still having a problem with this happening for the sasl_password file not being handled when there it a change. I will take a look at it and see if I can create a fix. In my case, what happened was the playbook errored after the sasl_password file was created so the handler was never reached. I'm not entirely sure that the postmap commands should occur in a handler because a change is never raised in the edge case where the playbook has an error after the role, the error is fixed and the playbook is run again.

ljurgs avatar Oct 01 '21 03:10 ljurgs

Did you take a look @ljurgs?

In most cases handlers are called when there're errors, right?

tersmitten avatar Nov 19 '21 10:11 tersmitten

Did you take a look @ljurgs?

In most cases handlers are called when there're errors, right?

As far as I know, handlers do not get raised if an error causes the playbook execution to abort.

ljurgs avatar Nov 30 '21 01:11 ljurgs

Did you take a look @ljurgs?

In most cases handlers are called when there're errors, right?

From the latest Ansible docs:

Ansible runs handlers at the end of each play. If a task notifies a handler but another task fails later in the play, by default the handler does not run on that host, which may leave the host in an unexpected state. For example, a task could update a configuration file and notify a handler to restart some service. If a task later in the same play fails, the configuration file might be changed but the service will not be restarted. You can change this behavior with the --force-handlers command-line option, by including force_handlers: True in a play, or by adding force_handlers = True to ansible.cfg. When handlers are forced, Ansible will run all notified handlers on all hosts, even hosts with failed tasks. (Note that certain errors could still prevent the handler from running, such as a host becoming unreachable.)

Maybe it can be mentioned the use of --force-handlers in the README.md?

Adito5393 avatar Jun 21 '23 15:06 Adito5393