Skip to content

Commit

Permalink
Adding a vagrant scenario.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdebock committed Nov 4, 2018
1 parent 670f23e commit b29b09d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
26 changes: 26 additions & 0 deletions molecule/vagrant/molecule.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
dependency:
name: galaxy
options:
role-file: requirements.yml
driver:
name: vagrant
provider:
name: virtualbox
lint:
name: yamllint
platforms:
- name: {{ role_name }}-debian
box: debian/stretch64
- name: {{ role_name }}-fedora
box: fedora/28-cloud-base
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: vagrant
verifier:
name: goss
lint:
name: yamllint
9 changes: 9 additions & 0 deletions molecule/vagrant/playbook.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
become: true
gather_facts: false

roles:
- robertdebock.bootstrap
- ansible-role-{{ role_name }}
8 changes: 8 additions & 0 deletions molecule/vagrant/tests/test_default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Molecule managed

---
file:
/etc/hosts:
exists: true
owner: root
group: root
53 changes: 53 additions & 0 deletions molecule/vagrant/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# This is an example playbook to execute goss tests.
# Tests need distributed to the appropriate ansible host/groups
# prior to execution by `goss validate`.

- name: Verify
hosts: all
become: true
vars:
goss_version: v0.3.6
goss_arch: amd64
goss_dst: /usr/local/bin/goss
goss_sha256sum: 53dd1156ab66f2c4275fd847372e6329d895cfb2f0bcbec5f86c1c4df7236dde
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
goss_test_directory: /tmp
goss_format: documentation
tasks:
- name: Download and install Goss
get_url:
url: "{{ goss_url }}"
dest: "{{ goss_dst }}"
sha256sum: "{{ goss_sha256sum }}"
mode: 0755
register: download_goss
until: download_goss is succeeded
retries: 3

- name: Copy Goss tests to remote
copy:
src: "{{ item }}"
dest: "{{ goss_test_directory }}/{{ item | basename }}"
with_fileglob:
- "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml"

- name: Register test files
shell: "ls {{ goss_test_directory }}/test_*.yml"
register: test_files

- name: Execute Goss tests
command: "{{ goss_dst }} -g {{ item }} validate --format {{ goss_format }}"
register: test_results
with_items: "{{ test_files.stdout_lines }}"

- name: Display details about the Goss results
debug:
msg: "{{ item.stdout_lines }}"
with_items: "{{ test_results.results }}"

- name: Fail when tests fail
fail:
msg: "Goss failed to validate"
when: item.rc != 0
with_items: "{{ test_results.results }}"

0 comments on commit b29b09d

Please sign in to comment.