diff --git a/.gitignore b/.gitignore index 9ca390c..1331d18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .kitchen/* - +*.pyc diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index 7a16e14..0000000 --- a/.kitchen.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -driver: - name: docker_cli - -transport: - name: docker_cli - -provisioner: - name: ansible_playbook - hosts: localhost - require_ansible_repo: false - require_ansible_omnibus: false - require_chef_for_busser: true - ansible_verbose: false - ansible_inventory: ./test/integration/inventory - -platforms: - - name: debian-9 - driver_config: - image: "nishiki/debian9:ansible-<%= ENV['ANSIBLE_VERSION'] ? ENV['ANSIBLE_VERSION'] : '2.7' %>" - command: /bin/systemd - volume: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - security_opt: seccomp=unconfined - -suites: - - name: default diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 66555b6..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -AllCops: - Exclude: - - db/**/* - - config/**/* - - Vagrantfile - TargetRubyVersion: 2.4 - -Naming/AccessorMethodName: - Enabled: false - -Lint/RescueWithoutErrorClass: - Enabled: false - -Metrics/LineLength: - Max: 120 -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/AbcSize: - Enabled: false - -Style/NumericLiteralPrefix: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/CommandLiteral: - Enabled: true - EnforcedStyle: percent_x -Style/Documentation: - Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 438c58c..31e3e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) ### Added +- test: add suport debian 10 and 11 - feat: add bsd-mailx package - feat: add transport map - feat: add aliases @@ -18,6 +19,11 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) ### Changed - chore: use FQCN for module name +- test: replace kitchen to molecule + +### Removed + +- test: remove support debian 9 ## v1.0.0 - 2019-03-07 diff --git a/README.md b/README.md index c89541f..60a6cea 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ Install and configure an simple mta with postfix ## Requirements -* Ansible >= 2.7 -* Debian Stretch +* Ansible >= 2.9 +* Debian + * Buster + * Bullseye ## Role variables @@ -56,17 +58,12 @@ Install and configure an simple mta with postfix ## Development -### Test syntax with yamllint +### Test with molecule and docker -* install `python` and `python-pip` -* install yamllint `pip install yamllint` -* run `yamllint .` - -### Test syntax with ansible-lint - -* install `python` and `python-pip` -* install yamllint `pip install ansible-lint` -* run `ansible-lint .` +* install [docker](https://docs.docker.com/engine/installation/) +* install `python3` and `python3-pip` +* install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint pytest-testinfra yamllint` +* run `molecule test` ### Tests with docker diff --git a/meta/main.yml b/meta/main.yml index 8b1edd6..abdf086 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,16 +1,17 @@ --- galaxy_info: - role_name: postfix-mta + role_name: postfix_mta author: Adrien Waksberg company: Adrien Waksberg description: Install and configure a simple mta with postfix license: Apache2 - min_ansible_version: 2.7 + min_ansible_version: 2.9 platforms: - name: Debian versions: - - stretch + - buster + - bullseye galaxy_tags: - postfix diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..6803a65 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,22 @@ +--- +- name: Converge + hosts: all + roles: + - ansible-role-postfix_mta + vars: + postfix_config: + inet_protocols: ipv4 + transport_maps: hash:/etc/postfix/transport + aliases_maps: hash:/etc/postfix/aliases + postfix_transports: + google.com: smtp:127.0.0.1 + postfix_aliases: + root: + - admin + - abuse + admin: admin@localhost.loc + + pre_tasks: + - name: update apt cache + ansible.builtin.apt: + update_cache: true diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..0507c53 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,26 @@ +--- +driver: + name: docker +platforms: + - name: debian10 + image: nishiki/debian10:molecule + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + command: /bin/systemd + capabilities: + - SYS_ADMIN + - name: debian11 + image: nishiki/debian11:molecule + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + command: /bin/systemd + capabilities: + - SYS_ADMIN +lint: | + set -e + yamllint . + ansible-lint . +verifier: + name: testinfra diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100644 index 0000000..edfb603 --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,42 @@ +import testinfra.utils.ansible_runner + +def test_packages(host): + for package_name in ['postfix', 'bsd-mailx']: + package = host.package(package_name) + assert package.is_installed + +def test_config_file(host): + path = host.file('/etc/postfix/main.cf') + assert path.exists + assert path.is_file + assert path.user == 'root' + assert path.group == 'root' + assert path.mode == 0o644 + assert path.contains('inet_protocols = ipv4') + +def test_transport_file(host): + path = host.file('/etc/postfix/transport') + assert path.exists + assert path.is_file + assert path.user == 'root' + assert path.group == 'root' + assert path.mode == 0o644 + assert path.contains('google.com smtp:127.0.0.1') + +def test_aliases_file(host): + path = host.file('/etc/postfix/aliases') + assert path.exists + assert path.is_file + assert path.user == 'root' + assert path.group == 'root' + assert path.mode == 0o644 + assert path.contains('root: admin,abuse') + +def test_service(host): + service = host.service('postfix') + assert service.is_running + assert service.is_enabled + +def test_socket(host): + socket = host.socket('tcp://127.0.0.1:25') + assert socket.is_listening diff --git a/test/integration/default/default.yml b/test/integration/default/default.yml deleted file mode 100644 index a71ac67..0000000 --- a/test/integration/default/default.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- hosts: default - connection: local - vars: - postfix_protocols: ipv4 - - roles: - - ansible-role-postfix-mta diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb deleted file mode 100644 index 54879b3..0000000 --- a/test/integration/default/serverspec/default_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'serverspec' - -set :backend, :exec - -puts -puts '================================' -puts %x(ansible --version) -puts '================================' - -%w[postfix bsd-mailx].each do |name| - describe package(name) do - it { should be_installed } - end -end - -describe file('/etc/postfix/main.cf') do - it { should be_file } - it { should be_mode 644 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should contain 'protocols = ipv4' } -end - -describe service('postfix') do - it { should be_enabled } - it { should be_running } - it { should be_running.under('systemd') } -end - -describe port(25) do - it { should be_listening } -end diff --git a/test/integration/inventory b/test/integration/inventory deleted file mode 100644 index 1ad37c3..0000000 --- a/test/integration/inventory +++ /dev/null @@ -1,2 +0,0 @@ -[default] -localhost