Changeset - 13982172ed2e
[Not reviewed]
roles/mail_forwarder/defaults/main.yml
Show inline comments
 
---
 

	
 
local_mail_aliases: {}
 
smtp_from_relay_allowed: True
 
smtp_from_relay_allowed: true
 
smtp_relay_host: ""
 
smtp_relay_truststore: "{{ lookup('file', tls_certificate_dir + '/truststore.pem') }}"
 
smtp_relay_host_port: null
roles/mail_forwarder/molecule/default/create.yml
Show inline comments
 
---
 
- name: Create
 
  hosts: localhost
 
  connection: local
 
  gather_facts: False
 
  gather_facts: false
 
  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
 
  vars:
 
    molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
 
    molecule_instance_config: "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}"
 
    molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
 
  tasks:
roles/mail_forwarder/molecule/default/destroy.yml
Show inline comments
 
---
 

	
 
- name: Destroy
 
  hosts: localhost
 
  connection: local
 
  gather_facts: False
 
  gather_facts: false
 
  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
 
  vars:
 
    molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
 
    molecule_instance_config: "{{ lookup('env',' MOLECULE_INSTANCE_CONFIG') }}"
 
    molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
 
  tasks:
roles/mail_forwarder/molecule/default/group_vars/parameters-mandatory.yml
Show inline comments
 
new file 100644
 
---
 

	
 
# Global common parameters.
 
tls_certificate_dir: tests/data/x509/
roles/mail_forwarder/molecule/default/group_vars/parameters-no-incoming.yml
Show inline comments
 
new file 100644
 
---
 

	
 
smtp_relay_host: mail-server
 
smtp_from_relay_allowed: false
 
smtp_relay_truststore: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 

	
 
# common
 
ca_certificates:
 
  testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
roles/mail_forwarder/molecule/default/group_vars/parameters-optional.yml
Show inline comments
 
new file 100644
 
---
 

	
 
local_mail_aliases:
 
  root: "root testuser"
 
smtp_from_relay_allowed: true
 
smtp_relay_host: mail-server
 
smtp_relay_host_port: 27
 
smtp_relay_truststore: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 

	
 
# common
 
ca_certificates:
 
  testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
roles/mail_forwarder/molecule/default/molecule.yml
Show inline comments
 
@@ -6,12 +6,14 @@ driver:
 
  name: vagrant
 
  provider:
 
    name: virtualbox
 

	
 
lint:
 
  name: yamllint
 
  options:
 
    config-file: ../../.yamllint.yml
 

	
 
platforms:
 

	
 
  - name: mail-server
 
    groups:
 
      - mail-servers
roles/mail_forwarder/molecule/default/playbook.yml
Show inline comments
 
---
 

	
 
- hosts: parameters-mandatory
 
  become: yes
 
- hosts: parameters-mandatory,parameters-optional,parameters-no-incoming
 
  become: true
 
  roles:
 
    - role: mail_forwarder
 

	
 
      # Global common parameters.
 
      tls_certificate_dir: tests/data/x509/
 

	
 
- hosts: parameters-optional
 
  become: yes
 
  roles:
 
    - role: mail_forwarder
 
      local_mail_aliases:
 
        root: "root testuser"
 
      smtp_from_relay_allowed: True
 
      smtp_relay_host: mail-server
 
      smtp_relay_host_port: 27
 
      smtp_relay_truststore: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 

	
 
      # common
 
      ca_certificates:
 
        testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 

	
 
- hosts: parameters-no-incoming
 
  become: yes
 
  roles:
 
    - role: mail_forwarder
 
      smtp_relay_host: mail-server
 
      smtp_from_relay_allowed: False
 
      smtp_relay_truststore: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 

	
 
      # common
 
      ca_certificates:
 
        testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 
    - mail_forwarder
roles/mail_forwarder/molecule/default/prepare.yml
Show inline comments
 
---
 

	
 
- name: Prepare
 
  hosts: all
 
  gather_facts: False
 
  gather_facts: false
 
  tasks:
 
    - name: Install python for Ansible
 
      raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
 
      become: True
 
      changed_when: False
 
      become: true
 
      changed_when: false
 

	
 
- hosts: all
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Update all caches to avoid errors due to missing remote archives
 
      apt:
 
        update_cache: yes
 
      changed_when: False
 
        update_cache: true
 
      changed_when: false
 

	
 
- hosts: all
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Set-up the hosts file
 
      lineinfile:
 
        path: /etc/hosts
 
        regexp: "^{{ item.key }}"
 
@@ -39,24 +39,24 @@
 
        10.31.127.22: "parameters-no-incoming-jessie64"
 
        10.31.127.30: "parameters-mandatory-stretch64"
 
        10.31.127.31: "parameters-optional-stretch64"
 
        10.31.127.32: "parameters-no-incoming-stretch64"
 

	
 
- hosts: clients
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Install SWAKS for testing SMTP capability
 
      apt:
 
        name: swaks
 
        state: installed
 
        state: present
 

	
 
    - name: Install tool for testing TCP connectivity
 
      apt:
 
        name: hping3
 
        state: installed
 
        state: present
 

	
 
    - name: Deploy CA certificate
 
      copy:
 
        src: tests/data/x509/ca.cert.pem
 
        dest: /usr/local/share/ca-certificates/testca.crt
 
        owner: root
 
@@ -68,13 +68,13 @@
 
  handlers:
 

	
 
    - name: Update CA certificate cache
 
      command: /usr/sbin/update-ca-certificates --fresh
 

	
 
- hosts: mail-servers
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Deploy CA certificate
 
      copy:
 
        src: tests/data/x509/ca.cert.pem
 
        dest: /usr/local/share/ca-certificates/testca.crt
 
@@ -93,16 +93,21 @@
 
        mode: 0600
 
      with_items:
 
        - mail-server_smtp.cert.pem
 
        - mail-server_smtp.key.pem
 

	
 
    - name: Install Postfix
 
      apt: name="postfix" state=installed
 
      apt:
 
        name: "postfix"
 
        state: present
 

	
 
    - name: Purge Exim configuration
 
      apt: name="exim4*" state=absent purge=yes
 
      apt:
 
        name: "exim4*"
 
        state: absent
 
        purge: true
 

	
 
    - name: Deploy Postfix configuration
 
      copy:
 
        src: tests/data/main.cf
 
        dest: /etc/postfix/main.cf
 
        owner: root
 
@@ -111,35 +116,35 @@
 
      notify:
 
        - Restart Postfix
 

	
 
    - name: Install tool for testing TCP connectivity
 
      apt:
 
        name: hping3
 
        state: installed
 
        state: present
 

	
 
    - name: Install SWAKS for testing SMTP capability
 
      apt:
 
        name: swaks
 
        state: installed
 
        state: present
 

	
 
    - name: Set-up port forwarding
 
      command: "iptables -t nat -A PREROUTING -p tcp -m tcp --dport 27 -j REDIRECT --to-ports 25"
 
      changed_when: False
 
      changed_when: false
 

	
 
  handlers:
 

	
 
    - name: Update CA certificate cache
 
      command: /usr/sbin/update-ca-certificates --fresh
 

	
 
    - name: Restart Postfix
 
      service:
 
        name: postfix
 
        state: restarted
 

	
 
- hosts: parameters-optional
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Create additional group for testing local aliases
 
      group:
 
        name: testuser
 

	
roles/mail_forwarder/molecule/default/tests/test_connectivity_from_client.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('client1')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['client1'])
 

	
 

	
 
def test_connectivity_from_client(host):
 
    """
 
    Tests connectivity towards mail forwarder servers from client
 
    (non-relay). Connectivity should fail for both.
roles/mail_forwarder/molecule/default/tests/test_connectivity_from_relay.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('mail-server')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['mail-server'])
 

	
 

	
 
def test_connectivity_from_relay(host):
 
    """
 
    Tests connectivity towards mail forwarder servers from relay. Connection
 
    towards parameters-mandatory should fail.
roles/mail_forwarder/molecule/default/tests/test_default.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts(['parameters-mandatory', 'parameters-optional', 'parameters-no-incoming'])
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory', 'parameters-optional', 'parameters-no-incoming'])
 

	
 

	
 
def test_installed_packages(host):
 
    """
 
    Tests if the necessary packages have been installed.
 
    """
roles/mail_forwarder/molecule/default/tests/test_mandatory.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('parameters-mandatory')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory'])
 

	
 

	
 
def test_smtp_relay_truststore_file(host):
 
    """
 
    Tests if SMTP relay truststore has correct content.
 
    """
roles/mail_forwarder/molecule/default/tests/test_optional.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('parameters-optional')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-optional'])
 

	
 

	
 
def test_smtp_relay_truststore_file(host):
 
    """
 
    Tests if SMTP relay truststore has correct content.
 
    """
roles/mail_forwarder/molecule/default/tests/test_smtp_relay_host_port.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('parameters-no-incoming')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-no-incoming'])
 

	
 

	
 
def test_postfix_main_cf_file_content(host):
 
    """
 
    Tests if the Postfix main configuration file content is correct.
 
    """
roles/mail_forwarder/tasks/main.yml
Show inline comments
 
---
 

	
 
- name: Install Postfix
 
  apt:
 
    name: postfix
 
    state: installed
 
    state: present
 

	
 
- name: Install procmail
 
  apt:
 
    name: procmail
 
    state: installed
 
    state: present
 

	
 
- name: Purge Exim configuration
 
  apt:
 
    name: "exim4*"
 
    state: absent
 
    purge: yes
 
    purge: true
 

	
 
- name: Deploy the SMTP relay TLS truststore
 
  copy:
 
    content: "{{ smtp_relay_truststore }}"
 
    dest: "/etc/ssl/certs/smtp_relay_truststore.pem"
 
    owner: root
 
@@ -74,13 +74,13 @@
 
  notify:
 
    - Restart ferm
 

	
 
- name: Install SWAKS
 
  apt:
 
    name: swaks
 
    state: installed
 
    state: present
 

	
 
- name: Explicitly run all handlers
 
  include: ../handlers/main.yml
 
  when: "handlers | default(False) | bool() == True"
 
  tags:
 
    - handlers
0 comments (0 inline, 0 general)