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 be652881b943192f49cf6aa02f24514e413da719..dfa3e073374435c6caf044fdd959ba65c9a9b524 100644 --- a/README.rst +++ b/README.rst @@ -1,13 +1,15 @@ Unattended upgrades ################### -An Ansible role to configure unattended upgrades on Debian based distros. +.. image:: https://travis-ci.org/adarnimrod/unattended-upgrades.svg?branch=master + :target: https://travis-ci.org/adarnimrod/unattended-upgrades + +Configure unattended upgrades on Debian based distros. 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/meta/main.yml b/meta/main.yml index 276d63af41fc8ce8a9450d03c675681fcbd2d8e9..1feed542023ef7fac5fff0e49b70e36b271ae0e0 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -8,5 +8,9 @@ galaxy_info: - name: Debian versions: - jessie + - name: Ubuntu + versions: + - trusty + - xenial galaxy_tags: [ debian ] dependencies: [] diff --git a/molecule.yml b/molecule.yml index b69c8b9159d1f6a02b71190a7f1a5f79ab694259..0f7154eb71cf86ba98e85bc53b29217443a88536 100644 --- a/molecule.yml +++ b/molecule.yml @@ -5,6 +5,10 @@ ansible: diff: True config_file: ../ansible.cfg +dependency: + name: galaxy + requirements_file: tests/requirements.yml + vagrant: providers: - name: virtualbox @@ -12,6 +16,10 @@ vagrant: platforms: - name: jessie box: debian/jessie64 + - name: xenial + box: ubuntu/xenial64 + - name: trusty + box: ubuntu/trusty64 instances: - name: unattended-upgrades options: @@ -21,3 +29,36 @@ vagrant: - 'vbguest.auto_update = false' - 'landrush.enabled = false' - 'landrush_ip.override = false' + +docker: + containers: + - name: unattended-upgrades-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 + - name: unattended-upgrades-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 + - name: unattended-upgrades-trusty + image: ubuntu-upstart + image_version: trusty + command: /sbin/init + privileged: True + environment: + DEBIAN_FRONTEND: noninteractive + container: docker diff --git a/tasks/main.yml b/tasks/main.yml index fbf2914ddffc04ecb102447b80ab3f12ca13a3da..376beb6721b86762ef63308846852845cfc23fa4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,6 @@ --- # tasks file for unattended-upgrades + - name: Assertions assert: that: ansible_pkg_mgr == 'apt' diff --git a/tests/playbook.yml b/tests/playbook.yml index d3ed5be474660e9d0b1f1c2ebc4c88619077086e..35ac89421290fee94b8499e5bdfa02718868f8a7 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,4 +1,13 @@ --- +- hosts: unattended-upgrades-openbsd + gather_facts: false + roles: [adarnimrod.openbsd-bootstrap] + +- hosts: unattended-upgrades-xenial + gather_facts: false + roles: [adarnimrod.debian-bootstrap] + - hosts: all + strategy: free roles: - role: unattended-upgrades diff --git a/tests/requirements.txt b/tests/requirements.txt index 0588c359a06c17f6d8a27f8d19be6cf89b2758b8..b9dd3357849815f2a92024577fb91a51616cb9da 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.7 +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 ce6bd0d5ecddc519244dd9576a36c7090edae28e..cdc294cd67e8c5b70eed5178580e6edde25e10bb 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -1,7 +1,3 @@ --- -- src: https://www.shore.co.il/git/openbsd-bootstrap - scm: git - name: openbsd_bootstrap -- src: https://www.shore.co.il/git/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'