Vendor Galaxy Roles and Collections
Some checks failed
/ Ansible Lint (push) Failing after 5m45s
/ Ansible Lint (pull_request) Failing after 4m59s

This commit is contained in:
Stefan Bethke 2026-02-06 22:07:16 +01:00
commit 2aed20393f
8 changed files with 387444 additions and 2 deletions

View file

@ -0,0 +1,19 @@
debops.postwhite - Manage Postscreen SPF Whitelist using Ansible
Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
Copyright (C) 2017 DebOps <https://debops.org/>
SPDX-License-Identifier: GPL-3.0-only
This Ansible role is part of DebOps.
DebOps is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
DebOps is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DebOps. If not, see https://www.gnu.org/licenses/.

View file

@ -0,0 +1,242 @@
---
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# .. Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
# .. Copyright (C) 2017 DebOps <https://debops.org/>
# .. SPDX-License-Identifier: GPL-3.0-only
# .. _postwhite__ref_defaults:
# debops.postwhite default variables [[[
# ======================================
# .. contents:: Sections
# :local:
#
# .. include:: ../../../../includes/global.rst
# Application environment [[[
# ---------------------------
# .. envvar:: postwhite__base_packages [[[
#
# List of base APT packages required by Postwhite.
postwhite__base_packages: [ 'curl' ]
# ]]]
# .. envvar:: postwhite__packages [[[
#
# List of additional APT packages to install with Postwhite.
postwhite__packages: []
# ]]]
# .. envvar:: postwhite__user [[[
#
# The UNIX system account which will be used to manage the whitelist.
postwhite__user: 'postwhite'
# ]]]
# .. envvar:: postwhite__group [[[
#
# The UNIX system group which will be used to manage the whitelist.
postwhite__group: 'postwhite'
# ]]]
# .. envvar:: postwhite__shell [[[
#
# The default shell of the UNIX system account.
postwhite__shell: '/usr/sbin/nologin'
# ]]]
# .. envvar:: postwhite__gecos [[[
#
# The GECOS field of the UNIX system account.
postwhite__gecos: 'Postscreen SPF Whitelist'
# ]]]
# .. envvar:: postwhite__home [[[
#
# The home directory of the UNIX system account.
postwhite__home: '{{ (ansible_local.fhs.home | d("/var/local"))
+ "/" + postwhite__user }}'
# ]]]
# ]]]
# Software stack [[[
# ------------------
# .. envvar:: postwhite__src [[[
#
# Base directory where the Postwhite and spf-tools source code will be cloned.
postwhite__src: '{{ (ansible_local.fhs.src | d("/usr/local/src"))
+ "/" + postwhite__user }}'
# ]]]
# .. envvar:: postwhite__spftools_git_repo [[[
#
# The URL of the 'spf-tools' git repository.
postwhite__spftools_git_repo: 'https://github.com/jsarenik/spf-tools'
# ]]]
# .. envvar:: postwhite__spftools_git_version [[[
#
# The 'spf-tools' git branch/tag to check out.
postwhite__spftools_git_version: 'master'
# ]]]
# .. envvar:: postwhite__spftools_git_dest [[[
#
# Directory where 'spf-tools' repository will be checked out.
postwhite__spftools_git_dest: '{{ postwhite__src + "/"
+ postwhite__spftools_git_repo.split("://")[1] }}'
# ]]]
# .. envvar:: postwhite__git_repo [[[
#
# The URL of the 'postwhite' git repository.
postwhite__git_repo: 'https://github.com/stevejenkins/postwhite'
# ]]]
# .. envvar:: postwhite__git_version [[[
#
# The 'postwhite' git branch/tag to check out.
postwhite__git_version: 'master'
# ]]]
# .. envvar:: postwhite__git_dest [[[
#
# Directory where 'postwhite' repository will be checked out.
postwhite__git_dest: '{{ postwhite__src + "/"
+ postwhite__git_repo.split("://")[1] }}'
# ]]]
# .. envvar:: postwhite__software_stack [[[
#
# Map of the required git repositories to clone, passed to the role tasks.
postwhite__software_stack:
- git_repo: '{{ postwhite__spftools_git_repo }}'
git_dest: '{{ postwhite__spftools_git_dest }}'
git_version: '{{ postwhite__spftools_git_version }}'
- git_repo: '{{ postwhite__git_repo }}'
git_dest: '{{ postwhite__git_dest }}'
git_version: '{{ postwhite__git_version }}'
# ]]]
# ]]]
# Postwhite configuration options [[[
# -----------------------------------
# .. envvar:: postwhite__spf_whitelist_path [[[
#
# Absolute path to the SPF whitelist file.
postwhite__spf_whitelist_path: '{{ postwhite__home + "/postscreen_spf_whitelist.cidr" }}'
# ]]]
# .. envvar:: postwhite__spf_blacklist_path [[[
#
# Absolute path to the SPF blacklist file.
postwhite__spf_blacklist_path: '{{ postwhite__home + "/postscreen_spf_blacklist.cidr" }}'
# ]]]
# .. envvar:: postwhite__whitelist_hosts [[[
#
# List of additional hosts or domains to add to the whitelist in addition to
# the list predefined by Postwhite.
postwhite__whitelist_hosts: []
# ]]]
# .. envvar:: postwhite__include_yahoo [[[
#
# Enable or disable inclusion of the custom list of Yahoo! mail servers.
postwhite__include_yahoo: True
# ]]]
# .. envvar:: postwhite__blacklist [[[
#
# If enabled, :command:`postwhite` will generate an additional file with
# blacklisted SMTP servers.
postwhite__blacklist: '{{ True if postwhite__blacklist_hosts | d() else False }}'
# ]]]
# .. envvar:: postwhite__blacklist_hosts [[[
#
# List of DNS domain names which will be added to the blacklist.
postwhite__blacklist_hosts: []
# ]]]
# .. envvar:: postwhite__invalid_ipv4 [[[
#
# Specify what Postwhite should do with invalid IPv4 addresses (see Postwhite
# documentation for details). Possible values: ``remove``, ``keep``, ``fix``.
postwhite__invalid_ipv4: 'remove'
# ]]]
# .. envvar:: postwhite__simplify [[[
#
# if enabled, Postwhite will remove the single IP addresses included in
# a bigger CIDR ranges, however this might slow down whitelist generation.
postwhite__simplify: False
# ]]]
# .. envvar:: postwhite__reload_postfix [[[
#
# Enable or disable automatic reload of Postfix after the script is finished.
# In DebOps this should be disabled, Postfix is reloaded independently by the
# wrapper script.
postwhite__reload_postfix: False
# ]]]
# ]]]
# Other options [[[
# -----------------
# .. envvar:: postwhite__cron_whitelist_update_frequency [[[
#
# Specify the frequency (``hourly``, ``daily``, ``weekly``) of the whitelist
# update job.
postwhite__cron_whitelist_update_frequency: 'daily'
# ]]]
# .. envvar:: postwhite__cron_yahoo_update_frequency [[[
#
# Specify the frequency (``hourly``, ``daily``, ``weekly``) of the Yahoo!
# address list update job.
postwhite__cron_yahoo_update_frequency: 'weekly'
# ]]]
# .. envvar:: postwhite__initial_update_method [[[
#
# Select the method which will be used to update the whitelist in the
# background after the role configures Postwhite:
#
# - ``async``: use Ansible ``async`` task execution method
#
# - ``batch``: use :command:`batch` command managed by :command:`at` service
#
postwhite__initial_update_method: '{{ "batch"
if (ansible_local | d() and ansible_local.atd | d() and
(ansible_local.atd.enabled | d()) | bool)
else "async" }}'
# ]]]
# ]]]
# Configuration for other Ansible roles [[[
# -----------------------------------------
# .. envvar:: postwhite__postfix__dependent_maincf [[[
#
# The :file:`main.cf` configuration for the :ref:`debops.postfix` Ansible role.
postwhite__postfix__dependent_maincf:
- name: 'postscreen_access_list'
state: 'append'
value:
- name: 'cidr:{{ postwhite__spf_whitelist_path }}'
state: 'present'
weight: 100
- name: 'cidr:{{ postwhite__spf_blacklist_path }}'
weight: 110
state: '{{ "present" if postwhite__blacklist | bool else "ignore" }}'
# ]]]
# ]]]
# ]]]

View file

@ -0,0 +1,22 @@
---
# Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2017 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Update Postwhite in the background using async
ansible.builtin.command: /usr/local/lib/postwhite
async: '1800'
poll: '0'
register: postwhite__register_async
changed_when: postwhite__register_async.changed | bool
when: postwhite__initial_update_method == 'async'
- name: Update Postwhite in the background using batch
ansible.builtin.shell: |
set -o nounset -o pipefail -o errexit &&
echo '/usr/local/lib/postwhite' | batch > /dev/null 2>&1
args:
executable: 'bash'
register: postwhite__register_batch
changed_when: postwhite__register_batch.changed | bool
when: postwhite__initial_update_method == 'batch'

View file

@ -0,0 +1,32 @@
---
# Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2017-2022 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# Ensure that custom Ansible plugins and modules included in the main DebOps
# collection are available to roles in other collections.
collections: [ 'debops.debops' ]
dependencies: []
galaxy_info:
author: 'Maciej Delmanowski'
description: 'Manage Postwhite, Postscreen SPF Whitelist Generator'
company: 'DebOps'
license: 'GPL-3.0-only'
min_ansible_version: '2.3.0'
platforms:
- name: 'Ubuntu'
versions: [ 'all' ]
- name: 'Debian'
versions: [ 'all' ]
galaxy_tags:
- smtp
- postscreen
- spf
- antispam

View file

@ -0,0 +1,134 @@
---
# Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2017 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Import DebOps global handlers
ansible.builtin.import_role:
name: 'global_handlers'
- name: Install required packages
ansible.builtin.package:
name: '{{ q("flattened", (postwhite__base_packages
+ postwhite__packages)) }}'
state: 'present'
register: postwhite__register_packages
until: postwhite__register_packages is succeeded
- name: Create the UNIX system group
ansible.builtin.group:
name: '{{ postwhite__group }}'
state: 'present'
system: True
- name: Create the UNIX system account
ansible.builtin.user:
name: '{{ postwhite__user }}'
group: '{{ postwhite__group }}'
home: '{{ postwhite__home }}'
comment: '{{ postwhite__gecos }}'
shell: '{{ postwhite__shell }}'
state: 'present'
system: True
- name: Create the source directory
ansible.builtin.file:
path: '{{ postwhite__src }}'
state: 'directory'
owner: '{{ postwhite__user }}'
group: '{{ postwhite__group }}'
mode: '0755'
- name: Clone and install the software stack
ansible.builtin.git:
repo: '{{ item.git_repo }}'
dest: '{{ item.git_dest }}'
version: '{{ item.git_version }}'
update: True
with_items: '{{ postwhite__software_stack }}'
become: True
become_user: '{{ postwhite__user }}'
- name: Generate Postwhite configuration
ansible.builtin.template:
src: 'etc/postwhite.conf.j2'
dest: '/etc/postwhite.conf'
owner: 'root'
group: 'root'
mode: '0644'
- name: Install the Postwhite wrapper script
ansible.builtin.template:
src: 'usr/local/lib/postwhite.j2'
dest: '/usr/local/lib/postwhite'
owner: 'root'
group: 'root'
mode: '0755'
- name: Update Yahoo! static host list
ansible.builtin.command: bash {{ postwhite__git_dest }}/scrape_yahoo
become: True
become_user: '{{ postwhite__user }}'
notify:
- 'Update Postwhite in the background using async'
- 'Update Postwhite in the background using batch'
register: postwhite__register_scrape_yahoo
changed_when: postwhite__register_scrape_yahoo.changed | bool
when: (ansible_local is undefined or
(ansible_local | d() and ansible_local.postwhite is undefined or
(ansible_local.postwhite | d() and
not (ansible_local.postwhite.installed | d()) | bool)))
- name: Initialize whitelist/blacklist files
ansible.builtin.file:
path: '{{ item }}'
state: 'touch'
owner: '{{ postwhite__user }}'
group: '{{ postwhite__group }}'
mode: '0644'
with_items:
- '{{ postwhite__spf_whitelist_path }}'
- '{{ postwhite__spf_blacklist_path }}'
when: (ansible_local is undefined or
(ansible_local | d() and ansible_local.postwhite is undefined or
(ansible_local.postwhite | d() and
not (ansible_local.postwhite.installed | d()) | bool)))
- name: Update Postwhite access lists daily
ansible.builtin.cron:
job: '/usr/local/lib/postwhite'
cron_file: 'postwhite'
name: 'Update Postwhite access lists'
special_time: '{{ postwhite__cron_whitelist_update_frequency }}'
user: 'root'
state: 'present'
- name: Update Yahoo IP address list weekly
ansible.builtin.cron:
job: 'bash {{ postwhite__git_dest + "/scrape_yahoo" }} > /dev/null'
cron_file: 'postwhite'
name: 'Update Yahoo IP address list'
special_time: '{{ postwhite__cron_yahoo_update_frequency }}'
user: 'postwhite'
state: 'present'
- name: Make sure that Ansible local facts directory exists
ansible.builtin.file:
path: '/etc/ansible/facts.d'
state: 'directory'
owner: 'root'
group: 'root'
mode: '0755'
- name: Save Postwhite local facts
ansible.builtin.template:
src: 'etc/ansible/facts.d/postwhite.fact.j2'
dest: '/etc/ansible/facts.d/postwhite.fact'
owner: 'root'
group: 'root'
mode: '0755'
notify: [ 'Refresh host facts' ]
tags: [ 'meta::facts' ]
- name: Update Ansible facts if they were modified
ansible.builtin.meta: 'flush_handlers'

View file

@ -0,0 +1,16 @@
#!{{ ansible_python['executable'] }}
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2017 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# {{ ansible_managed }}
from __future__ import print_function
from json import dumps
from sys import exit
output = {'installed': True}
print(dumps(output, sort_keys=True, indent=4))

View file

@ -0,0 +1,40 @@
{# Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2017 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
# {{ ansible_managed }}
# CONFIGURATION OPTIONS FOR POSTWHITE
# https://github.com/stevejenkins/postwhite
# POSTWHITE WILL LOOK FOR THIS FILE IN /etc/postwhite.conf
# FILE PATHS
spftoolspath="{{ postwhite__spftools_git_dest }}"
postfixpath="{{ postwhite__home }}"
postfixbinarypath="/usr/sbin"
whitelist="{{ postwhite__spf_whitelist_path | basename }}"
blacklist="{{ postwhite__spf_blacklist_path | basename }}"
yahoo_static_hosts="{{ postwhite__home }}/yahoo_static_hosts.txt"
# CUSTOM HOSTS
# Enter custom hosts separated by a space, ex: "example.com example2.com example3.com"
custom_hosts="{{ ([ postwhite__whitelist_hosts ] if postwhite__whitelist_hosts is string else postwhite__whitelist_hosts) | join(' ') }}"
# Include list of Yahoo Outbound IPs from https://help.yahoo.com/kb/SLN23997.html?
include_yahoo="{{ 'yes' if postwhite__include_yahoo | bool else 'no' }}"
# Do you also want to build a blacklist?
enable_blacklist="{{ 'yes' if postwhite__blacklist | bool else 'no' }}"
blacklist_hosts="{{ ([ postwhite__blacklist_hosts ] if postwhite__blacklist_hosts is string else postwhite__blacklist_hosts) | join(' ') }}"
# Do what to invalid IPv4 addresses and CIDRs?
# Valid settings are 'remove' 'fix' or 'keep'
invalid_ip4="{{ postwhite__invalid_ipv4 }}"
# Simplify (remove) IP addresses from the whitelist that are already covered by CIDRs?
# WARNING: Enabling this option can dramatically increase the time Postwhite takes to
# run if you have many mailers selected. Try it once, then come back and turn it off. :)
simplify="{{ 'yes' if postwhite__simplify | bool else 'no' }}"
# Reload Postfix Automatically when done?
reload_postfix="{{ 'yes' if postwhite__reload_postfix | bool else 'no' }}"

View file

@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2017 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# {{ ansible_managed }}
# This is a wrapper script for Postwhite, a Postscreen SPF Whitelist Generator
set -o nounset -o pipefail -o errexit
readonly POSTWHITE_SCRIPT="{{ postwhite__git_dest }}/postwhite"
readonly POSTWHITE_USER="{{ postwhite__user }}"
readonly LOCK_FILE="/run/lock/postwhite.lock"
readonly LOCK_FD="200"
acquire_lock () {
local fd="${LOCK_FD}"
local lock_file="${LOCK_FILE}"
# Create lock file
eval "exec ${fd}>${lock_file}"
# Acquire lock
if flock -n "${fd}" ; then
trap "clean_up" EXIT
return 0
else
return 1
fi
}
clean_up () {
if [ -n "${LOCK_FILE}" ] && [ -r "${LOCK_FILE}" ] ; then
rm -f "${LOCK_FILE}"
fi
exit 0
}
error_exit () {
local message="${*}"
printf "Error: %s\\n" "${message}"
exit 1
}
update_access_list () {
if [ -x "${POSTWHITE_SCRIPT}" ] ; then
if tty -s > /dev/null 2>&1 ; then
su --shell /bin/sh -c "umask 0022 ; nice ${POSTWHITE_SCRIPT}" "${POSTWHITE_USER}"
if [ -x "/usr/sbin/postfix" ] ; then
/usr/sbin/postfix reload
fi
else
su --shell /bin/sh -c "umask 0022 ; nice ${POSTWHITE_SCRIPT} > /dev/null 2>&1" "${POSTWHITE_USER}"
if [ -x "/usr/sbin/postfix" ] ; then
/usr/sbin/postfix reload > /dev/null 2>&1
fi
fi
fi
}
main () {
acquire_lock || error_exit "Cannot acquire lock on \"${LOCK_FILE}\""
update_access_list
}
main