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..abc583a44f62a169059b177cabed55bfe3ab9183 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +--- +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 + - molecule test --driver docker + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ + email: false diff --git a/README.rst b/README.rst index e1a13e8f0b75379c1cd77fd65e08c4347813a4ec..c7a05e4b2cf4f64b1d2d2dca101c454bce467154 100644 --- a/README.rst +++ b/README.rst @@ -1,15 +1,18 @@ Unbound ####### +.. image:: https://travis-ci.org/adarnimrod/example.svg?branch=master + :target: https://travis-ci.org/adarnimrod/example + Provision the Unbound DNS resolver. The configuration from this role is log to syslog, DNSSEC and use the conf.d directory. To add your own configuration, add -a template at :code:`template/unbound/conf.d/*.conf`. +a template at :code:`template/unbound/conf.d/*.conf` either inside the role or +relative to your playbook. 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 -------------- @@ -29,21 +32,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 ------- diff --git a/ansible.cfg b/ansible.cfg index 2bc7613f4df5ddc0fe0f2719df832ddfff4bfe62..a33a906b7db5fa209df2b129eff0b36c42f661d9 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -2,9 +2,10 @@ library = library host_key_checking = False retry_files_enabled = False -roles_path = .molecule/roles:.molecule/../roles:../:../../ +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 9a3581475b3f760799ff051054939e2c2375f328..01d9b26452cf7dd6be57f491b59c5588d1e76890 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,4 @@ --- -# defaults file for ansible-role-unbound +# defaults file for unbound + unbound_mail_alias: root diff --git a/handlers/main.yml b/handlers/main.yml index 17c7c19c2a4141a42aeb9e59b066a0afa8cfada5..fb0242e66150c06f106be4a7fb5abf86e15f8604 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,6 @@ --- -# handlers file for ansible-role-unbound +# handlers file for unbound + - name: Restart Unbound service: name: unbound diff --git a/meta/main.yml b/meta/main.yml index f9425516aa1c1e07f1fc3b0f1262202822f5cb36..58f49ba362b1b241ae6cf9b2bf008d509b86097b 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,6 +1,6 @@ galaxy_info: author: Nimrod Adar - description: Provision Unbound DNS resolver + description: Provision the Unbound DNS resolver company: Shore technologies license: MIT min_ansible_version: 2.0 diff --git a/molecule.yml b/molecule.yml index ee423d7f964b367c3e105adbbe62ac08fd85b98a..fd6a14ce33cf0435ece91e9f4d67e6775cc90ec4 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: @@ -13,10 +16,10 @@ vagrant: platforms: - name: openbsd box: kaorimatz/openbsd-6.0-amd64 - - name: debian + - name: jessie box: debian/jessie64 instances: - - name: ansible-role-unbound + - name: unbound options: append_platform_to_hostname: yes raw_config_args: @@ -24,3 +27,17 @@ vagrant: - 'vbguest.auto_update = false' - 'landrush.enabled = false' - 'landrush_ip.override = false' + +docker: + containers: + - name: unbound-xenial + image: ubuntu + image_version: xenial + command: /sbin/init + privileged: True + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup + - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket + environment: + DEBIAN_FRONTEND: noninteractive + container: docker diff --git a/tasks/main.yml b/tasks/main.yml index 724bb2b1ebea8dabb160b28e640900b0fd912e81..198710d01e66670d8cfca62316705ed443d84be9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,9 +1,11 @@ --- -# tasks file for ansible-role-unbound +# tasks file for unbound + - name: Assertions assert: that: - - ansible_os_family in ['OpenBSD', 'Debian'] + - ansible_os_family in aliases_file + - ansible_os_family in unbound_user - name: APT install when: ansible_pkg_mgr == 'apt' diff --git a/tests/playbook.yml b/tests/playbook.yml index df0cd6b53e90c74cbe85c84bfe0c81eee81b03d7..2b6cfdcee01c4d0f428f07afce38e4ee346857a6 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,7 +1,13 @@ --- -- hosts: ansible-role-unbound-openbsd +- hosts: unbound-openbsd gather_facts: false - roles: [openbsd_bootstrap] + roles: [openbsd-bootstrap] + +- hosts: unbound-xenial + gather_facts: false + roles: [debian-bootstrap] - hosts: all - roles: [ansible-role-unbound] + strategy: free + roles: + - role: unbound diff --git a/tests/requirements.txt b/tests/requirements.txt index 0588c359a06c17f6d8a27f8d19be6cf89b2758b8..e48b249b4899c9d8170a65953599aa44c633517f 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.2 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/tests/test_unbound.py b/tests/test_unbound.py index 5f824458303de6855caca9ad73b33c6cc919be1c..819d3a33302379c2e69fadacf94b4cfac1ea63cc 100644 --- a/tests/test_unbound.py +++ b/tests/test_unbound.py @@ -1,3 +1,8 @@ +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') + + def test_unbound_config(Command, Sudo): with Sudo(): assert Command('unbound-checkconf').rc == 0 diff --git a/vars/main.yml b/vars/main.yml index ec128bacd5149a7a4938b231d0da9085ea5b7ea6..230bbfd52066768711a85e48a640cf057c0bfd4c 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,5 +1,5 @@ --- -# vars file for ansible-role-unbound +# vars file for unbound aliases_file: OpenBSD: /etc/mail/aliases