From 3e1b0473cc59ebf4cddcfacf3e744ac9ae966b0e Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Thu, 30 Aug 2018 23:34:04 +0200 Subject: [PATCH] Initial molecule WIP --- .yamllint | 12 ++ molecule/README.md | 90 ++++++++ molecule/clients/Dockerfile.j2 | 1 + molecule/clients/INSTALL.rst | 26 +++ molecule/clients/molecule.yml | 96 +++++++++ molecule/clients/playbook.yml | 1 + molecule/clients/prepare.yml | 1 + molecule/clients/restore.sh.j2 | 1 + molecule/clients/side_effect.yml | 1 + molecule/clients/tests/test_all.yml | 1 + molecule/clients/tests/test_client.yml | 1 + .../clients/tests/test_client_restore.yml | 1 + molecule/clients/tests/test_server.yml | 1 + molecule/clients/verify.yml | 154 ++++++++++++++ molecule/commands/Dockerfile.j2 | 1 + molecule/commands/INSTALL.rst | 26 +++ molecule/commands/molecule.yml | 51 +++++ molecule/commands/playbook.yml | 1 + molecule/commands/prepare.yml | 1 + molecule/commands/restore.sh.j2 | 1 + molecule/commands/side_effect.yml | 1 + molecule/commands/tests/test_all.yml | 1 + molecule/commands/tests/test_client.yml | 1 + .../commands/tests/test_client_commands.yml | 19 ++ .../commands/tests/test_client_restore.yml | 1 + molecule/commands/tests/test_server.yml | 1 + molecule/commands/verify.yml | 151 +++++++++++++ molecule/folders/Dockerfile.j2 | 1 + molecule/folders/INSTALL.rst | 26 +++ molecule/folders/molecule.yml | 50 +++++ molecule/folders/playbook.yml | 1 + molecule/folders/prepare.yml | 1 + molecule/folders/restore.sh.j2 | 1 + molecule/folders/side_effect.yml | 1 + molecule/folders/tests/test_all.yml | 1 + molecule/folders/tests/test_client.yml | 1 + .../folders/tests/test_client_folders.yml | 11 + .../folders/tests/test_client_restore.yml | 1 + molecule/folders/tests/test_server.yml | 1 + molecule/folders/verify.yml | 151 +++++++++++++ molecule/generic_files/Dockerfile.j2 | 14 ++ molecule/generic_files/playbook.yml | 5 + molecule/generic_files/prepare.yml | 23 ++ molecule/generic_files/restore.sh.j2 | 1 + molecule/generic_files/tests/test_all.yml | 9 + molecule/generic_files/tests/test_client.yml | 38 ++++ .../tests/test_client_restore.yml | 18 ++ molecule/generic_files/tests/test_server.yml | 28 +++ molecule/lamp/Dockerfile.j2 | 1 + molecule/lamp/INSTALL.rst | 26 +++ molecule/lamp/molecule.yml | 44 ++++ molecule/lamp/playbook.yml | 1 + molecule/lamp/prepare.yml | 1 + molecule/lamp/restore.sh.j2 | 1 + molecule/lamp/side_effect.yml | 1 + molecule/lamp/tests/test_all.yml | 1 + molecule/lamp/tests/test_client.yml | 1 + molecule/lamp/tests/test_client_restore.yml | 1 + molecule/lamp/tests/test_lamp.yml | 17 ++ molecule/lamp/tests/test_server.yml | 1 + molecule/lamp/verify.yml | 200 ++++++++++++++++++ molecule/mgt/Dockerfile.j2 | 1 + molecule/mgt/INSTALL.rst | 26 +++ molecule/mgt/molecule.yml | 76 +++++++ molecule/mgt/playbook.yml | 1 + molecule/mgt/prepare.yml | 1 + molecule/mgt/restore.sh.j2 | 1 + molecule/mgt/side_effect.yml | 1 + molecule/mgt/tests/test_all.yml | 1 + molecule/mgt/tests/test_client.yml | 1 + molecule/mgt/tests/test_client_restore.yml | 1 + molecule/mgt/tests/test_mgt.yml | 16 ++ molecule/mgt/tests/test_server.yml | 1 + molecule/mgt/verify.yml | 200 ++++++++++++++++++ molecule/multiple/Dockerfile.j2 | 1 + molecule/multiple/INSTALL.rst | 26 +++ molecule/multiple/molecule.yml | 69 ++++++ molecule/multiple/playbook.yml | 1 + molecule/multiple/prepare.yml | 1 + molecule/multiple/restore.sh.j2 | 1 + molecule/multiple/side_effect.yml | 1 + molecule/multiple/tests/test_all.yml | 1 + molecule/multiple/tests/test_client.yml | 1 + .../multiple/tests/test_client_restore.yml | 1 + molecule/multiple/tests/test_server.yml | 1 + molecule/multiple/verify.yml | 151 +++++++++++++ 86 files changed, 1904 insertions(+) create mode 100644 .yamllint create mode 100644 molecule/README.md create mode 120000 molecule/clients/Dockerfile.j2 create mode 100644 molecule/clients/INSTALL.rst create mode 100644 molecule/clients/molecule.yml create mode 120000 molecule/clients/playbook.yml create mode 120000 molecule/clients/prepare.yml create mode 120000 molecule/clients/restore.sh.j2 create mode 120000 molecule/clients/side_effect.yml create mode 120000 molecule/clients/tests/test_all.yml create mode 120000 molecule/clients/tests/test_client.yml create mode 120000 molecule/clients/tests/test_client_restore.yml create mode 120000 molecule/clients/tests/test_server.yml create mode 100644 molecule/clients/verify.yml create mode 120000 molecule/commands/Dockerfile.j2 create mode 100644 molecule/commands/INSTALL.rst create mode 100644 molecule/commands/molecule.yml create mode 120000 molecule/commands/playbook.yml create mode 120000 molecule/commands/prepare.yml create mode 120000 molecule/commands/restore.sh.j2 create mode 120000 molecule/commands/side_effect.yml create mode 120000 molecule/commands/tests/test_all.yml create mode 120000 molecule/commands/tests/test_client.yml create mode 100644 molecule/commands/tests/test_client_commands.yml create mode 120000 molecule/commands/tests/test_client_restore.yml create mode 120000 molecule/commands/tests/test_server.yml create mode 100644 molecule/commands/verify.yml create mode 120000 molecule/folders/Dockerfile.j2 create mode 100644 molecule/folders/INSTALL.rst create mode 100644 molecule/folders/molecule.yml create mode 120000 molecule/folders/playbook.yml create mode 120000 molecule/folders/prepare.yml create mode 120000 molecule/folders/restore.sh.j2 create mode 120000 molecule/folders/side_effect.yml create mode 120000 molecule/folders/tests/test_all.yml create mode 120000 molecule/folders/tests/test_client.yml create mode 100644 molecule/folders/tests/test_client_folders.yml create mode 120000 molecule/folders/tests/test_client_restore.yml create mode 120000 molecule/folders/tests/test_server.yml create mode 100644 molecule/folders/verify.yml create mode 100644 molecule/generic_files/Dockerfile.j2 create mode 100644 molecule/generic_files/playbook.yml create mode 100644 molecule/generic_files/prepare.yml create mode 120000 molecule/generic_files/restore.sh.j2 create mode 100644 molecule/generic_files/tests/test_all.yml create mode 100644 molecule/generic_files/tests/test_client.yml create mode 100644 molecule/generic_files/tests/test_client_restore.yml create mode 100644 molecule/generic_files/tests/test_server.yml create mode 120000 molecule/lamp/Dockerfile.j2 create mode 100644 molecule/lamp/INSTALL.rst create mode 100644 molecule/lamp/molecule.yml create mode 120000 molecule/lamp/playbook.yml create mode 120000 molecule/lamp/prepare.yml create mode 120000 molecule/lamp/restore.sh.j2 create mode 120000 molecule/lamp/side_effect.yml create mode 120000 molecule/lamp/tests/test_all.yml create mode 120000 molecule/lamp/tests/test_client.yml create mode 120000 molecule/lamp/tests/test_client_restore.yml create mode 100644 molecule/lamp/tests/test_lamp.yml create mode 120000 molecule/lamp/tests/test_server.yml create mode 100644 molecule/lamp/verify.yml create mode 120000 molecule/mgt/Dockerfile.j2 create mode 100644 molecule/mgt/INSTALL.rst create mode 100644 molecule/mgt/molecule.yml create mode 120000 molecule/mgt/playbook.yml create mode 120000 molecule/mgt/prepare.yml create mode 120000 molecule/mgt/restore.sh.j2 create mode 120000 molecule/mgt/side_effect.yml create mode 120000 molecule/mgt/tests/test_all.yml create mode 120000 molecule/mgt/tests/test_client.yml create mode 120000 molecule/mgt/tests/test_client_restore.yml create mode 100644 molecule/mgt/tests/test_mgt.yml create mode 120000 molecule/mgt/tests/test_server.yml create mode 100644 molecule/mgt/verify.yml create mode 120000 molecule/multiple/Dockerfile.j2 create mode 100644 molecule/multiple/INSTALL.rst create mode 100644 molecule/multiple/molecule.yml create mode 120000 molecule/multiple/playbook.yml create mode 120000 molecule/multiple/prepare.yml create mode 120000 molecule/multiple/restore.sh.j2 create mode 120000 molecule/multiple/side_effect.yml create mode 120000 molecule/multiple/tests/test_all.yml create mode 120000 molecule/multiple/tests/test_client.yml create mode 120000 molecule/multiple/tests/test_client_restore.yml create mode 120000 molecule/multiple/tests/test_server.yml create mode 100644 molecule/multiple/verify.yml diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..e8b5eb7 --- /dev/null +++ b/.yamllint @@ -0,0 +1,12 @@ +extends: default + +ignore: | + *test_client.yml + *test_client_restore.yml + *test_server.yml + *test_mgt.yml + +rules: + line-length: + max: 1024 + level: warning diff --git a/molecule/README.md b/molecule/README.md new file mode 100644 index 0000000..2432cd1 --- /dev/null +++ b/molecule/README.md @@ -0,0 +1,90 @@ +# Borg backup role - Molecule testing + +Requirements: + + +Ansible 2.4 or higher +Molecule 2.17.0 or higher + +Docker host (local or remote through shell environment) + +## Available tests + +All scenarios run the same tests by default defined in generic_tests + +### all + +Verify the borg-binary is present + +### client + +Verifies if all the required parameters are present on the client to perform a backup. It verifies an already existing backup has run and if it has succeeded. + +### server + +Verifies if all server-related configurations are in place and if the backup is working from a server perspective. + + +## Available test-scenarios + +### clients + +This tests spins up supported platforms and verifies the basic functionality of both server and client with the generic_tests. + +``` +borgbackup_appendonly: +borgbackup_servers: +borgbackup_include: +borgbackup_passphrase: +``` + +### commands + +Verify if both pre and post commands are configured at backup time and are run. + +``` +borgbackup_pre_commands: +borgbackup_post_commands: +``` + +### folders + +Verify if both inclusion and exclusion of folders is working as expected + +``` +borgbackup_include: +borgbackup_exclude: +``` + +### lamp + +Verify a basic lamp setup meaning making sure /var/www/ and automysqlbackup is configured properly and backed up. +As an extra preparation, apache2 and automysqlbackup are installed for verification. + + +``` +backup_pre_commands: needs to be extended with automysqlbackup +borgbackup_include: need to contain both /var/www and /var/lib/automysqlbackup +``` + +### multiple + +Testing whether backing up to multiple targets works properly. + +``` +borgbackup_servers: +``` + +### mgt + +Testing whether the management-station functionality works + +``` +borgbackup_management: +borgbackup_management_user: +borgbackup_management_sshkey: +``` + +### restore + + diff --git a/molecule/clients/Dockerfile.j2 b/molecule/clients/Dockerfile.j2 new file mode 120000 index 0000000..0373a45 --- /dev/null +++ b/molecule/clients/Dockerfile.j2 @@ -0,0 +1 @@ +../generic_files/Dockerfile.j2 \ No newline at end of file diff --git a/molecule/clients/INSTALL.rst b/molecule/clients/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/clients/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/clients/molecule.yml b/molecule/clients/molecule.yml new file mode 100644 index 0000000..7fb7b9c --- /dev/null +++ b/molecule/clients/molecule.yml @@ -0,0 +1,96 @@ +--- +driver: + name: docker +lint: + name: yamllint +platforms: + - name: ${MOLECULE_SCENARIO_NAME}-cub + hostname: ${MOLECULE_SCENARIO_NAME}-cub + image: ubuntu:bionic + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cux + hostname: ${MOLECULE_SCENARIO_NAME}-cux + image: ubuntu:xenial + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cut + hostname: ${MOLECULE_SCENARIO_NAME}-cut + image: ubuntu:trusty + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cds + hostname: ${MOLECULE_SCENARIO_NAME}-cds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cdj + hostname: ${MOLECULE_SCENARIO_NAME}-cdj + image: debian:jessie + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cdw + hostname: ${MOLECULE_SCENARIO_NAME}-cdw + image: debian:wheezy + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cc7 + hostname: ${MOLECULE_SCENARIO_NAME}-cc7 + image: centos:7 + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cc6 + hostname: ${MOLECULE_SCENARIO_NAME}-cc6 + image: centos:6 + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-sds + hostname: ${MOLECULE_SCENARIO_NAME}-sds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_servers +provisioner: + name: ansible + inventory: + group_vars: + all: + borgbackup_appendonly: true + borgbackup_servers: + - fqdn: ${MOLECULE_SCENARIO_NAME}-sds + user: borgds + type: normal + home: /var/backup/ + pool: repos + options: "" + borgbackup_include: + - "/etc" + - "/root" + - "/var/log" + - "/home" + host_vars: + ${MOLECULE_SCENARIO_NAME}-cub: + borgbackup_passphrase: soo6Uabiex + ${MOLECULE_SCENARIO_NAME}-cux: + borgbackup_passphrase: ooFeila1ie + ${MOLECULE_SCENARIO_NAME}-cut: + borgbackup_passphrase: oisjflqohu + ${MOLECULE_SCENARIO_NAME}-cds: + borgbackup_passphrase: eewoo7paf6J + ${MOLECULE_SCENARIO_NAME}-cdj: + borgbackup_passphrase: aef1Iekahpi + ${MOLECULE_SCENARIO_NAME}-cdw: + borgbackup_passphrase: ReiTul4asei + ${MOLECULE_SCENARIO_NAME}-cc7: + borgbackup_passphrase: ASFQiejwasd + ${MOLECULE_SCENARIO_NAME}-cc6: + borgbackup_passphrase: Ansdkfqooia + lint: + name: ansible-lint +scenario: + name: clients +verifier: + name: goss + lint: + name: yamllint diff --git a/molecule/clients/playbook.yml b/molecule/clients/playbook.yml new file mode 120000 index 0000000..ace0a3d --- /dev/null +++ b/molecule/clients/playbook.yml @@ -0,0 +1 @@ +../generic_files/playbook.yml \ No newline at end of file diff --git a/molecule/clients/prepare.yml b/molecule/clients/prepare.yml new file mode 120000 index 0000000..28e9479 --- /dev/null +++ b/molecule/clients/prepare.yml @@ -0,0 +1 @@ +../generic_files/prepare.yml \ No newline at end of file diff --git a/molecule/clients/restore.sh.j2 b/molecule/clients/restore.sh.j2 new file mode 120000 index 0000000..07356a7 --- /dev/null +++ b/molecule/clients/restore.sh.j2 @@ -0,0 +1 @@ +../generic_files/restore.sh.j2 \ No newline at end of file diff --git a/molecule/clients/side_effect.yml b/molecule/clients/side_effect.yml new file mode 120000 index 0000000..589163f --- /dev/null +++ b/molecule/clients/side_effect.yml @@ -0,0 +1 @@ +../restore/side_effect.yml \ No newline at end of file diff --git a/molecule/clients/tests/test_all.yml b/molecule/clients/tests/test_all.yml new file mode 120000 index 0000000..50b87ac --- /dev/null +++ b/molecule/clients/tests/test_all.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_all.yml \ No newline at end of file diff --git a/molecule/clients/tests/test_client.yml b/molecule/clients/tests/test_client.yml new file mode 120000 index 0000000..865fba3 --- /dev/null +++ b/molecule/clients/tests/test_client.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client.yml \ No newline at end of file diff --git a/molecule/clients/tests/test_client_restore.yml b/molecule/clients/tests/test_client_restore.yml new file mode 120000 index 0000000..01a0351 --- /dev/null +++ b/molecule/clients/tests/test_client_restore.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client_restore.yml \ No newline at end of file diff --git a/molecule/clients/tests/test_server.yml b/molecule/clients/tests/test_server.yml new file mode 120000 index 0000000..1c4e7c6 --- /dev/null +++ b/molecule/clients/tests/test_server.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/clients/verify.yml b/molecule/clients/verify.yml new file mode 100644 index 0000000..cdc44c2 --- /dev/null +++ b/molecule/clients/verify.yml @@ -0,0 +1,154 @@ +--- +# 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 all + hosts: all + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" + goss_test_directory: /tmp + goss_format: documentation + molecule_scenario_name: clients + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_all.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_all.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 }}" + +- name: Verify clients + hosts: all:!borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" + goss_test_directory: /tmp + goss_format: documentation + molecule_scenario_name: clients + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_client*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_client*.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 }}" + +- name: Verify backup servers + hosts: borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" + goss_test_directory: /tmp + goss_format: documentation + molecule_scenario_name: clients + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_server*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_server*.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/molecule/commands/Dockerfile.j2 b/molecule/commands/Dockerfile.j2 new file mode 120000 index 0000000..0373a45 --- /dev/null +++ b/molecule/commands/Dockerfile.j2 @@ -0,0 +1 @@ +../generic_files/Dockerfile.j2 \ No newline at end of file diff --git a/molecule/commands/INSTALL.rst b/molecule/commands/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/commands/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/commands/molecule.yml b/molecule/commands/molecule.yml new file mode 100644 index 0000000..8adb38e --- /dev/null +++ b/molecule/commands/molecule.yml @@ -0,0 +1,51 @@ +--- +driver: + name: docker +lint: + name: yamllint +platforms: + - name: ${MOLECULE_SCENARIO_NAME}-cds + hostname: ${MOLECULE_SCENARIO_NAME}-cds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-sds + hostname: ${MOLECULE_SCENARIO_NAME}-sds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_servers +provisioner: + name: ansible + inventory: + group_vars: + all: + borgbackup_appendonly: true + borgbackup_servers: + - fqdn: ${MOLECULE_SCENARIO_NAME}-sds + user: borgds + type: normal + home: /var/backup/ + pool: repos + options: "" + borgbackup_include: + - "/etc" + - "/root" + - "/var/log" + - "/home" + host_vars: + ${MOLECULE_SCENARIO_NAME}-cds: + borgbackup_passphrase: soo6Uabiex + borgbackup_pre_commands: + - "touch /var/log/pre_command" + borgbackup_post_commands: + - "touch /var/log/post_command" + lint: + name: ansible-lint +scenario: + name: commands +verifier: + name: goss + lint: + name: yamllint diff --git a/molecule/commands/playbook.yml b/molecule/commands/playbook.yml new file mode 120000 index 0000000..ace0a3d --- /dev/null +++ b/molecule/commands/playbook.yml @@ -0,0 +1 @@ +../generic_files/playbook.yml \ No newline at end of file diff --git a/molecule/commands/prepare.yml b/molecule/commands/prepare.yml new file mode 120000 index 0000000..28e9479 --- /dev/null +++ b/molecule/commands/prepare.yml @@ -0,0 +1 @@ +../generic_files/prepare.yml \ No newline at end of file diff --git a/molecule/commands/restore.sh.j2 b/molecule/commands/restore.sh.j2 new file mode 120000 index 0000000..07356a7 --- /dev/null +++ b/molecule/commands/restore.sh.j2 @@ -0,0 +1 @@ +../generic_files/restore.sh.j2 \ No newline at end of file diff --git a/molecule/commands/side_effect.yml b/molecule/commands/side_effect.yml new file mode 120000 index 0000000..589163f --- /dev/null +++ b/molecule/commands/side_effect.yml @@ -0,0 +1 @@ +../restore/side_effect.yml \ No newline at end of file diff --git a/molecule/commands/tests/test_all.yml b/molecule/commands/tests/test_all.yml new file mode 120000 index 0000000..50b87ac --- /dev/null +++ b/molecule/commands/tests/test_all.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_all.yml \ No newline at end of file diff --git a/molecule/commands/tests/test_client.yml b/molecule/commands/tests/test_client.yml new file mode 120000 index 0000000..865fba3 --- /dev/null +++ b/molecule/commands/tests/test_client.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client.yml \ No newline at end of file diff --git a/molecule/commands/tests/test_client_commands.yml b/molecule/commands/tests/test_client_commands.yml new file mode 100644 index 0000000..5667f74 --- /dev/null +++ b/molecule/commands/tests/test_client_commands.yml @@ -0,0 +1,19 @@ +# Molecule managed + +--- +file: + /var/log/post_command: + exists: true + owner: root + group: root + /var/log/pre_command: + exists: true + owner: root + group: root + /usr/local/bin/borg-backup: + exists: true + owner: root + group: root + contains: + - "/var/log/post_command" + - "/var/log/pre_command" diff --git a/molecule/commands/tests/test_client_restore.yml b/molecule/commands/tests/test_client_restore.yml new file mode 120000 index 0000000..01a0351 --- /dev/null +++ b/molecule/commands/tests/test_client_restore.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client_restore.yml \ No newline at end of file diff --git a/molecule/commands/tests/test_server.yml b/molecule/commands/tests/test_server.yml new file mode 120000 index 0000000..1c4e7c6 --- /dev/null +++ b/molecule/commands/tests/test_server.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/commands/verify.yml b/molecule/commands/verify.yml new file mode 100644 index 0000000..393cd1c --- /dev/null +++ b/molecule/commands/verify.yml @@ -0,0 +1,151 @@ +--- +# 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 all + hosts: all + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_all.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_all.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 }}" + +- name: Verify clients + hosts: all:!borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_client*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_client*.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 }}" + +- name: Verify backup servers + hosts: borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_server*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_server*.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/molecule/folders/Dockerfile.j2 b/molecule/folders/Dockerfile.j2 new file mode 120000 index 0000000..0373a45 --- /dev/null +++ b/molecule/folders/Dockerfile.j2 @@ -0,0 +1 @@ +../generic_files/Dockerfile.j2 \ No newline at end of file diff --git a/molecule/folders/INSTALL.rst b/molecule/folders/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/folders/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/folders/molecule.yml b/molecule/folders/molecule.yml new file mode 100644 index 0000000..0f6369c --- /dev/null +++ b/molecule/folders/molecule.yml @@ -0,0 +1,50 @@ +--- +driver: + name: docker +lint: + name: yamllint +platforms: + - name: ${MOLECULE_SCENARIO_NAME}-cds + hostname: ${MOLECULE_SCENARIO_NAME}-cds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-sds + hostname: ${MOLECULE_SCENARIO_NAME}-sds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_servers +provisioner: + name: ansible + inventory: + group_vars: + all: + borgbackup_appendonly: true + borgbackup_servers: + - fqdn: ${MOLECULE_SCENARIO_NAME}-sds + user: borgds + type: normal + home: /var/backup/ + pool: repos + options: "" + host_vars: + ${MOLECULE_SCENARIO_NAME}-cds: + borgbackup_passphrase: soo6Uabiex + borgbackup_include: + - "/etc" + - "/root" + - "/var/log" + - "/home" + - "/var/cache" + borgbackup_exclude: + - "/var/cache/apt" + lint: + name: ansible-lint +scenario: + name: folders +verifier: + name: goss + lint: + name: yamllint diff --git a/molecule/folders/playbook.yml b/molecule/folders/playbook.yml new file mode 120000 index 0000000..ace0a3d --- /dev/null +++ b/molecule/folders/playbook.yml @@ -0,0 +1 @@ +../generic_files/playbook.yml \ No newline at end of file diff --git a/molecule/folders/prepare.yml b/molecule/folders/prepare.yml new file mode 120000 index 0000000..28e9479 --- /dev/null +++ b/molecule/folders/prepare.yml @@ -0,0 +1 @@ +../generic_files/prepare.yml \ No newline at end of file diff --git a/molecule/folders/restore.sh.j2 b/molecule/folders/restore.sh.j2 new file mode 120000 index 0000000..07356a7 --- /dev/null +++ b/molecule/folders/restore.sh.j2 @@ -0,0 +1 @@ +../generic_files/restore.sh.j2 \ No newline at end of file diff --git a/molecule/folders/side_effect.yml b/molecule/folders/side_effect.yml new file mode 120000 index 0000000..589163f --- /dev/null +++ b/molecule/folders/side_effect.yml @@ -0,0 +1 @@ +../restore/side_effect.yml \ No newline at end of file diff --git a/molecule/folders/tests/test_all.yml b/molecule/folders/tests/test_all.yml new file mode 120000 index 0000000..50b87ac --- /dev/null +++ b/molecule/folders/tests/test_all.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_all.yml \ No newline at end of file diff --git a/molecule/folders/tests/test_client.yml b/molecule/folders/tests/test_client.yml new file mode 120000 index 0000000..865fba3 --- /dev/null +++ b/molecule/folders/tests/test_client.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client.yml \ No newline at end of file diff --git a/molecule/folders/tests/test_client_folders.yml b/molecule/folders/tests/test_client_folders.yml new file mode 100644 index 0000000..4978699 --- /dev/null +++ b/molecule/folders/tests/test_client_folders.yml @@ -0,0 +1,11 @@ +# Molecule managed + +--- +file: + /usr/local/bin/borg-backup: + exists: true + owner: root + group: root + contains: + - "/var/cache" + - "--exclude '/var/cache/apt'" diff --git a/molecule/folders/tests/test_client_restore.yml b/molecule/folders/tests/test_client_restore.yml new file mode 120000 index 0000000..01a0351 --- /dev/null +++ b/molecule/folders/tests/test_client_restore.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client_restore.yml \ No newline at end of file diff --git a/molecule/folders/tests/test_server.yml b/molecule/folders/tests/test_server.yml new file mode 120000 index 0000000..1c4e7c6 --- /dev/null +++ b/molecule/folders/tests/test_server.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/folders/verify.yml b/molecule/folders/verify.yml new file mode 100644 index 0000000..393cd1c --- /dev/null +++ b/molecule/folders/verify.yml @@ -0,0 +1,151 @@ +--- +# 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 all + hosts: all + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_all.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_all.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 }}" + +- name: Verify clients + hosts: all:!borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_client*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_client*.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 }}" + +- name: Verify backup servers + hosts: borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_server*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_server*.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/molecule/generic_files/Dockerfile.j2 b/molecule/generic_files/Dockerfile.j2 new file mode 100644 index 0000000..2a39d9e --- /dev/null +++ b/molecule/generic_files/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates cron iputils-ping openssh-client openssh-server && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash anacron iputils openssh-clients openssh-server && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/generic_files/playbook.yml b/molecule/generic_files/playbook.yml new file mode 100644 index 0000000..9b2e87b --- /dev/null +++ b/molecule/generic_files/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: borgbackup diff --git a/molecule/generic_files/prepare.yml b/molecule/generic_files/prepare.yml new file mode 100644 index 0000000..7bc50f0 --- /dev/null +++ b/molecule/generic_files/prepare.yml @@ -0,0 +1,23 @@ +--- +- name: prepare servers - Debian only + hosts: borgbackup_servers + gather_facts: true + tasks: + - name: start ssh - Debian Server + command: service ssh start +# note: https://forums.docker.com/t/any-simple-and-safe-way-to-start-services-on-centos7-systemd/5695/8 +# needs to be implemented +# - name: start sshd +# command: service sshd start + +- name: prepare lamp + hosts: lamp + tasks: + - name: Install required packages + apt: + name: "{{ item }}" + state: installed + with_items: + - apache2 + - mysql-server + - automysqlbackup diff --git a/molecule/generic_files/restore.sh.j2 b/molecule/generic_files/restore.sh.j2 new file mode 120000 index 0000000..7c4ac9c --- /dev/null +++ b/molecule/generic_files/restore.sh.j2 @@ -0,0 +1 @@ +../restore/restore.sh.j2 \ No newline at end of file diff --git a/molecule/generic_files/tests/test_all.yml b/molecule/generic_files/tests/test_all.yml new file mode 100644 index 0000000..6b73f0c --- /dev/null +++ b/molecule/generic_files/tests/test_all.yml @@ -0,0 +1,9 @@ +# Molecule managed + +--- +file: + /usr/local/bin/borg: + exists: true + owner: root + group: root + mode: "0755" diff --git a/molecule/generic_files/tests/test_client.yml b/molecule/generic_files/tests/test_client.yml new file mode 100644 index 0000000..1d9bf31 --- /dev/null +++ b/molecule/generic_files/tests/test_client.yml @@ -0,0 +1,38 @@ +# Molecule managed + +--- +file: + /var/log/borg-backup.log: + exists: true + owner: root + group: root + contains: + - "Backup succeeded" + /root/.borg.passphrase: + exists: true + owner: root + group: root + contains: + - 'export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"' + /root/.ssh/config: + exists: true + owner: root + group: root + contains: +{% for item in borgbackup_servers %} + - 'ANSIBLE MANAGED BLOCK {{ item.fqdn }}' +{% endfor %} + /usr/local/bin/borg-backup: + exists: true + owner: root + group: root + mode: "0744" + +command: + bash /usr/local/bin/borg-backup list: + exit-status: 0 + stdout: +{% for item in borgbackup_servers %} + - "Archives on {{ item.fqdn }}" +{% endfor %} + - "/[[:digit:]]{8}-[[:digit:]]{4}.*/" diff --git a/molecule/generic_files/tests/test_client_restore.yml b/molecule/generic_files/tests/test_client_restore.yml new file mode 100644 index 0000000..746c0b0 --- /dev/null +++ b/molecule/generic_files/tests/test_client_restore.yml @@ -0,0 +1,18 @@ +--- +file: + /root/sample.txt: + exists: true + +command: +{% for item in borgbackup_servers %} + diff -s /root/sample.txt /root/restore/{{ item.fqdn }}/root/sample.txt: + exit-status: 0 + stdout: + - "Files /root/sample.txt and /root/restore/{{ item.fqdn }}/root/sample.txt are identical" +{% endfor %} + /root/restore.sh verify: + exit-status: 0 + stdout: +{% for item in borgbackup_servers %} + - "verifying on {{ item.fqdn }}" +{% endfor %} diff --git a/molecule/generic_files/tests/test_server.yml b/molecule/generic_files/tests/test_server.yml new file mode 100644 index 0000000..31856d4 --- /dev/null +++ b/molecule/generic_files/tests/test_server.yml @@ -0,0 +1,28 @@ +# Molecule managed + +--- +file: +{% for item in borgbackup_servers %} +{% if item.fqdn == inventory_hostname %} + {{ item.home }}: + exists: true + owner: "{{ item.user }}" + group: "{{ item.user }}" +{% for host in groups.all|difference(groups.borgbackup_servers) %} + {{ item.home }}/repos/{{ host }}: + exists: true +{% endfor %} +{% endif %} +{% endfor %} +{% for item in borgbackup_servers %} +{% if item.fqdn == inventory_hostname %} + {{ item.home }}/.ssh/authorized_keys: + exists: true + owner: "{{ item.user }}" + group: "{{ item.user }}" + contains: +{% for host in groups.all|difference(groups.borgbackup_servers) %} + - "{{ host }};borg serve" +{% endfor %} +{% endif %} +{% endfor %} diff --git a/molecule/lamp/Dockerfile.j2 b/molecule/lamp/Dockerfile.j2 new file mode 120000 index 0000000..0373a45 --- /dev/null +++ b/molecule/lamp/Dockerfile.j2 @@ -0,0 +1 @@ +../generic_files/Dockerfile.j2 \ No newline at end of file diff --git a/molecule/lamp/INSTALL.rst b/molecule/lamp/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/lamp/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/lamp/molecule.yml b/molecule/lamp/molecule.yml new file mode 100644 index 0000000..534ebc0 --- /dev/null +++ b/molecule/lamp/molecule.yml @@ -0,0 +1,44 @@ +--- +driver: + name: docker +lint: + name: yamllint +platforms: + - name: ${MOLECULE_SCENARIO_NAME}-cds + hostname: ${MOLECULE_SCENARIO_NAME}-cds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - lamp + - name: ${MOLECULE_SCENARIO_NAME}-sds + hostname: ${MOLECULE_SCENARIO_NAME}-sds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_servers +provisioner: + name: ansible + inventory: + group_vars: + all: + borgbackup_appendonly: true + borgbackup_servers: + - fqdn: ${MOLECULE_SCENARIO_NAME}-sds + user: borgds + type: normal + home: /var/backup/ + pool: repos + options: "" + host_vars: + ${MOLECULE_SCENARIO_NAME}-cds: + borgbackup_passphrase: soo6Uabiex + lint: + name: ansible-lint +scenario: + name: lamp +verifier: + name: goss + lint: + name: yamllint diff --git a/molecule/lamp/playbook.yml b/molecule/lamp/playbook.yml new file mode 120000 index 0000000..ace0a3d --- /dev/null +++ b/molecule/lamp/playbook.yml @@ -0,0 +1 @@ +../generic_files/playbook.yml \ No newline at end of file diff --git a/molecule/lamp/prepare.yml b/molecule/lamp/prepare.yml new file mode 120000 index 0000000..28e9479 --- /dev/null +++ b/molecule/lamp/prepare.yml @@ -0,0 +1 @@ +../generic_files/prepare.yml \ No newline at end of file diff --git a/molecule/lamp/restore.sh.j2 b/molecule/lamp/restore.sh.j2 new file mode 120000 index 0000000..07356a7 --- /dev/null +++ b/molecule/lamp/restore.sh.j2 @@ -0,0 +1 @@ +../generic_files/restore.sh.j2 \ No newline at end of file diff --git a/molecule/lamp/side_effect.yml b/molecule/lamp/side_effect.yml new file mode 120000 index 0000000..589163f --- /dev/null +++ b/molecule/lamp/side_effect.yml @@ -0,0 +1 @@ +../restore/side_effect.yml \ No newline at end of file diff --git a/molecule/lamp/tests/test_all.yml b/molecule/lamp/tests/test_all.yml new file mode 120000 index 0000000..50b87ac --- /dev/null +++ b/molecule/lamp/tests/test_all.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_all.yml \ No newline at end of file diff --git a/molecule/lamp/tests/test_client.yml b/molecule/lamp/tests/test_client.yml new file mode 120000 index 0000000..865fba3 --- /dev/null +++ b/molecule/lamp/tests/test_client.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client.yml \ No newline at end of file diff --git a/molecule/lamp/tests/test_client_restore.yml b/molecule/lamp/tests/test_client_restore.yml new file mode 120000 index 0000000..01a0351 --- /dev/null +++ b/molecule/lamp/tests/test_client_restore.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client_restore.yml \ No newline at end of file diff --git a/molecule/lamp/tests/test_lamp.yml b/molecule/lamp/tests/test_lamp.yml new file mode 100644 index 0000000..01fbf62 --- /dev/null +++ b/molecule/lamp/tests/test_lamp.yml @@ -0,0 +1,17 @@ +# Molecule managed + +--- +file: + /etc/hosts: + exists: true + owner: root + group: root + /usr/local/bin/borg-backup: + exists: true + owner: root + group: root + contains: + - "automysqlbackup" + - "/var/www" + /var/lib/automysqlbackup/daily: + exists: true diff --git a/molecule/lamp/tests/test_server.yml b/molecule/lamp/tests/test_server.yml new file mode 120000 index 0000000..1c4e7c6 --- /dev/null +++ b/molecule/lamp/tests/test_server.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/lamp/verify.yml b/molecule/lamp/verify.yml new file mode 100644 index 0000000..5342bc0 --- /dev/null +++ b/molecule/lamp/verify.yml @@ -0,0 +1,200 @@ +--- +# 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 all + hosts: all + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_all.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_all.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 }}" + +- name: Verify clients + hosts: all:!borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_client*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_client*.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 }}" + +- name: Verify lamp clients + hosts: lamp + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_lamp*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_lamp*.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 }}" + +- name: Verify backup servers + hosts: borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_server*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_server*.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/molecule/mgt/Dockerfile.j2 b/molecule/mgt/Dockerfile.j2 new file mode 120000 index 0000000..0373a45 --- /dev/null +++ b/molecule/mgt/Dockerfile.j2 @@ -0,0 +1 @@ +../generic_files/Dockerfile.j2 \ No newline at end of file diff --git a/molecule/mgt/INSTALL.rst b/molecule/mgt/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/mgt/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/mgt/molecule.yml b/molecule/mgt/molecule.yml new file mode 100644 index 0000000..bad6774 --- /dev/null +++ b/molecule/mgt/molecule.yml @@ -0,0 +1,76 @@ +--- +driver: + name: docker +lint: + name: yamllint +platforms: + - name: ${MOLECULE_SCENARIO_NAME}-cds + hostname: ${MOLECULE_SCENARIO_NAME}-cds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cub + hostname: ${MOLECULE_SCENARIO_NAME}-cub + image: ubuntu:bionic + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-sds + hostname: ${MOLECULE_SCENARIO_NAME}-sds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_servers + - name: ${MOLECULE_SCENARIO_NAME}-mds + hostname: ${MOLECULE_SCENARIO_NAME}-mds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_management +provisioner: + name: ansible + inventory: + group_vars: + all: + borgbackup_appendonly: true + borgbackup_servers: + - fqdn: ${MOLECULE_SCENARIO_NAME}-sds + user: borgds + type: normal + home: /var/backup/ + pool: repos + options: "" + borgbackup_retention: + hourly: 12 + daily: 7 + weekly: 4 + monthly: 6 + yearly: 1 + borgbackup_include: + - "/etc" + - "/root" + - "/var/log" + - "/home" + borgbackup_management_station: ${MOLECULE_SCENARIO_NAME}-mds + borgbackup_servers: + borgbackup_required: false + borgbackup_management: + borgbackup_management_user: root + borgbackup_management_sshkey: | + ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXM5MuTbKbciopdHP314g0b72O5xaCf+4mt97bLPBwmW8UpOebWMkE+jYKET2B9fiOkyU9aWq+Tx7tfo31avN0nRf/VsxNupLcH605KdYOmw+EPjVDFLRXZb3j0AGDJM9YCd/KrwJlf8Tu4sXq0RhRNmqRBsBMjevpKCioQLzWJ1oCs1TLWxTS4nN7Jwy+Ou2gJEB7jKj907pFiCIPWRU4LLHlwE7DjunBr4THgE2Sj0tWkiYDKKoH++Rm62wVYL0oTLOJrQuqu52FEniPDgTnZwhy7b5MAHF5f2BscBorQxEkToWOVfX14Mzf+HC/arT2IPoE1Iv2XdWoiGiaWnyr + host_vars: + ${MOLECULE_SCENARIO_NAME}-cds: + borgbackup_passphrase: soo6Uabiex + ${MOLECULE_SCENARIO_NAME}-cub: + borgbackup_passphrase: iousheafqj + ${MOLECULE_SCENARIO_NAME}-mds: + borgbackup_passphrase: Zuequei1ro + lint: + name: ansible-lint +scenario: + name: mgt +verifier: + name: goss + lint: + name: yamllint diff --git a/molecule/mgt/playbook.yml b/molecule/mgt/playbook.yml new file mode 120000 index 0000000..ace0a3d --- /dev/null +++ b/molecule/mgt/playbook.yml @@ -0,0 +1 @@ +../generic_files/playbook.yml \ No newline at end of file diff --git a/molecule/mgt/prepare.yml b/molecule/mgt/prepare.yml new file mode 120000 index 0000000..28e9479 --- /dev/null +++ b/molecule/mgt/prepare.yml @@ -0,0 +1 @@ +../generic_files/prepare.yml \ No newline at end of file diff --git a/molecule/mgt/restore.sh.j2 b/molecule/mgt/restore.sh.j2 new file mode 120000 index 0000000..07356a7 --- /dev/null +++ b/molecule/mgt/restore.sh.j2 @@ -0,0 +1 @@ +../generic_files/restore.sh.j2 \ No newline at end of file diff --git a/molecule/mgt/side_effect.yml b/molecule/mgt/side_effect.yml new file mode 120000 index 0000000..589163f --- /dev/null +++ b/molecule/mgt/side_effect.yml @@ -0,0 +1 @@ +../restore/side_effect.yml \ No newline at end of file diff --git a/molecule/mgt/tests/test_all.yml b/molecule/mgt/tests/test_all.yml new file mode 120000 index 0000000..50b87ac --- /dev/null +++ b/molecule/mgt/tests/test_all.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_all.yml \ No newline at end of file diff --git a/molecule/mgt/tests/test_client.yml b/molecule/mgt/tests/test_client.yml new file mode 120000 index 0000000..865fba3 --- /dev/null +++ b/molecule/mgt/tests/test_client.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client.yml \ No newline at end of file diff --git a/molecule/mgt/tests/test_client_restore.yml b/molecule/mgt/tests/test_client_restore.yml new file mode 120000 index 0000000..01a0351 --- /dev/null +++ b/molecule/mgt/tests/test_client_restore.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client_restore.yml \ No newline at end of file diff --git a/molecule/mgt/tests/test_mgt.yml b/molecule/mgt/tests/test_mgt.yml new file mode 100644 index 0000000..ce09c27 --- /dev/null +++ b/molecule/mgt/tests/test_mgt.yml @@ -0,0 +1,16 @@ +# Molecule managed + +--- +file: + /root/prune.sh: + exists: true + owner: root + group: root + mode: "0700" + contains: +{% for host in groups.all|difference(groups.borgbackup_servers) %} + - "Host: {{ host }}" + - "export BORG_PASSPHRASE={{ borgbackup_passphrase }}" + - ":/var/backup/repos/{{ host }}" +{% endfor %} + - "/usr/local/bin/borg prune" diff --git a/molecule/mgt/tests/test_server.yml b/molecule/mgt/tests/test_server.yml new file mode 120000 index 0000000..1c4e7c6 --- /dev/null +++ b/molecule/mgt/tests/test_server.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/mgt/verify.yml b/molecule/mgt/verify.yml new file mode 100644 index 0000000..7ebf8a2 --- /dev/null +++ b/molecule/mgt/verify.yml @@ -0,0 +1,200 @@ +--- +# 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 all + hosts: all + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_all.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_all.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 }}" + +- name: Verify mgt + hosts: borgbackup_management + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_mgt.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_mgt.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 }}" + +- name: Verify clients + hosts: all:!borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_client*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_client*.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 }}" + +- name: Verify backup servers + hosts: borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_server*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_server*.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/molecule/multiple/Dockerfile.j2 b/molecule/multiple/Dockerfile.j2 new file mode 120000 index 0000000..0373a45 --- /dev/null +++ b/molecule/multiple/Dockerfile.j2 @@ -0,0 +1 @@ +../generic_files/Dockerfile.j2 \ No newline at end of file diff --git a/molecule/multiple/INSTALL.rst b/molecule/multiple/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/multiple/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/multiple/molecule.yml b/molecule/multiple/molecule.yml new file mode 100644 index 0000000..959817d --- /dev/null +++ b/molecule/multiple/molecule.yml @@ -0,0 +1,69 @@ +--- +driver: + name: docker +lint: + name: yamllint + options: + config-file: ${MOLECULE_PROJECT_DIRECTORY}/.yamllint +platforms: + - name: ${MOLECULE_SCENARIO_NAME}-cds + hostname: ${MOLECULE_SCENARIO_NAME}-cds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-cub + hostname: ${MOLECULE_SCENARIO_NAME}-cub + image: ubuntu:bionic + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + - name: ${MOLECULE_SCENARIO_NAME}-sds + hostname: ${MOLECULE_SCENARIO_NAME}-sds + image: debian:stretch + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_servers + - name: ${MOLECULE_SCENARIO_NAME}-sub + hostname: ${MOLECULE_SCENARIO_NAME}-sub + image: ubuntu:bionic + networks: + - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - borgbackup_servers +provisioner: + name: ansible + inventory: + group_vars: + all: + borgbackup_appendonly: true + borgbackup_servers: + - fqdn: ${MOLECULE_SCENARIO_NAME}-sds + user: borgdj + type: normal + home: /var/backup/ + pool: repos + options: "" + - fqdn: ${MOLECULE_SCENARIO_NAME}-sub + user: borgux + type: normal + home: /var/backup-jail/ + pool: repos + options: "" + borgbackup_include: + - "/etc" + - "/root" + - "/var/log" + - "/home" + host_vars: + ${MOLECULE_SCENARIO_NAME}-cds: + borgbackup_passphrase: soo6Uabiex + ${MOLECULE_SCENARIO_NAME}-cub: + borgbackup_passphrase: lidafruhkj + lint: + name: ansible-lint +scenario: + name: multiple +verifier: + name: goss + lint: + name: yamllint diff --git a/molecule/multiple/playbook.yml b/molecule/multiple/playbook.yml new file mode 120000 index 0000000..ace0a3d --- /dev/null +++ b/molecule/multiple/playbook.yml @@ -0,0 +1 @@ +../generic_files/playbook.yml \ No newline at end of file diff --git a/molecule/multiple/prepare.yml b/molecule/multiple/prepare.yml new file mode 120000 index 0000000..28e9479 --- /dev/null +++ b/molecule/multiple/prepare.yml @@ -0,0 +1 @@ +../generic_files/prepare.yml \ No newline at end of file diff --git a/molecule/multiple/restore.sh.j2 b/molecule/multiple/restore.sh.j2 new file mode 120000 index 0000000..07356a7 --- /dev/null +++ b/molecule/multiple/restore.sh.j2 @@ -0,0 +1 @@ +../generic_files/restore.sh.j2 \ No newline at end of file diff --git a/molecule/multiple/side_effect.yml b/molecule/multiple/side_effect.yml new file mode 120000 index 0000000..589163f --- /dev/null +++ b/molecule/multiple/side_effect.yml @@ -0,0 +1 @@ +../restore/side_effect.yml \ No newline at end of file diff --git a/molecule/multiple/tests/test_all.yml b/molecule/multiple/tests/test_all.yml new file mode 120000 index 0000000..50b87ac --- /dev/null +++ b/molecule/multiple/tests/test_all.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_all.yml \ No newline at end of file diff --git a/molecule/multiple/tests/test_client.yml b/molecule/multiple/tests/test_client.yml new file mode 120000 index 0000000..865fba3 --- /dev/null +++ b/molecule/multiple/tests/test_client.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client.yml \ No newline at end of file diff --git a/molecule/multiple/tests/test_client_restore.yml b/molecule/multiple/tests/test_client_restore.yml new file mode 120000 index 0000000..01a0351 --- /dev/null +++ b/molecule/multiple/tests/test_client_restore.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_client_restore.yml \ No newline at end of file diff --git a/molecule/multiple/tests/test_server.yml b/molecule/multiple/tests/test_server.yml new file mode 120000 index 0000000..1c4e7c6 --- /dev/null +++ b/molecule/multiple/tests/test_server.yml @@ -0,0 +1 @@ +../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/multiple/verify.yml b/molecule/multiple/verify.yml new file mode 100644 index 0000000..393cd1c --- /dev/null +++ b/molecule/multiple/verify.yml @@ -0,0 +1,151 @@ +--- +# 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 all + hosts: all + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_all.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_all.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 }}" + +- name: Verify clients + hosts: all:!borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_client*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_client*.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 }}" + +- name: Verify backup servers + hosts: borgbackup_servers + become: true + vars: + goss_version: v0.3.2 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec + 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 + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_server*.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_server*.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 }}"