diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 83a18d25e58ca7adc2e526f0ed30b12263cb0c13..233bc80d8f4b0a2ed98f97e33a6269dd6ef0d882 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ - id: check-merge-conflict - id: flake8 - id: check-symlinks -- repo: https://www.shore.co.il/git/ansible-pre-commit +- repo: https://github.com/adarnimrod/ansible-pre-commit.git sha: 0fadd691465b97db8992cfc66650f630e433324b hooks: - id: ansible-syntax-check diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..5ffdda67f1e0328400f9f8521ca831818be20357 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +--- +language: python +python: "2.7" +dist: trusty +sudo: false +group: beta +services: [docker] +cache: + - pip + - directories: + - $HOME/.pre-commit + +install: + - pip install -r tests/requirements.txt | cat + - ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles + - molecule dependency + +script: + - pre-commit run --all-files + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ + email: false diff --git a/README.rst b/README.rst index 52948489037260fa75f7d16db3dac77399e2f16c..12d4ea39168332ace647b4aff3a9c74b584838be 100644 --- a/README.rst +++ b/README.rst @@ -1,10 +1,14 @@ bgp-spamd ######### -Provision spamd with spam list distributed via bpg. For more information visit -`bgp-spamd.net <http://bgp-spamd.net/>`_. Configuration of PF is more custom and -out of scope for this role, however one can include the configuration snippet -created by this role by adding the following to your :code:`pf.conf`. +.. image:: https://travis-ci.org/adarnimrod/bgp-spamd.svg?branch=master + :target: https://travis-ci.org/adarnimrod/bgp-spamd + +Provision spamd with spam list distributed via BGP using OpenBGPD on OpenBSD. +For more information visit `bgp-spamd.net <http://bgp-spamd.net/>`_. +Configuration of PF is more custom and out of scope for this role, however one +can include the configuration snippet created by this role by adding the +following to your :code:`pf.conf`. .. code:: @@ -23,8 +27,7 @@ your :code:`pf.conf`. Requirements ------------ -See :code:`meta/main.yml`, :code:`tests/requirements.yml` and assertions at -the top of :code:`tasks/main.yml`. +See :code:`meta/main.yml` and assertions at the top of :code:`tasks/main.yml`. Role Variables -------------- @@ -44,21 +47,22 @@ See :code:`tests/playbook.yml`. Testing ------- -Testing requires Virtualbox and Vagrant and Python 2.7. Install the Python -dependencies, add pre-commit hooks by running: +Testing requires Python 2.7 and either Docker or Vagrant and Virtualbox. +Install the Python dependencies, dependent roles and roles required for +testing: .. code:: shell pip install -r tests/requirements.txt - pre-commit install + ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles + molecule dependency To run the full test suite: .. code:: shell - ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles - molecule test --platform all pre-commit run --all-files + molecule test --platform all License ------- @@ -73,3 +77,9 @@ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located at: https://www.shore.co.il/git/. + +TODO +---- + +- Better tests in Travis CI (currently everything is done offline because of + dependency on VirtualBox). diff --git a/ansible.cfg b/ansible.cfg index 2bc7613f4df5ddc0fe0f2719df832ddfff4bfe62..905e3c64897217cd1b88acde10920ae04c7c6011 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -5,6 +5,7 @@ retry_files_enabled = False roles_path = .molecule/roles:.molecule/../roles:../:../../ command_warnings = True deprecation_warnings = True +callback_whitelist = profile_tasks [ssh_connection] pipelining = True diff --git a/defaults/main.yml b/defaults/main.yml index bac4ccdc5f882052a33374264ec984901f88e540..cf3d70b0588b02d80a360ced88e800ae4cfadc1d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,5 @@ --- -# defaults file for ansible-role-bgp-spamd +# defaults file for bgp-spamd spamd_hostname: '{{ ansible_fqdn }}' # The hostname sent by spamd. spamd_alloweddomains: [] # Allowed domains to be whitelisted. diff --git a/handlers/main.yml b/handlers/main.yml index 703775e2d601fdcebb7ec5a36753a986ab20935f..074beb86093349b6dd1ff533c77045673b1513db 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,5 @@ --- -# handlers file for ansible-role-bgp-spamd +# handlers file for bgp-spamd - name: Reload PF command: /sbin/pfctl -f /etc/pf.conf diff --git a/meta/main.yml b/meta/main.yml index 59f4f9d8dc4582b0e84bd3acc638fd771946a05b..d1afa3c37379cd09b67f28a9598fdf55f0608491 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,6 +1,6 @@ galaxy_info: author: Nimrod Adar - description: An example Ansible role + description: Provision spamd with spam list distributed via BGP using OpenBGPD on OpenBSD company: Shore technologies license: MIT min_ansible_version: 2.0 diff --git a/molecule.yml b/molecule.yml index e98775a270e7ea8498149662ae3e2c06ab1f1477..1cc2103ba63439cf7e62b551a6a68a90904e7052 100644 --- a/molecule.yml +++ b/molecule.yml @@ -4,6 +4,9 @@ ansible: playbook: tests/playbook.yml diff: True config_file: ../ansible.cfg + +dependency: + name: galaxy requirements_file: tests/requirements.yml vagrant: @@ -14,7 +17,7 @@ vagrant: - name: openbsd box: kaorimatz/openbsd-6.0-amd64 instances: - - name: ansible-role-bgp-spamd + - name: bgp-spamd options: append_platform_to_hostname: yes raw_config_args: diff --git a/tasks/main.yml b/tasks/main.yml index cbc25b6a0d84d4061acb2751b28375ba114b6195..d906017d89206d20c6eabade6dab6689b912b8f6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,5 @@ --- -# tasks file for ansible-role-bgp-spamd +# tasks file for bgp-spamd - name: Assertions assert: diff --git a/tests/playbook.yml b/tests/playbook.yml index 62d08274f7267cb35226879da106124a7dfa9037..2f19a66528dbc2dd8ac280f6e7fd0ab7af3ac878 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,7 +1,7 @@ --- -- hosts: ansible-role-bgp-spamd-openbsd +- hosts: bgp-spamd-openbsd gather_facts: false - roles: [openbsd_bootstrap] + roles: [openbsd-bootstrap] - hosts: all pre_tasks: @@ -11,5 +11,5 @@ dest: /etc/pf.conf state: present roles: - - role: ansible-role-bgp-spamd + - role: bgp-spamd spamd_alloweddomains: ["{{ ansible_domain }}"] diff --git a/tests/requirements.txt b/tests/requirements.txt index 0588c359a06c17f6d8a27f8d19be6cf89b2758b8..497d43068abcde060d092a5241d0a3ddac24b589 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,6 +1,11 @@ ansible==2.2.0.0 -testinfra==1.4.3 -molecule==1.13.0 -ansible-lint==3.4.4 -pre-commit==0.9.3 +testinfra==1.4.5 +molecule==1.17.0 +ansible-lint==3.4.8 +pre-commit==0.9.4 piprot==0.9.7 +python-vagrant==0.5.14 +docker-py==1.10.6 +netaddr==0.7.18 +passlib==1.7.0 +bcrypt==3.1.1 diff --git a/tests/requirements.yml b/tests/requirements.yml index 8b9b2bcba3b4459621ff239243ac0375a081f20a..70716f60b9e624bc5a09442517a08667363949f4 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -1,7 +1,5 @@ --- -- src: https://www.shore.co.il/git/ansible-role-openbsd-bootstrap - scm: git - name: openbsd_bootstrap -- src: https://www.shore.co.il/git/ansible-role-debian-bootstrap - scm: git - name: debian_bootstrap +- src: adarnimrod.openbsd-bootstrap + name: openbsd-bootstrap +- src: adarnimrod.debian-bootstrap + name: debian-bootstrap diff --git a/tests/test_example.py b/tests/test_example.py index 12d4c7a5294fc8128e8ae695e8afaaa62a002f9b..aaea50030b9784f0528df9b936cf1903d3af5994 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -1,7 +1,12 @@ +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') + + def test_example(Command): assert Command('uname').rc == 0 def test_root(Command, Sudo): with Sudo(): - assert Command('whoami').stdout == 'root' + assert Command('whoami').stdout.strip() == 'root' diff --git a/vars/main.yml b/vars/main.yml index 30dbf867fa9b10d26ffcdfbf40fb4e0e29b3beac..1beebfbce6369488d406249f83582d08d8d8df13 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for ansible-role-bgp-spamd +# vars file for bgp-spamd