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 549f9d3f44decb5d6832f9d04403a72f4eeddbf3..57d46644822eafd37f69bd645605f3a4b467e66e 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,10 @@ NSD ### -Provision NSD authorative DNS server. By default the role has minimal +.. image:: https://travis-ci.org/adarnimrod/nsd.svg?branch=master + :target: https://travis-ci.org/adarnimrod/nsd + +Provision an NSD authorative DNS server. By default the role has minimal configuration. You can add your own by overriding the default :code:`nsd_config` dictionary with your own for configuration under the :code:`server` block in :code:`nsd.conf`. For other blocks that can declared @@ -14,8 +17,7 @@ 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 -------------- @@ -35,21 +37,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 98921f075db0b13648778ba40013b97f5d9de3fe..69ca08bcca695a7867e5d10f89760007d8569d18 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,5 @@ --- -# defaults file for ansible-role-nsd +# defaults file for nsd nsd_mail_alias: root # Where to send mail for the NSD user. nsd_config: # key/value configuration under the server block, for more diff --git a/handlers/main.yml b/handlers/main.yml index 1d0cfc2ccee28d9ca5d9af1bbdd35ce592d35c52..9b195ffbb8295d3935dd5765198a0d3f9f47c302 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,5 @@ --- -# handlers file for ansible-role-nsd +# handlers file for nsd - name: Restart NSD service: diff --git a/meta/main.yml b/meta/main.yml index 609e4ed853c8ae0da91d790815c63dcbb6360add..6416300f70d86fbc9cf8561c3db3298f33a6b899 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,6 +1,6 @@ galaxy_info: author: Nimrod Adar - description: Install and configure NSD + description: Provision an NSD authorative DNS server company: Shore technologies license: MIT min_ansible_version: 2.0 @@ -12,5 +12,8 @@ galaxy_info: - name: Debian versions: - jessie + - name: Ubuntu + versions: + - xenial galaxy_tags: [ networking, web ] dependencies: [] diff --git a/molecule.yml b/molecule.yml index 5e5bdd1c962dea4611e3ef4c170ada201c561d9a..a186246437b13d95b372ba6d696665ee6e9b259d 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-nsd + - name: nsd 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: nsd-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 229bb3530b65b7d99b0a3ae0fb1b3382210e9366..e01ddecc3bdde982d6f41df89ec0250846afeb5f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,12 @@ --- -# tasks file for ansible-role-nsd +# tasks file for nsd - name: Assertions assert: that: - - ansible_os_family in [ 'Debian', 'OpenBSD' ] + - ansible_os_family in nsd_user + - ansible_os_family in aliases_file + - nsd_config is iterable - name: APT install NSD when: ansible_pkg_mgr == 'apt' diff --git a/tests/playbook.yml b/tests/playbook.yml index bd8a3bc41d39c68cdccfbbba050dac44f0c49cb7..84aceb6b80edfe27654b12441c1ea41e76a43eb9 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,10 +1,16 @@ --- -- hosts: ansible-role-nsd-openbsd +- hosts: nsd-openbsd gather_facts: false - roles: [openbsd_bootstrap] + roles: [openbsd-bootstrap] + +- hosts: nsd-xenial + gather_facts: false + roles: [debian-bootstrap] - hosts: all - roles: [ ansible-role-nsd ] + strategy: free + roles: + - role: nsd post_tasks: - name: Copy test zone with_items: 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_nsd.py b/tests/test_nsd.py index 868465fb77d44425d33e9bccaa8ce5208dda8dde..fe6f6106a6cb92a3f2da84e9639cc748f41eba60 100644 --- a/tests/test_nsd.py +++ b/tests/test_nsd.py @@ -1,3 +1,8 @@ +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') + + def test_nsd(Command, Sudo): with Sudo(): assert Command('nsd -v').rc == 0 diff --git a/vars/main.yml b/vars/main.yml index 0c44b652cbb7366f108369d1eec8192cdbe3fcb0..872791f150f09634e9692538b519df54e3d5c057 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,5 +1,5 @@ --- -# vars file for ansible-role-nsd +# vars file for nsd nsd_conf: '{{ "/var/nsd/etc/nsd.conf" if ansible_os_family == "OpenBSD" else "/etc/nsd/nsd.conf" }}' nsd_conf_d: '{{ nsd_conf }}.d'