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 d108464a57c869d3fc406a1623f19f0164f2d67d..f70d47f057705dd630c03fa93536ca6c865137f0 100644 --- a/README.rst +++ b/README.rst @@ -1,13 +1,15 @@ NTP client ########## -An Ansible role for installing and configuring an NTP client. +.. image:: https://travis-ci.org/adarnimrod/ntp-client.svg?branch=master + :target: https://travis-ci.org/adarnimrod/ntp-client + +Provision an NTP client. 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 -------------- @@ -27,21 +29,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..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 764931eed090419a22dc619c522b38210eebcd8c..acbbcc0c96c5e5a8a5abda45a18cc46da0e66c91 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,2 @@ --- -# defaults file for ansible-role-ntp-client +# defaults file for ntp-client diff --git a/handlers/main.yml b/handlers/main.yml index 721c05cd9d7dfbc6c146cca58e381a2310f70c93..51e09fc1be5180501550085103f27b8196b8bf97 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,5 @@ --- -# handlers file for ansible-role-ntp-client +# handlers file for ntp-client - name: Restart ntpd service: diff --git a/meta/main.yml b/meta/main.yml index b8c0d9f2eef96efedbfab5a8288130f1f735fa38..9e513d068b539612a5ba08af74aec36da3c758a4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,6 +1,6 @@ galaxy_info: author: Nimrod Adar - description: An Ansible role for configuring NTP time syncronization. + description: Provision an NTP client company: Shore technologies license: MIT min_ansible_version: 2.0 diff --git a/molecule.yml b/molecule.yml index 838fd33060da0c7114b639da886a1de4cd6224b8..92aae9fb6bd52e899ce4b3ed92326a12145ba9d9 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,12 +16,10 @@ vagrant: platforms: - name: openbsd box: kaorimatz/openbsd-6.0-amd64 - - name: debian + - name: jessie box: debian/jessie64 - - name: ubuntu - box: ubuntu/xenial64 instances: - - name: ansible-role-ntp-client + - name: ntp-client options: append_platform_to_hostname: yes raw_config_args: @@ -26,3 +27,17 @@ vagrant: - 'vbguest.auto_update = false' - 'landrush.enabled = false' - 'landrush_ip.override = false' + +docker: + containers: + - name: ntp-client-jessie + image: debian + image_version: jessie + 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 b8dc3c36937f5acb4dd386d2277bbd597953dc63..30acc1b7ddaf42e1666131d8f8aa5d31f0836989 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,6 @@ --- -# tasks file for ansible-role-ntp-client +# tasks file for ntp-client + - name: Assertions assert: that: ansible_os_family in [ 'Debian', 'OpenBSD' ] diff --git a/tests/playbook.yml b/tests/playbook.yml index 15092e57cb0ee27e2b4b656dfea467f2d4f8d820..6f9523243bc49fbd73e1c4e3b857c58cbec82152 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,11 +1,13 @@ --- -- hosts: ansible-role-ntp-client-openbsd +- hosts: ntp-client-openbsd gather_facts: false - roles: [openbsd_bootstrap] + roles: [adarnimrod.openbsd-bootstrap] -- hosts: ansible-role-ntp-client-ubuntu +- hosts: ntp-client-xenial gather_facts: false - roles: [debian_bootstrap] + roles: [adarnimrod.debian-bootstrap] - hosts: all - roles: [ansible-role-ntp-client] + strategy: free + roles: + - role: ntp-client diff --git a/tests/requirements.txt b/tests/requirements.txt index 0588c359a06c17f6d8a27f8d19be6cf89b2758b8..70cb7661036d9bd7cc73bfb2f4f8978edce7ea4c 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,6 +1,8 @@ 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.16.1 +ansible-lint==3.4.8 +pre-commit==0.9.4 piprot==0.9.7 +python-vagrant==0.5.14 +docker-py==1.10.6 diff --git a/tests/requirements.yml b/tests/requirements.yml index 8b9b2bcba3b4459621ff239243ac0375a081f20a..cdc294cd67e8c5b70eed5178580e6edde25e10bb 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -1,7 +1,3 @@ --- -- 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 +- src: adarnimrod.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_ntp.py b/tests/test_ntp.py index ffa5d1f0ace956ec5005e5b54d6aa0e44827a936..41a8af87c4b1cce23c43fb303beb58b8395bd72f 100644 --- a/tests/test_ntp.py +++ b/tests/test_ntp.py @@ -1,12 +1,12 @@ -def test_ntp(Service, Ansible): - if Ansible('setup')['ansible_facts']['ansible_service_mgr'] == 'systemd': - service = Service('systemd-timesyncd') - elif Ansible('setup')['ansible_facts']['ansible_os_family'] == 'Debian': - service = Service('openntpd') - elif Ansible('setup')['ansible_facts']['ansible_os_family'] == 'OpenBSD': - service = Service('ntpd') - assert service.is_running +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') + + +def test_ntp(Service): + assert Service('systemd-timesyncd').is_running or Service( + 'ntpd').is_running try: - assert service.is_enabled + Service('systemd-timesyncd').is_enabled or Service('ntpd').is_enabled except NotImplementedError: pass diff --git a/vars/main.yml b/vars/main.yml index 7bbd5f201a5633dfd015863c7b3dab2b5b4995f0..87c6647d0eab23322f4e372ad34187540bd1de5b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,5 +1,5 @@ --- -# vars file for ansible-role-ntp-client +# vars file for ntp-client ntpd_conf: OpenBSD: /etc/ntpd.conf