From 0af07191b150868cba87cd6d2ab7fe949b8b87e5 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 22 Feb 2021 12:31:29 +0100 Subject: [PATCH 1/3] Make use of github actions --- .github/workflows/ci.yml | 80 +++++++++++++++++++++++ .github/workflows/release.yml | 20 ++++++ .travis.yml | 105 ------------------------------- .yamllint | 15 +++++ README.md | 5 +- Vagrantfile | 26 ++------ defaults/main.yml | 3 +- handlers/main.yml | 2 +- meta/main.yml | 4 +- molecule/default/converge.yml | 13 ++++ molecule/default/molecule.yml | 19 ++++++ molecule/default/prepare.yml | 5 ++ molecule/default/verify.yml | 5 ++ tasks/main.yml | 4 +- templates/etc/postfix/main.cf.j2 | 4 +- vars/main.yml | 2 +- 16 files changed, 175 insertions(+), 137 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml create mode 100644 .yamllint create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/prepare.yml create mode 100644 molecule/default/verify.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bf43d29 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +--- +name: CI +'on': + pull_request: + push: + branches: + - master + schedule: + - cron: '30 1 * * 3' + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + + - name: Set up Python 3 + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies + run: pip install yamllint ansible-lint[core] + + - name: Lint code + run: | + yamllint . + ansible-lint + + molecule: + name: Molecule + runs-on: ubuntu-latest + defaults: + run: + working-directory: "${{ github.repository }}" + needs: + - lint + strategy: + fail-fast: false + matrix: + include: + - distro: debian8 + - distro: debian9 + - distro: debian10 + - distro: ubuntu1604 + ansible-version: '>=2.8, <2.9' + - distro: ubuntu1604 + ansible-version: '>=2.9, <2.10' + - distro: ubuntu1604 + ansible-version: '>=2.10, <2.11' + - distro: ubuntu1604 + - distro: ubuntu1804 + - distro: ubuntu2004 + + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + with: + path: "${{ github.repository }}" + + - name: Set up Python 3 + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies + run: pip install 'ansible${{ matrix.ansible-version }}' molecule[docker] docker + + - name: Run Molecule tests + run: | + molecule test + env: + ANSIBLE_FORCE_COLOR: '1' + ANSIBLE_VERBOSITY: '2' + MOLECULE_DEBUG: '1' + MOLECULE_DISTRO: "${{ matrix.distro }}" + PY_COLORS: '1' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2354e68 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +--- +name: Release +'on': + push: + tags: + - '*' + +jobs: + + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + + - name: Publish to Galaxy + uses: robertdebock/galaxy-action@1.1.0 + with: + galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9970dfd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,105 +0,0 @@ ---- -sudo: required -dist: xenial - -language: python -python: - - "2.7" - - "3.5" - -env: - - ANSIBLE_VERSION=latest - - ANSIBLE_VERSION=2.10.1 - - ANSIBLE_VERSION=2.10.0 - - ANSIBLE_VERSION=2.9.14 - - ANSIBLE_VERSION=2.9.13 - - ANSIBLE_VERSION=2.9.12 - - ANSIBLE_VERSION=2.9.11 - - ANSIBLE_VERSION=2.9.10 - - ANSIBLE_VERSION=2.9.9 - - ANSIBLE_VERSION=2.9.8 - - ANSIBLE_VERSION=2.9.7 - - ANSIBLE_VERSION=2.9.6 - - ANSIBLE_VERSION=2.9.5 - - ANSIBLE_VERSION=2.9.4 - - ANSIBLE_VERSION=2.9.3 - - ANSIBLE_VERSION=2.9.2 - - ANSIBLE_VERSION=2.9.1 - - ANSIBLE_VERSION=2.9.0 - - ANSIBLE_VERSION=2.8.16 - - ANSIBLE_VERSION=2.8.15 - - ANSIBLE_VERSION=2.8.14 - - ANSIBLE_VERSION=2.8.13 - - ANSIBLE_VERSION=2.8.12 - - ANSIBLE_VERSION=2.8.11 - - ANSIBLE_VERSION=2.8.10 - - ANSIBLE_VERSION=2.8.9 - - ANSIBLE_VERSION=2.8.8 - - ANSIBLE_VERSION=2.8.7 - - ANSIBLE_VERSION=2.8.6 - - ANSIBLE_VERSION=2.8.5 - - ANSIBLE_VERSION=2.8.4 - - ANSIBLE_VERSION=2.8.3 - - ANSIBLE_VERSION=2.8.2 - - ANSIBLE_VERSION=2.8.1 - - ANSIBLE_VERSION=2.8.0 - -jobs: - include: - - python: "3.8" - env: ANSIBLE_VERSION=latest ANSIBLE_LINT_VERSION=latest - exclude: - - python: "2.7" - env: ANSIBLE_VERSION=latest - - python: "2.7" - env: ANSIBLE_VERSION=2.10.2 - - python: "2.7" - env: ANSIBLE_VERSION=2.10.1 - -branches: - only: - - master - -before_install: - - sudo apt-get update -qq - - # Remove postfix - - sudo apt-get remove --purge --yes postfix - -install: - # Install Ansible. - - if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible==$ANSIBLE_VERSION; fi - - > - if [ -n "$ANSIBLE_LINT_VERSION" ]; then - if [ "$ANSIBLE_LINT_VERSION" = "latest" ]; then - pip install ansible-lint; - else - pip install ansible-lint==$ANSIBLE_LINT_VERSION; - fi - fi - -script: - # Check the role/playbook's syntax. - - ansible-playbook -i tests/inventory tests/test.yml --syntax-check - - # Run the role/playbook with ansible-playbook. - - ansible-playbook -i tests/inventory tests/test.yml -vvvv - - # Run the role/playbook again, checking to make sure it's idempotent. - - > - ansible-playbook -i tests/inventory tests/test.yml - | grep -q 'changed=0.*failed=0' - && (echo 'Idempotence test: pass' && exit 0) - || (echo 'Idempotence test: fail' && exit 1) - - - > - if [ -n "$ANSIBLE_LINT_VERSION" ]; then - ansible-lint tests/test.yml; - fi - -notifications: - email: false - webhooks: https://galaxy.ansible.com/api/v1/notifications/ - slack: - rooms: - secure: "U+eNXkGDBtGw6x0f5v80/TCdk5vV0+8n3wHJ0wiXJjUcb+xavkXD66tqy5cdud+bVzlU2jVxutZGLjdwzYo7cshW/blT4qrz2kg4QaSENxZjIlzed0WEg+xRLetUp6yBVSML/1K7uEBKrQcP44H3EkLf1knCtN1o2Im4ORL+vT8=" diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..894450c --- /dev/null +++ b/.yamllint @@ -0,0 +1,15 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable + +ignore: | + .tox/ diff --git a/README.md b/README.md index e937008..ab10ab6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## postfix -[![Build Status](https://travis-ci.org/Oefenweb/ansible-postfix.svg?branch=master)](https://travis-ci.org/Oefenweb/ansible-postfix) +[![CI](https://github.com/Oefenweb/ansible-postfix/workflows/CI/badge.svg)](https://github.com/Oefenweb/ansible-postfix/actions?query=workflow%3ACI) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-postfix-blue.svg)](https://galaxy.ansible.com/oefenweb/postfix) Set up a postfix server in Debian-like systems. @@ -29,7 +29,8 @@ None * `postfix_sender_dependent_relayhost_maps` [default: `[]`]: Transport mapping based on sender address `/etc/postfix/sender_dependent_relayhost_maps` ([see](http://www.postfix.org/postconf.5.html#recipient_canonical_maps)) * `postfix_header_checks` [default: `[]`]: Lookup tables for content inspection of primary non-MIME message headers `/etc/postfix/header_checks` ([see](http://www.postfix.org/postconf.5.html#header_checks)) * `postfix_header_checks_database_type` [default: `regexp`]: The database type for use in `header_checks` - * `postfix_generic` [default: `[]`]: Generic table address mapping in `/etc/postfix/generic` ([see](http://www.postfix.org/generic.5.html)) + * `postfix_generic` [default: `postfix_smtp_generic_maps`]: **Deprecated**, use `postfix_smtp_generic_maps` + * `postfix_smtp_generic_maps` [default: `[]`]: Generic table address mapping in `/etc/postfix/generic` ([see](http://www.postfix.org/generic.5.html)) * `postfix_smtp_generic_maps_database_type` [default: `"{{ postfix_default_database_type }}"`]: The database type for use in `smtp_generic_maps` * `postfix_mydestination` [default: `["{{ postfix_hostname }}", 'localdomain', 'localhost', 'localhost.localdomain']`]: Specifies what domains this machine will deliver locally, instead of forwarding to another machine diff --git a/Vagrantfile b/Vagrantfile index 3517233..a0182a0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,40 +4,26 @@ role = File.basename(File.expand_path(File.dirname(__FILE__))) boxes = [ - { - :name => "ubuntu-1204", - :box => "bento/ubuntu-12.04", - :ip => '10.0.0.11', - :cpu => "50", - :ram => "256" - }, - { - :name => "ubuntu-1404", - :box => "bento/ubuntu-14.04", - :ip => '10.0.0.12', - :cpu => "50", - :ram => "256" - }, { :name => "ubuntu-1604", :box => "bento/ubuntu-16.04", - :ip => '10.0.0.13', + :ip => '10.0.0.12', :cpu => "50", :ram => "256" }, { :name => "ubuntu-1804", :box => "bento/ubuntu-18.04", - :ip => '10.0.0.14', + :ip => '10.0.0.13', :cpu => "50", :ram => "384" }, { - :name => "debian-7", - :box => "bento/debian-7", - :ip => '10.0.0.15', + :name => "ubuntu-2004", + :box => "bento/ubuntu-20.04", + :ip => '10.0.0.14', :cpu => "50", - :ram => "256" + :ram => "384" }, { :name => "debian-8", diff --git a/defaults/main.yml b/defaults/main.yml index 98d6720..e2c9fa3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -22,7 +22,8 @@ postfix_transport_maps_database_type: "{{ postfix_default_database_type }}" postfix_sender_dependent_relayhost_maps: [] postfix_header_checks: [] postfix_header_checks_database_type: regexp -postfix_generic: [] +postfix_generic: "{{ postfix_smtp_generic_maps }}" +postfix_smtp_generic_maps: [] postfix_smtp_generic_maps_database_type: "{{ postfix_default_database_type }}" postfix_relayhost: '' diff --git a/handlers/main.yml b/handlers/main.yml index c820da9..2c5c1ae 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -29,7 +29,7 @@ when: postfix_default_database_type != 'regexp' - name: postmap generic - command: postmap {{ postfix_smtp_generic_maps_database_type }}:{{ postfix_generic_file }} + command: postmap {{ postfix_smtp_generic_maps_database_type }}:{{ postfix_smtp_generic_maps_file }} when: postfix_smtp_generic_maps_database_type != 'regexp' - name: remove pid diff --git a/meta/main.yml b/meta/main.yml index 44d8381..222e2dc 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -10,13 +10,11 @@ galaxy_info: platforms: - name: Ubuntu versions: - - precise - - trusty - xenial - bionic + - focal - name: Debian versions: - - wheezy - jessie - stretch - buster diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..44670e5 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,13 @@ +--- +- name: Converge + hosts: all + become: true + pre_tasks: + - name: include variables + include_vars: "{{ item }}" + with_first_found: + - "{{ playbook_dir }}/../../tests/vars/_{{ ansible_distribution_release }}.yml" + - "{{ playbook_dir }}/../../tests/vars/_{{ ansible_distribution | lower }}.yml" + - "{{ playbook_dir }}/../../tests/vars/_default.yml" + roles: + - ../../../ diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..fbb7120 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,19 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu1604}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: verify.yml diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..9a6673d --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare + hosts: all + become: true + tasks: [] diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..44debad --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,5 @@ +--- +- name: Verify + hosts: all + become: true + tasks: [] diff --git a/tasks/main.yml b/tasks/main.yml index 133905c..61a2c38 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -202,7 +202,7 @@ - name: configure generic table lineinfile: - dest: "{{ postfix_generic_file }}" + dest: "{{ postfix_smtp_generic_maps_file }}" regexp: '^{{ item.pattern | regex_escape }}\s.*' line: '{{ item.pattern }} {{ item.result }}' owner: root @@ -210,7 +210,7 @@ mode: 0644 create: true state: present - with_items: "{{ postfix_generic }}" + with_items: "{{ postfix_smtp_generic_maps }}" notify: - postmap generic - restart postfix diff --git a/templates/etc/postfix/main.cf.j2 b/templates/etc/postfix/main.cf.j2 index e590a56..ba9431c 100644 --- a/templates/etc/postfix/main.cf.j2 +++ b/templates/etc/postfix/main.cf.j2 @@ -51,8 +51,8 @@ transport_maps = {{ postfix_transport_maps_database_type }}:{{ postfix_transport {% if postfix_sender_dependent_relayhost_maps %} sender_dependent_relayhost_maps = {{ postfix_default_database_type }}:{{ postfix_sender_dependent_relayhost_maps_file }} {% endif %} -{% if postfix_generic %} -smtp_generic_maps = {{ postfix_smtp_generic_maps_database_type }}:{{ postfix_generic_file }} +{% if postfix_smtp_generic_maps %} +smtp_generic_maps = {{ postfix_smtp_generic_maps_database_type }}:{{ postfix_smtp_generic_maps_file }} {% endif %} {% if postfix_header_checks %} smtp_header_checks = {{ postfix_header_checks_database_type }}:{{ postfix_header_checks_file }} diff --git a/vars/main.yml b/vars/main.yml index 050326f..9488eca 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -15,5 +15,5 @@ postfix_sender_canonical_maps_file: /etc/postfix/sender_canonical_maps postfix_recipient_canonical_maps_file: /etc/postfix/recipient_canonical_maps postfix_transport_maps_file: /etc/postfix/transport_maps postfix_sender_dependent_relayhost_maps_file: /etc/postfix/sender_dependent_relayhost_maps -postfix_generic_file: /etc/postfix/generic +postfix_smtp_generic_maps_file: /etc/postfix/generic postfix_header_checks_file: /etc/postfix/header_checks From e2533ff62f43b312948c6117bf0ec5daaf9d9c3d Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 22 Feb 2021 12:45:27 +0100 Subject: [PATCH 2/3] Cs fix --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 61a2c38..bc404a1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,7 +2,7 @@ --- - name: facts | set set_fact: - is_docker_guest: "{{ ansible_virtualization_role | default('host') == 'guest' and ansible_virtualization_type | default('none') == 'docker' }}" + is_docker_guest: "{{ ansible_virtualization_role | default('host') == 'guest' and ansible_virtualization_type | default('none') == 'docker' }}" tags: - configuration - postfix From 783bee27578502b66611838fe7c16f8812c7b6ab Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 22 Feb 2021 12:49:26 +0100 Subject: [PATCH 3/3] Cleanup --- molecule/default/converge.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 44670e5..be762b2 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -2,12 +2,5 @@ - name: Converge hosts: all become: true - pre_tasks: - - name: include variables - include_vars: "{{ item }}" - with_first_found: - - "{{ playbook_dir }}/../../tests/vars/_{{ ansible_distribution_release }}.yml" - - "{{ playbook_dir }}/../../tests/vars/_{{ ansible_distribution | lower }}.yml" - - "{{ playbook_dir }}/../../tests/vars/_default.yml" roles: - ../../../