Skip to content

Commit

Permalink
Add postfix relayhost class
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd-ntrf committed Sep 28, 2021
1 parent be94397 commit d53d413
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions Puppetfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod 'puppet-fail2ban', '3.3.0'
mod 'puppet-healthcheck', '1.0.1'
mod 'puppet-logrotate', '5.0.0'
mod 'puppet-nodejs', '8.1.0'
mod 'puppet-postfix', '2.0.0'
mod 'puppet-prometheus', '10.2.0'
mod 'puppet-selinux', '3.2.0'
mod 'puppet-squid', '3.0.0'
Expand Down
5 changes: 5 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ profile::reverse_proxy::mokey_subdomain: mokey
prometheus::storage_retention: '48h'
prometheus::storage_retention_size: '5GB'

profile::base::domain_name: "%{alias('terraform.data.domain_name')}"
profile::base::sudoer_username: "%{alias('terraform.data.sudoer_username')}"
profile::base::public_keys: "%{alias('terraform.data.public_keys')}"

Expand All @@ -108,6 +109,10 @@ profile::freeipa::client::server_ip: "%{alias('terraform.tag_ip.mgmt.0')}"
profile::consul::client::server_ip: "%{alias('terraform.tag_ip.puppet.0')}"
profile::nfs::client::server_ip: "%{alias('terraform.tag_ip.nfs.0')}"

profile::mail::relayhost::origin: "%{alias('terraform.data.domain_name')}"
profile::mail::sender::origin: "%{alias('terraform.data.domain_name')}"
profile::mail::sender::relayhost_ip: "%{alias('terraform.tag_ip.public.0')}"

profile::nfs::server::devices: "%{alias('terraform.volumes.nfs')}"

profile::reverse_proxy::domain_name: "%{alias('terraform.data.domain_name')}"
7 changes: 7 additions & 0 deletions manifests/site.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@
if 'mfa' in $instance_tags {
include profile::mfa
}

if 'public' in $instance_tags {
include profile::mail::relayhost
} else {
include profile::mail::sender
}

}
5 changes: 3 additions & 2 deletions site/profile/manifests/base.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class profile::base (
String $domain_name,
Array[String] $public_keys,
String $sudoer_username = 'centos',
Optional[String] $admin_email = undef,
Expand Down Expand Up @@ -27,12 +28,12 @@
}

if $admin_email {
include profile::mail::server
file { '/opt/puppetlabs/bin/postrun':
ensure => present,
mode => '0700',
content => epp('profile/base/postrun', {
'email' => $admin_email,
'email' => $admin_email,
'domain' => $domain_name,
}),
}
}
Expand Down
45 changes: 39 additions & 6 deletions site/profile/manifests/mail.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
class profile::mail::server {
ensure_packages(['postfix'], { ensure => 'present'})
class profile::mail::sender(
String $relayhost_ip,
String $origin,
) {
class { 'postfix':
inet_protocols => 'ipv4',
relayhost => $relayhost_ip,
myorigin => $origin,
satellite => true,
manage_mailx => false,
}

postfix::config { 'authorized_submit_users':
ensure => present,
value => 'root, slurm',
}
}

class profile::mail::relayhost(
String $origin,
) {

$cidr = profile::getcidr()
$interface = split($::interfaces, ',')[0]
$ipaddress = $::networking['interfaces'][$interface]['ip']

class { 'postfix':
inet_interfaces => "127.0.0.1, ${ipaddress}",
inet_protocols => 'ipv4',
mynetworks => "127.0.0.0/8, ${cidr}",
myorigin => $origin,
mta => true,
relayhost => 'direct',
smtp_listen => 'all',
manage_mailx => false,
}

service { 'postfix':
ensure => running,
enable => true,
require => Package['postfix'],
postfix::config { 'authorized_submit_users':
ensure => present,
value => 'root, slurm',
}
}
1 change: 0 additions & 1 deletion site/profile/manifests/slurm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@
# Slurm controller class. This where slurmctld is ran.
class profile::slurm::controller {
contain profile::slurm::base
include profile::mail::server

file { '/usr/sbin/slurm_mail':
ensure => 'present',
Expand Down
2 changes: 1 addition & 1 deletion site/profile/templates/base/postrun.epp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ $actions -lt 2 ]] && [[ ! -z "$email" ]]; then
lines=($(journalctl -u puppet | grep -n -E 'Starting Puppet client|Applied catalog in' | cut -f 1 -d : | tail -n 2))
cat << EOF | /usr/sbin/sendmail $email
To: $email
From: puppet@$(hostname -f)
From: $(hostname -s)-puppet-noreply@<%= $domain %>
Subject: $(hostname -f) is online
$(journalctl -u puppet | sed -n "${lines[0]},${lines[1]}p")
EOF
Expand Down

0 comments on commit d53d413

Please sign in to comment.