Host-specific configurations in custom templates

May 20, 2017
172
18
58
Netherlands
cyberfusion.nl
Hello,

I have a PMG cluster with two hosts. I need to add a Postfix configuration option with different values on both hosts (in /etc/postfix/main.cf and /etc/postfix/master.cf). I cannot use any variables provided by PMG for this.

When I change the template on host A and host B and `pmgconfig sync`, obviously host B's config is overwritten by the master's.

Is there a directive I can use in templates that disables that block from being replicated to other cluster nodes?
 
currently this is not possible...
Which variable would that be - and what's the use case (there might be a workaround)?
 
currently this is not possible...
Which variable would that be - and what's the use case (there might be a workaround)?
Thanks for the response.

I am using a randmap to distribute mail across multiple IPs. If this is the same on all cluster nodes, I would have to put the same IP on multiple servers... It looks like this:


main.cf

Code:
sender_dependent_default_transport_maps=randmap:{185-233-175-147.out.prorelay.nl,185-233-175-149.out.prorelay.nl,185-233-175-151.out.prorelay.nl,185-233-175-164.out.prorelay.nl,185-233-175-165.out.prorelay.nl}


master.cf

Code:
185-233-175-147.out.prorelay.nl     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=185.233.175.147
  -o smtp_helo_name=smtp.prorelay.nl
  -o syslog_name=185-233-175-147.out.prorelay.nl
185-233-175-149.out.prorelay.nl     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=185.233.175.149
  -o smtp_helo_name=smtp.prorelay.nl
  -o syslog_name=185-233-175-149.out.prorelay.nl
185-233-175-151.out.prorelay.nl     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=185.233.175.151
  -o smtp_helo_name=smtp.prorelay.nl
  -o syslog_name=185-233-175-151.out.prorelay.nl
185-233-175-164.out.prorelay.nl     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=185.233.175.164
  -o smtp_helo_name=smtp.prorelay.nl
  -o syslog_name=185-233-175-164.out.prorelay.nl
185-233-175-165.out.prorelay.nl     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=185.233.175.165
  -o smtp_helo_name=smtp.prorelay.nl
  -o syslog_name=185-233-175-165.out.prorelay.nl
 
hm - you do have the host-name available as variable for the config-templates
maybe create 2 large 'IF' blocks (or one IF ELSE)
both containing only the ips configured on the node

hope this helps!
 
hm - you do have the host-name available as variable for the config-templates
maybe create 2 large 'IF' blocks (or one IF ELSE)
both containing only the ips configured on the node

hope this helps!
That is definitely useful. I didn't think of that yet.

Do you mean something like this?

Code:
[%- IF dns.hostname == 'mgw0-0' -%]
IP stuff for mgw0-1
[%- ELSE %]
[%- IF dns.hostname == 'mgw0-1' -%]
IP stuff for mgw0-1
[%- ELSE %]


I do not see any option to do elseif (like `[%- ELSEIF -%]`), is that correct?
 
Last edited:
Please see posts above. What I did is described there.

Hi William,

As far as I understand, I made a configuration below. If I have a mistake, can you correct it? Is it a correct configuration?

Code:
Now pmg1.domain.com main.cf

sender_dependent_default_transport_maps = randmap:{relay1,relay2}
smtp_connection_cache_on_demand=no

after editing:
[%- ELSIF dns.hostname == 'pmg1.domain.com' -%]
sender_dependent_default_transport_maps = randmap:{relay1,relay2}
[%- ELSE %]

[%- ELSIF dns.hostname == 'pmg2.domain.com' -%]
sender_dependent_default_transport_maps = randmap:{relay3,relay4}
[%- ELSE %]

Code:
Now pmg1.domain.com master.cf

relay1     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=1.1.1.1
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay1
relay2     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=2.2.2.2
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay2

after editing:

[%- ELSIF dns.hostname == 'pmg1.domain.com' -%]
relay1     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=1.1.1.1
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay1
relay2     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=2.2.2.2
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay2
[%- ELSE %]

[%- ELSIF dns.hostname == 'pmg2.domain.com' -%]
relay3     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=3.3.3.3
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay1
relay4     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=4.4.4.4
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay2
[%- ELSE %]
 
please don't double-post - I've answered your question in your original thread: https://forum.proxmox.com/threads/how-to-add-virtual-ip-with-cluster.65139/#post-295081

[[ IF + (optionally ELSEIF ) + ELSE (at the end) ]] as I understand it should be as follows:

Code:
[% IF dns.hostname == 'pmg1.domain.com' %]
relay1 unix - - n - - smtp
-o smtp_bind_address=1.1.1.1
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay1
relay2 unix - - n - - smtp
-o smtp_bind_address=2.2.2.2
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay2

[% ELSIF dns.hostname == 'pmg2.domain.com' %]
relay3 unix - - n - - smtp
-o smtp_bind_address=3.3.3.3
-o smtp_helo_name=pmg2.domain.com
-o syslog_name=relay3
relay4 unix - - n - - smtp
-o smtp_bind_address=4.4.4.4
-o smtp_helo_name=pmg2.domain.com
-o syslog_name=relay4

[% ELSE %]
relay1 unix - - n - - smtp
-o smtp_bind_address=1.1.1.1
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay1
relay2 unix - - n - - smtp
-o smtp_bind_address=2.2.2.2
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay2

[% END %]


[[you need to remove the ELSE before the endif]] If I remove ELSE, should it be as follows:
Code:
[% IF dns.hostname == 'pmg1.domain.com' %]
relay1 unix - - n - - smtp
-o smtp_bind_address=1.1.1.1
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay1
relay2 unix - - n - - smtp
-o smtp_bind_address=2.2.2.2
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay2

[% ELSIF dns.hostname == 'pmg2.domain.com' %]
relay3 unix - - n - - smtp
-o smtp_bind_address=3.3.3.3
-o smtp_helo_name=pmg2.domain.com
-o syslog_name=relay3
relay4 unix - - n - - smtp
-o smtp_bind_address=4.4.4.4
-o smtp_helo_name=pmg2.domain.com
-o syslog_name=relay4

[% END %]

Which one should I try? I do not have much experience on these issues. It is his first time. I'm asking too many questions. Thank you.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!