Use Molecule for testing.
This commit is contained in:
parent
3ea3d94286
commit
b8614e06c4
|
@ -0,0 +1,36 @@
|
||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint: |
|
||||||
|
yamllint --config-file molecule/default/yaml-lint.yml .
|
||||||
|
ansible-lint
|
||||||
|
flake8
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian10}-ansible:latest"
|
||||||
|
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
lint: ansible-lint
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
|
||||||
|
scenario:
|
||||||
|
name: default
|
||||||
|
test_sequence:
|
||||||
|
- lint
|
||||||
|
- destroy
|
||||||
|
- syntax
|
||||||
|
- create
|
||||||
|
- converge
|
||||||
|
- idempotence
|
||||||
|
- verify
|
||||||
|
- destroy
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
||||||
|
lint: flake8
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
vars:
|
||||||
|
d: ${VERIFIER_NAME}
|
||||||
|
acme_sh_domains: []
|
||||||
|
roles:
|
||||||
|
- role: cloudflare-acme
|
|
@ -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_motd_file_exist(host):
|
||||||
|
f = host.file('/tmp/acme.sh')
|
||||||
|
assert not f.exists
|
||||||
|
|
||||||
|
# def test_motd_file_work(host):
|
||||||
|
# host.run_test('/etc/profile.d/motd.sh')
|
|
@ -0,0 +1,36 @@
|
||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint: |
|
||||||
|
yamllint --config-file molecule/default/yaml-lint.yml .
|
||||||
|
ansible-lint
|
||||||
|
flake8
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian9}-ansible:latest"
|
||||||
|
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||||
|
privileged: true
|
||||||
|
pre_build_image: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
lint: ansible-lint
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
|
||||||
|
scenario:
|
||||||
|
name: default
|
||||||
|
test_sequence:
|
||||||
|
- lint
|
||||||
|
- destroy
|
||||||
|
- syntax
|
||||||
|
- create
|
||||||
|
- converge
|
||||||
|
- idempotence
|
||||||
|
# - verify
|
||||||
|
- destroy
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
||||||
|
lint: flake8
|
|
@ -1,34 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
- hosts: "all"
|
|
||||||
become: True
|
|
||||||
|
|
||||||
vars:
|
|
||||||
acme_sh_become_user: "test"
|
|
||||||
roles:
|
|
||||||
- "role_under_test"
|
|
||||||
|
|
||||||
pre_tasks:
|
|
||||||
- name: Add test user
|
|
||||||
user:
|
|
||||||
name: "{{ acme_sh_become_user }}"
|
|
||||||
shell: "/bin/bash"
|
|
||||||
|
|
||||||
post_tasks:
|
|
||||||
- name: Ensure acme.sh was cloned
|
|
||||||
command: test -d /usr/local/src/acme.sh
|
|
||||||
register: result_cloned
|
|
||||||
changed_when: result_cloned.rc != 0
|
|
||||||
|
|
||||||
- name: Ensure acme.sh was installed
|
|
||||||
command: ./acme.sh --version
|
|
||||||
args:
|
|
||||||
chdir: "~/.acme.sh"
|
|
||||||
register: result_installed
|
|
||||||
changed_when: result_installed.rc != 0
|
|
||||||
become_user: "{{ acme_sh_become_user }}"
|
|
||||||
|
|
||||||
- name: Ensure certificate installation path exists
|
|
||||||
command: test -d /etc/ssl/ansible
|
|
||||||
register: result_cert_installed_path
|
|
||||||
changed_when: result_cert_installed_path.rc != 0
|
|
Loading…
Reference in New Issue