Parameterized handlers

Hi everyone,

I’m looking into ansible for managing our farm of mail servers, and it looks very, very promising (as having used Puppet for another project, it is great to see the need for node setup greatly reduced :slight_smile: )

So I’m looking into managing our postfix mailservers with ansible, and we have a lot of postmap type files, which have to be re-hashed on the remote side if a file changes.

I think handlers is the way to go here, but I’m not quite sure how to handle those in a play yet.

As an example, I am creating my relay_domains file from a template with the following task:

  • name: Generate relay_domains
    template: src=relay_domains.j2 dest={{ postfix }}/relay_domains

To get something executed now when the file changes, a notify would have to be used. But I really wouldn’t like adding a static handler for each postmap file I’ll be adding to the config, that is error prone and not really in the spirit of what I try to do here.

Ideally, the task would look something like this:

  • name: Generate relay_domains
    template: src=relay_domains.j2 dest={{ postfix }}/relay_domains
    notify:
  • postmap {{ postfix }}/relay_domains

With a handler defined something like this:

  • name: postmap $i
    action: postmap hash:$i

Is something like this possible? Or do I need to write a new map module based on the template module? (As most of the postmap files will probably be created from templates)

Or any other solution I could use?

Any help would be greatly appreciated, and thanks in advance!

Best regards,
Jens

I did this by creating a makefile in my postfix configuration (on every
target) so I have a single notify to postfix-makefile, which then just
rebuilds for the changed source files my calling postmap or newaliases on
them.

Brian,

you implemented `validate' on template and copy (because of, well, cake :slight_smile:

How about a `compile' or similarly named switch which does
post-processing when the file has been a) successfully validated and b)
copied to its destination?

Just a thought.

        -JP

It would not be hard, I’ll add it to my list (cookies or cake will accelerate implementation).

Actually, I take that back, this will overlap with handlers too much, I am working on a patch to add parameters to handlers when notified which would also solve this issue.

Yes, actually that would be really great, and really what I need.

Do you have a status how far that is along? Can I help? Testing or developing, both would be possible :slight_smile:

Regards,
Jens

Hi Brian & everyone else,

As I like to continue working on this mailserver playbook, going the Makefile route in the postfix config dir seems to be the way to go (though it is slightly hackish).

As I stated before, I really don’t want to maintain all the possible postmaps in two places (the playbook and a Makefile), so I thought maybe it would be a good idea to render that Makefile from a template as well, showing all the postmaps I have.

So either I need to get a listing (in a template) of all the tasks which define a postmap (possibly with a tag), or I define a structured variable each time I define a postmap, which would also be fine, as then everything is in one place. Then I could iterate over keys/entries in that variable, and generate my Makefile from a template.

Is this possible? I tried various approaches today for this, but I am still struggling to get something working…

Thanks for all the input until now!

Best regards,
Jens

I took a brute force approach on the makefile, it will run postmap on any file in the etc/postfix dir that has changed excluding .conf ones.

Brian Coca