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..adf68979f3be70a12ea4474358f0c6696601a46a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +--- +language: python +python: "2.7" +dist: trusty +sudo: false +group: beta +services: [docker] + +install: + - pip install -r tests/requirements.txt + - 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/ diff --git a/README.rst b/README.rst index 1af8b8c704ba48aa87cacb5a57a7a9cf622e701e..c2ee62133c1d4113869bd07f10f2e7d0b7823ac0 100644 --- a/README.rst +++ b/README.rst @@ -27,21 +27,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/molecule.yml b/molecule.yml index 2ed891bd68cbd998d1af4cb7ff5dee192c42b18d..6fb3a1a74a871bb59a3dfde60f7e4fd957b1da7c 100644 --- a/molecule.yml +++ b/molecule.yml @@ -4,6 +4,9 @@ ansible: playbook: tests/playbook.yml diff: True config_file: ../ansible.cfg + +dependencies: + name: galaxy requirements_file: tests/requirements.yml vagrant: @@ -30,3 +33,11 @@ vagrant: - 'vbguest.auto_update = false' - 'landrush.enabled = false' - 'landrush_ip.override = false' + +docker: + containers: + - name: ansible-role-example-ubuntu + image: ubuntu + image_version: xenial + environment: + DEBIAN_FRONTEND: noninteractive diff --git a/tests/requirements.txt b/tests/requirements.txt index 0588c359a06c17f6d8a27f8d19be6cf89b2758b8..db304aa969372e2b07281c303b4cef86529b67f9 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 +molecule==1.14.0 ansible-lint==3.4.4 pre-commit==0.9.3 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..2fd4277a79ac54c36daf1dc8d983d8bbdce2732f 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -1,7 +1,7 @@ --- -- src: https://www.shore.co.il/git/ansible-role-openbsd-bootstrap +- src: https://github.com/adarnimrod/ansible-role-openbsd-bootstrap scm: git name: openbsd_bootstrap -- src: https://www.shore.co.il/git/ansible-role-debian-bootstrap +- src: https://github.com/adarnimrod/ansible-role-debian-bootstrap scm: git 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'