mirror of
https://github.com/geerlingguy/ansible-role-certbot.git
synced 2025-04-19 17:01:37 +02:00
Switch tests to use Molecule.
This commit is contained in:
parent
3f1a802d71
commit
e14d6eb04a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*.retry
|
*.retry
|
||||||
tests/test.sh
|
*/__pycache__
|
||||||
|
*.pyc
|
||||||
|
36
.travis.yml
36
.travis.yml
@ -1,23 +1,33 @@
|
|||||||
---
|
---
|
||||||
|
language: python
|
||||||
services: docker
|
services: docker
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- distro: centos7
|
global:
|
||||||
- distro: centos6
|
- ROLE_NAME: certbot
|
||||||
playbook: test-source-install.yml
|
matrix:
|
||||||
- distro: ubuntu1604
|
- MOLECULE_DISTRO: centos7
|
||||||
- distro: ubuntu1404
|
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
|
||||||
playbook: test-source-install.yml
|
- MOLECULE_DISTRO: centos6
|
||||||
- distro: debian8
|
MOLECULE_PLAYBOOK: playbook-source-install.yml
|
||||||
playbook: test-source-install.yml
|
- MOLECULE_DISTRO: ubuntu1604
|
||||||
|
- MOLECULE_DISTRO: ubuntu1404
|
||||||
|
MOLECULE_PLAYBOOK: playbook-source-install.yml
|
||||||
|
- MOLECULE_DISTRO: debian9
|
||||||
|
|
||||||
|
install:
|
||||||
|
# Install test dependencies.
|
||||||
|
- pip install molecule docker
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
# Use actual Ansible Galaxy role name for the project directory.
|
||||||
|
- cd ../
|
||||||
|
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
|
||||||
|
- cd geerlingguy.$ROLE_NAME
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# Download test shim.
|
|
||||||
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
|
|
||||||
- chmod +x ${PWD}/tests/test.sh
|
|
||||||
|
|
||||||
# Run tests.
|
# Run tests.
|
||||||
- ${PWD}/tests/test.sh
|
- molecule test
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
27
molecule/default/molecule.yml
Normal file
27
molecule/default/molecule.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint:
|
||||||
|
name: yamllint
|
||||||
|
options:
|
||||||
|
config-file: molecule/default/yaml-lint.yml
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible
|
||||||
|
command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
lint:
|
||||||
|
name: ansible-lint
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
|
||||||
|
scenario:
|
||||||
|
name: default
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
||||||
|
lint:
|
||||||
|
name: flake8
|
@ -1,8 +1,10 @@
|
|||||||
---
|
---
|
||||||
- hosts: all
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
certbot_install_from_source: yes
|
certbot_install_from_source: true
|
||||||
|
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- name: Update apt cache.
|
- name: Update apt cache.
|
||||||
@ -20,4 +22,4 @@
|
|||||||
|
|
||||||
roles:
|
roles:
|
||||||
- geerlingguy.git
|
- geerlingguy.git
|
||||||
- role_under_test
|
- geerlingguy.certbot
|
@ -1,5 +1,7 @@
|
|||||||
---
|
---
|
||||||
- hosts: all
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- name: Update apt cache.
|
- name: Update apt cache.
|
||||||
@ -19,4 +21,4 @@
|
|||||||
when: ansible_os_family == 'Debian'
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- role_under_test
|
- geerlingguy.certbot
|
14
molecule/default/tests/test_default.py
Normal file
14
molecule/default/tests/test_default.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
|
def test_hosts_file(host):
|
||||||
|
f = host.file('/etc/hosts')
|
||||||
|
|
||||||
|
assert f.exists
|
||||||
|
assert f.user == 'root'
|
||||||
|
assert f.group == 'root'
|
6
molecule/default/yaml-lint.yml
Normal file
6
molecule/default/yaml-lint.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 120
|
||||||
|
level: warning
|
@ -1,11 +0,0 @@
|
|||||||
# Ansible Role tests
|
|
||||||
|
|
||||||
To run the test playbook(s) in this directory:
|
|
||||||
|
|
||||||
1. Install and start Docker.
|
|
||||||
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
|
|
||||||
- `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
|
|
||||||
1. Make the test shim executable: `chmod +x tests/test.sh`.
|
|
||||||
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`
|
|
||||||
|
|
||||||
If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`
|
|
Loading…
x
Reference in New Issue
Block a user