diff --git a/molecule.yml b/molecule.yml deleted file mode 100644 index 486107a..0000000 --- a/molecule.yml +++ /dev/null @@ -1,89 +0,0 @@ ---- -molecule: - # directory in CWD to place all temp files, etc. - molecule_dir: .molecule - - # where temporary state will be stored (lives under molecule_dir) - state_file: state - - # name of temporary vagrantfile created during runs (lives under molecule_dir) - vagrantfile_file: vagrantfile - - # directories to ignore when doing trailing whitespace checks on files during verify command - ignore_paths: - - .git - - .vagrant - - .molecule - - # directory to look for goss tests - goss_dir: tests/goss - goss_playbook: verifier.yml - - # directory containing group_vars to use with ansible - group_vars: ../tests/group_vars - - test: - sequence: - - destroy - - syntax - - create - - converge - - idempotence - - verify - -dependency: - name: galaxy - -# ansible related configuration -ansible: - playbook: tests/playbook.yml - -# configuration options for the internal call to vagrant -vagrant: - raw_config_args: - - "hostmanager.enabled = true" - # Enable for debug purpose - #- "hostmanager.manage_host = true" - - "hostmanager.manage_guest = true" - - "hostmanager.ignore_private_ip = false" - - "hostmanager.include_offline = true" - - # molecule's --platform option will look for these names - platforms: - - name: Debian9 - box: debian/stretch64 - - providers: - - name: virtualbox - type: virtualbox - options: - memory: 1024 - cpus: 2 - - instances: - - name: prom2teams.vm - ansible_groups: - - prom2teams - interfaces: - - network_name: private_network - type: static - ip: 172.28.128.10 - auto_config: true - -docker: - containers: - - name: prom2teams.cont - ansible_groups: - - prom2teams - dockerfile: tests/Dockerfile - image: debian9-testinfra - image_version: latest - privileged: True - cap_add: - - SYS_ADMIN - volume_mounts: - - '/sys/fs/cgroup:/sys/fs/cgroup:ro' - command: '/lib/systemd/systemd' - -verifier: - name: goss diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..88d6c5b --- /dev/null +++ b/molecule/default/Dockerfile.j2 @@ -0,0 +1,15 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN mkdir -p /usr/share/man/man1 + +RUN apt-get update && \ + apt-get install -y iproute sudo systemd systemd-sysv python python-setuptools ssh cron locales ca-certificates && \ + apt-get clean + +RUN systemctl mask getty.target diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst new file mode 100644 index 0000000..6a44bde --- /dev/null +++ b/molecule/default/INSTALL.rst @@ -0,0 +1,22 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* Docker Engine + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ pip install 'molecule[docker]' diff --git a/tests/group_vars/prom2teams/main.yml b/molecule/default/group_vars/prom2teams/main.yml similarity index 68% rename from tests/group_vars/prom2teams/main.yml rename to molecule/default/group_vars/prom2teams/main.yml index fbe39ca..d95a445 100644 --- a/tests/group_vars/prom2teams/main.yml +++ b/molecule/default/group_vars/prom2teams/main.yml @@ -1,4 +1,9 @@ --- +prom2teams_user: prom2teams +prom2teams_group: prom2teams +prom2teams_config_folder: /etc/prom2teams +prom2teams_version: 2.4.0 +prom2teams_logs_folder: /var/log/prom2teams prom2teams_required_libs: - python3 diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..2c7201c --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,35 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + options: + config-file: .yamllint +platforms: + - name: prom2teams + groups: + - prom2teams + image: ${MOLECULE_DISTRO:-debian:stretch-slim} + privileged: false + capabilities: + - SYS_ADMIN + volumes: + - '/sys/fs/cgroup:/sys/fs/cgroup:ro' + tmpfs: + - /run + - /run/lock + command: '/lib/systemd/systemd' + stop_signal: 'RTMIN+3' +provisioner: + name: ansible + lint: + name: ansible-lint +scenario: + name: default +verifier: + name: goss + lint: + name: yamllint + enabled: false diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 0000000..d35c024 --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: prom2teams-role diff --git a/tests/goss/specs/prom2teams.yml.j2 b/molecule/default/tests/test_prom2teams.yml similarity index 100% rename from tests/goss/specs/prom2teams.yml.j2 rename to molecule/default/tests/test_prom2teams.yml diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..b541986 --- /dev/null +++ b/molecule/default/verify.yml @@ -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.7 + goss_arch: amd64 + goss_sha256sum: 357f5c7f2e7949b412bce44349cd32ab19eb3947255a8ac805f884cc2c + goss_dst: /usr/local/bin/goss + 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 }}" + mode: 0755 + register: download_goss + until: download_goss is succeeded + retries: 3 + + - name: Copy Goss tests to remote + template: + 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 }}" diff --git a/tests/Dockerfile b/tests/Dockerfile deleted file mode 100644 index 45cf85d..0000000 --- a/tests/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM geerlingguy/docker-debian9-ansible:latest - -# This is to override Testinfra issue with Debian 9 Docker image -RUN touch /tmp/systemd -RUN ln -s /tmp/systemd /sbin/init diff --git a/tests/goss/verifier.yml b/tests/goss/verifier.yml deleted file mode 100644 index e7ee695..0000000 --- a/tests/goss/verifier.yml +++ /dev/null @@ -1,31 +0,0 @@ -- name: Testing prerequisites - hosts: prom2teams - gather_facts: yes - - vars: - goss_version: "v0.3.5" - goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-amd64" - goss_results: goss_results - - vars_files: - - ../../defaults/main.yml - - ../group_vars/prom2teams/main.yml - - tasks: - - name: Download and install Goss - get_url: - url: "{{ goss_url }}" - dest: "/usr/local/bin/goss" - mode: 0755 - - - name: Copy tests to remote - template: - src: "{{ playbook_dir }}/specs/{{ item }}.j2" - dest: "/tmp/{{ item }}" - with_items: - - prom2teams.yml - - - name: Goss tests - command: "goss -g /tmp/{{ item }} validate -format tap" - with_items: - - prom2teams.yml diff --git a/tests/playbook.yml b/tests/playbook.yml deleted file mode 100644 index 29a0b91..0000000 --- a/tests/playbook.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- - -- hosts: prom2teams - roles: - - role: prom2teams_role