From 3e1b0473cc59ebf4cddcfacf3e744ac9ae966b0e Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Thu, 30 Aug 2018 23:34:04 +0200 Subject: [PATCH 01/27] 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 }}" From 01bc64e95cf10b8e714469e4bc2539a83d0b93ed Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Thu, 30 Aug 2018 23:37:26 +0200 Subject: [PATCH 02/27] Styleguide improvements --- backup.yml | 2 +- defaults/main.yml | 6 +++--- meta/main.yml | 18 +++++++++--------- tasks/borg-client.yml | 24 ++++++++++++------------ tasks/main.yml | 3 ++- tasks/management.yml | 10 +++++----- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/backup.yml b/backup.yml index 3a02331..8ec6fae 100644 --- a/backup.yml +++ b/backup.yml @@ -2,7 +2,7 @@ - name: Configure Borg backup hosts: all - become: True + become: true roles: - role: borgbackup diff --git a/defaults/main.yml b/defaults/main.yml index 5a174f7..ac3e6ba 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,5 @@ --- -borgbackup_required: True +borgbackup_required: true borgbackup_client_user: root borgbackup_ssh_key: "~{{ borgbackup_client_user }}/.ssh/id_borg_rsa" @@ -36,8 +36,8 @@ borgbackup_cron_day: "*" borgbackup_cron_hour: "{{ 5|random(seed=inventory_hostname) }}" borgbackup_cron_minute: "{{ 59|random(seed=inventory_hostname) }}" -borgbackup_appendonly: False -borgbackup_appendonly_repoconfig: False +borgbackup_appendonly: false +borgbackup_appendonly_repoconfig: false borgbackup_management_station: '' borgbackup_management_user: '' borgbackup_management_ssh_pubkey: '' diff --git a/meta/main.yml b/meta/main.yml index a79e23f..baaf749 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -5,15 +5,15 @@ galaxy_info: license: MIT min_ansible_version: 1.9 platforms: - - name: EL - versions: - - all - - name: Debian - versions: - - all - - name: Ubuntu - versions: - - all + - name: EL + versions: + - all + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - all galaxy_tags: - borg - borgbackup diff --git a/tasks/borg-client.yml b/tasks/borg-client.yml index d67df3b..ee71a62 100644 --- a/tasks/borg-client.yml +++ b/tasks/borg-client.yml @@ -2,7 +2,7 @@ - name: client | generate ssh key for this machine user: name: "{{ borgbackup_client_user }}" - generate_ssh_key: yes + generate_ssh_key: true ssh_key_bits: 2048 ssh_key_file: "{{ borgbackup_ssh_key }}" ssh_key_type: rsa @@ -10,19 +10,19 @@ - name: client | fetch ssh-key shell: "cat {{ borgbackup_ssh_key }}.pub" register: sshkey - changed_when: False + changed_when: false - name: client | write passphrase lineinfile: dest: "~{{ borgbackup_client_user }}/.borg.passphrase" state: "present" line: 'export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"' - create: "yes" + create: true - name: client | disable strict key checking for backup servers blockinfile: dest: "~{{ borgbackup_client_user }}/.ssh/config" - create: yes + create: true marker: "### {mark} ANSIBLE MANAGED BLOCK {{ item.fqdn }} ###" content: | Host {{ item.fqdn }} @@ -46,7 +46,7 @@ - name: client | get authorized_keys file raw: scp {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys /tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys delegate_to: localhost - become: no + become: false when: item.type in ['rsync.net','hetzner'] with_items: "{{ borgbackup_servers }}" changed_when: false @@ -57,9 +57,9 @@ key: "{{ sshkey.stdout }}" key_options: 'command="cd {{ item.pool }}/{{ inventory_hostname }};/usr/local/bin/borg1 serve {% if borgbackup_appendonly %}--append-only {% endif %} --restrict-to-path {{ item.pool }}/{{ inventory_hostname }}",no-port-forwarding,no-X11-forwarding,no-pty,no-agent-forwarding,no-user-rc' path: "/tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys" - manage_dir: no + manage_dir: false delegate_to: localhost - become: no + become: false when: item.type in ['rsync.net','hetzner'] with_items: "{{ borgbackup_servers }}" register: authkeys @@ -67,7 +67,7 @@ - name: client | upload local authorized_keys to rsync.net / hetzner raw: scp /tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys delegate_to: localhost - become: no + become: false when: item.type in ['rsync.net','hetzner'] and authkeys.changed with_items: "{{ borgbackup_servers }}" @@ -76,7 +76,7 @@ path: /tmp/authkeys-{{ item.type }}-{{ item.fqdn }}-authkeys state: absent delegate_to: localhost - become: no + become: false with_items: "{{ borgbackup_servers }}" when: authkeys.changed changed_when: false @@ -109,12 +109,12 @@ day: "{{ borgbackup_cron_day }}" job: "/usr/local/bin/borg-backup backup" -- name: client | disable automysqlbackup cronjob, it's in our pre-backup-tasks +- name: client | disable automysqlbackup cronjob, it's in our pre-backup-tasks lineinfile: dest: "/etc/cron.daily/automysqlbackup" regexp: "^/usr/sbin/automysqlbackup$" line: "#/usr/sbin/automysqlbackup" state: "present" - backrefs: "yes" - create: "no" + backrefs: true + create: false when: automysql.stat.isdir is defined and automysql.stat.isdir == True diff --git a/tasks/main.yml b/tasks/main.yml index a394037..a09c8a4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,6 +1,7 @@ --- # Due to inverse logic behaviour when searching for an item in an undefined list. -- set_fact: +- name: setting facts + set_fact: borgbackup_servers_group: "{{ groups.borgbackup_servers | default([]) }} " borgbackup_management_group: "{{ groups.borgbackup_management | default([]) }}" diff --git a/tasks/management.yml b/tasks/management.yml index 7f280a0..74a2e2e 100644 --- a/tasks/management.yml +++ b/tasks/management.yml @@ -20,7 +20,7 @@ - name: management | get rsync.net authorized_keys file raw: scp {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys /tmp/rsync.net-{{ item.fqdn }}-authkeys delegate_to: localhost - become: no + become: false when: item.type == 'rsync.net' with_items: "{{ borgbackup_servers }}" changed_when: false @@ -30,9 +30,9 @@ user: "{{ ansible_user_id }}" key: "{{ borgbackup_management_ssh_pubkey }}" path: "/tmp/rsync.net-{{ item.fqdn }}-authkeys" - manage_dir: no + manage_dir: false delegate_to: localhost - become: no + become: false when: item.type == 'rsync.net' with_items: "{{ borgbackup_servers }}" register: authkeys @@ -40,7 +40,7 @@ - name: management | upload local authorized_keys to rsync.net raw: scp /tmp/rsync.net-{{ item.fqdn }}-authkeys {{ item.user }}@{{ item.fqdn }}:.ssh/authorized_keys delegate_to: localhost - become: no + become: false when: item.type == 'rsync.net' and authkeys.changed with_items: "{{ borgbackup_servers }}" @@ -49,7 +49,7 @@ path: /tmp/rsync.net-{{ item.fqdn }}-authkeys state: absent delegate_to: localhost - become: no + become: false with_items: "{{ borgbackup_servers }}" when: authkeys.changed changed_when: false From e1d9aae46edb50d2a98588aea23e369843003537 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Mon, 3 Sep 2018 20:48:47 +0200 Subject: [PATCH 03/27] Fixing restore-test --- molecule/clients/side_effect.yml | 2 +- molecule/commands/side_effect.yml | 2 +- molecule/folders/side_effect.yml | 2 +- molecule/generic_files/restore.sh.j2 | 37 +++++++++++++++++++++++++- molecule/generic_files/side_effect.yml | 17 ++++++++++++ molecule/lamp/side_effect.yml | 2 +- molecule/mgt/side_effect.yml | 2 +- molecule/multiple/side_effect.yml | 2 +- 8 files changed, 59 insertions(+), 7 deletions(-) mode change 120000 => 100644 molecule/generic_files/restore.sh.j2 create mode 100644 molecule/generic_files/side_effect.yml diff --git a/molecule/clients/side_effect.yml b/molecule/clients/side_effect.yml index 589163f..9bfbda0 120000 --- a/molecule/clients/side_effect.yml +++ b/molecule/clients/side_effect.yml @@ -1 +1 @@ -../restore/side_effect.yml \ No newline at end of file +../generic_files/side_effect.yml \ No newline at end of file diff --git a/molecule/commands/side_effect.yml b/molecule/commands/side_effect.yml index 589163f..9bfbda0 120000 --- a/molecule/commands/side_effect.yml +++ b/molecule/commands/side_effect.yml @@ -1 +1 @@ -../restore/side_effect.yml \ No newline at end of file +../generic_files/side_effect.yml \ No newline at end of file diff --git a/molecule/folders/side_effect.yml b/molecule/folders/side_effect.yml index 589163f..9bfbda0 120000 --- a/molecule/folders/side_effect.yml +++ b/molecule/folders/side_effect.yml @@ -1 +1 @@ -../restore/side_effect.yml \ No newline at end of file +../generic_files/side_effect.yml \ No newline at end of file diff --git a/molecule/generic_files/restore.sh.j2 b/molecule/generic_files/restore.sh.j2 deleted file mode 120000 index 7c4ac9c..0000000 --- a/molecule/generic_files/restore.sh.j2 +++ /dev/null @@ -1 +0,0 @@ -../restore/restore.sh.j2 \ No newline at end of file diff --git a/molecule/generic_files/restore.sh.j2 b/molecule/generic_files/restore.sh.j2 new file mode 100644 index 0000000..9367f00 --- /dev/null +++ b/molecule/generic_files/restore.sh.j2 @@ -0,0 +1,36 @@ +#!/bin/sh + +export BORG_PASSPHRASE="{{ borgbackup_passphrase }}" + +last_backup=`/usr/local/bin/borg-backup list | grep '^[0-9]' | awk ' { print $1 } ' | tail -1` + +if [ "$1" = "verify" ] + then +{% for b in borgbackup_servers %} +{% if b.type == 'hetzner' %} + REPOSITORY=ssh://{{ b.user }}@{{ b.fqdn }}:23/./{{ b.home }}{{ b.pool }}/{{ inventory_hostname }} +{% else %} + REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }} +{% endif %} + printf "verifying on {{ b.fqdn }} :\n" + /usr/local/bin/borg extract --list --dry-run $REPOSITORY::$last_backup root/sample.txt +{% endfor %} + exit 0 +fi + +if [ "$1" = "restore" ] + then + file="$2" +{% for b in borgbackup_servers %} +{% if b.type == 'hetzner' %} + REPOSITORY=ssh://{{ b.user }}@{{ b.fqdn }}:23/./{{ b.home }}{{ b.pool }}/{{ inventory_hostname }} +{% else %} + REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ inventory_hostname }} +{% endif %} + rm -rf /root/restore/{{ b.fqdn }} + mkdir -p /root/restore/{{ b.fqdn }} + cd /root/restore/{{ b.fqdn }} + /usr/local/bin/borg extract $REPOSITORY::$last_backup root/sample.txt +{% endfor %} + exit 0 +fi diff --git a/molecule/generic_files/side_effect.yml b/molecule/generic_files/side_effect.yml new file mode 100644 index 0000000..dcf0feb --- /dev/null +++ b/molecule/generic_files/side_effect.yml @@ -0,0 +1,17 @@ +--- +- hosts: all:!borgbackup_servers + gather_facts: false + tasks: + - name: generate random file + command: dd if=/dev/urandom of=/root/sample.txt bs=1M count=4 + args: + creates: /root/sample.txt + - name: template restore test + template: + src: restore.sh.j2 + dest: /root/restore.sh + mode: "0755" + - name: back up + command: /usr/local/bin/borg-backup backup + - name: restore test file + command: /root/restore.sh restore root/sample.txt diff --git a/molecule/lamp/side_effect.yml b/molecule/lamp/side_effect.yml index 589163f..9bfbda0 120000 --- a/molecule/lamp/side_effect.yml +++ b/molecule/lamp/side_effect.yml @@ -1 +1 @@ -../restore/side_effect.yml \ No newline at end of file +../generic_files/side_effect.yml \ No newline at end of file diff --git a/molecule/mgt/side_effect.yml b/molecule/mgt/side_effect.yml index 589163f..9bfbda0 120000 --- a/molecule/mgt/side_effect.yml +++ b/molecule/mgt/side_effect.yml @@ -1 +1 @@ -../restore/side_effect.yml \ No newline at end of file +../generic_files/side_effect.yml \ No newline at end of file diff --git a/molecule/multiple/side_effect.yml b/molecule/multiple/side_effect.yml index 589163f..9bfbda0 120000 --- a/molecule/multiple/side_effect.yml +++ b/molecule/multiple/side_effect.yml @@ -1 +1 @@ -../restore/side_effect.yml \ No newline at end of file +../generic_files/side_effect.yml \ No newline at end of file From e396c028ec528b384c8b8081827bb17fdf74ac87 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Mon, 3 Sep 2018 21:07:45 +0200 Subject: [PATCH 04/27] Setting permissions on repository directory correct --- tasks/borg-server.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tasks/borg-server.yml b/tasks/borg-server.yml index 3a18d12..c6ea5b3 100644 --- a/tasks/borg-server.yml +++ b/tasks/borg-server.yml @@ -9,6 +9,15 @@ with_items: "{{ borgbackup_servers }}" when: item.type == 'normal' +- name: server | set permissions + file: + dest: "{{ item.home }}" + owner: "{{ item.user }}" + group: "{{ item.user }}" + delegate_to: "{{ item.fqdn }}" + with_items: "{{ borgbackup_servers }}" + when: item.type == 'normal' + - name: server | create directories file: path: "{{ item.home}}{{ item.pool }}" From d7a2b04413852eaa065cc304f021546d654c7568 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 21:11:12 +0100 Subject: [PATCH 05/27] Testing travis-ci --- .travis-ci.yml | 13 +++++++++++++ molecule/folders/molecule.yml | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 .travis-ci.yml diff --git a/.travis-ci.yml b/.travis-ci.yml new file mode 100644 index 0000000..bde7d15 --- /dev/null +++ b/.travis-ci.yml @@ -0,0 +1,13 @@ +--- +sudo: required +language: python +services: + - docker +before_install: + - sudo apt-get -qq update +install: + - pip install molecule + - pip install ansible==2.7 + - pip install docker +script: + - molecule test --scenario-name folders diff --git a/molecule/folders/molecule.yml b/molecule/folders/molecule.yml index 0f6369c..f22c8f2 100644 --- a/molecule/folders/molecule.yml +++ b/molecule/folders/molecule.yml @@ -9,6 +9,8 @@ platforms: image: debian:stretch networks: - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - lamp - name: ${MOLECULE_SCENARIO_NAME}-sds hostname: ${MOLECULE_SCENARIO_NAME}-sds image: debian:stretch From eeb4dbecf28a5066f6a770e1b938b86bd4ce3701 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 21:11:53 +0100 Subject: [PATCH 06/27] Stashing commit --- molecule/multiple/molecule.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/molecule/multiple/molecule.yml b/molecule/multiple/molecule.yml index 959817d..a160855 100644 --- a/molecule/multiple/molecule.yml +++ b/molecule/multiple/molecule.yml @@ -18,7 +18,7 @@ platforms: - name: ${MOLECULE_SCENARIO_NAME}-borg - name: ${MOLECULE_SCENARIO_NAME}-sds hostname: ${MOLECULE_SCENARIO_NAME}-sds - image: debian:stretch + image: ubuntu:xenial networks: - name: ${MOLECULE_SCENARIO_NAME}-borg groups: @@ -59,6 +59,8 @@ provisioner: borgbackup_passphrase: soo6Uabiex ${MOLECULE_SCENARIO_NAME}-cub: borgbackup_passphrase: lidafruhkj + ${MOLECULE_SCENARIO_NAME}-sub: + borgbackup_passphrase: oiasdfoain lint: name: ansible-lint scenario: From e6d05ba1b4c996ed761cf23611b3a079b92c1a72 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 21:32:21 +0100 Subject: [PATCH 07/27] Wrong filename --- .travis-ci.yml => .travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis-ci.yml => .travis.yml (100%) diff --git a/.travis-ci.yml b/.travis.yml similarity index 100% rename from .travis-ci.yml rename to .travis.yml From 4e03828a3e60a016c51af3a2275359900bf2d709 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 21:36:45 +0100 Subject: [PATCH 08/27] Test all scenarios --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bde7d15..934205a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,4 @@ install: - pip install ansible==2.7 - pip install docker script: - - molecule test --scenario-name folders + - molecule test --all From 99b87a15571e00e141cd36c43efb2272c2b7d041 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 21:41:51 +0100 Subject: [PATCH 09/27] Showing build-status in README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index da7f5f4..fc7783f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.com/dverhelst/borgbackup.svg?branch=feature/molecule)](https://travis-ci.com/dverhelst/borgbackup) + # Borg backup role This role installs Borg backup on borgbackup\_servers and clients. The role contains a wrapper-script 'borg-backup' to ease the usage on the client. Supported options include borg-backup info | init | list | backup | mount. Automysqlbackup will run as pre-backup command if it's installed. The role supports both self hosted and offsite backup-storage such as rsync.net and hetzner storage box as Borg server. From f55917c6764dad1fd38c234f5eea3f29c338930e Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 22:15:10 +0100 Subject: [PATCH 10/27] Adding centos group for prepare-limiting --- molecule/clients/molecule.yml | 4 ++++ molecule/folders/molecule.yml | 2 -- molecule/generic_files/prepare.yml | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/molecule/clients/molecule.yml b/molecule/clients/molecule.yml index 7fb7b9c..ea756e2 100644 --- a/molecule/clients/molecule.yml +++ b/molecule/clients/molecule.yml @@ -39,11 +39,15 @@ platforms: image: centos:7 networks: - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - centos - name: ${MOLECULE_SCENARIO_NAME}-cc6 hostname: ${MOLECULE_SCENARIO_NAME}-cc6 image: centos:6 networks: - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - centos - name: ${MOLECULE_SCENARIO_NAME}-sds hostname: ${MOLECULE_SCENARIO_NAME}-sds image: debian:stretch diff --git a/molecule/folders/molecule.yml b/molecule/folders/molecule.yml index f22c8f2..0f6369c 100644 --- a/molecule/folders/molecule.yml +++ b/molecule/folders/molecule.yml @@ -9,8 +9,6 @@ platforms: image: debian:stretch networks: - name: ${MOLECULE_SCENARIO_NAME}-borg - groups: - - lamp - name: ${MOLECULE_SCENARIO_NAME}-sds hostname: ${MOLECULE_SCENARIO_NAME}-sds image: debian:stretch diff --git a/molecule/generic_files/prepare.yml b/molecule/generic_files/prepare.yml index 7bc50f0..8682ee8 100644 --- a/molecule/generic_files/prepare.yml +++ b/molecule/generic_files/prepare.yml @@ -10,8 +10,8 @@ # - name: start sshd # command: service sshd start -- name: prepare lamp - hosts: lamp +- name: prepare all + hosts: all:!borgbackup_servers:!centos tasks: - name: Install required packages apt: From 0506e653b69d4f148806e05a73dc8956db546c6c Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 22:49:12 +0100 Subject: [PATCH 11/27] Make sure mysql is started --- molecule/generic_files/prepare.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/molecule/generic_files/prepare.yml b/molecule/generic_files/prepare.yml index 8682ee8..1d5a43b 100644 --- a/molecule/generic_files/prepare.yml +++ b/molecule/generic_files/prepare.yml @@ -15,9 +15,15 @@ tasks: - name: Install required packages apt: - name: "{{ item }}" - state: installed - with_items: - - apache2 - - mysql-server - - automysqlbackup + name: + - apache2 + - mysql-server + - automysqlbackup + state: present + notify: start mysql + handlers: + - name: start mysql + service: + name: mysql + state: started + enabled: yes From 7085d8cd81fa69b7074940e8039f33feaa22d418 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 22:58:30 +0100 Subject: [PATCH 12/27] Wrong truthy falsy --- molecule/generic_files/prepare.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule/generic_files/prepare.yml b/molecule/generic_files/prepare.yml index 1d5a43b..eb8c72c 100644 --- a/molecule/generic_files/prepare.yml +++ b/molecule/generic_files/prepare.yml @@ -26,4 +26,4 @@ service: name: mysql state: started - enabled: yes + enabled: true From 2be8c7717f2dcb348e146197c74aafd4edd0344a Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Sun, 10 Mar 2019 23:08:05 +0100 Subject: [PATCH 13/27] sequential for testing --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 934205a..b30e632 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,9 @@ install: - pip install ansible==2.7 - pip install docker script: - - molecule test --all + - molecule test --scenario-name commands + - molecule test --scenario-name folders + - molecule test --scenario-name lamp + - molecule test --scenario-name mgt + - molecule test --scenario-name multiple + - molecule test --scenario-name clients From b4695d74033e35fceb948d7de9f2d3c9101d8cce Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Mon, 11 Mar 2019 08:13:17 +0100 Subject: [PATCH 14/27] remove old ubuntu trusty and debian wheezy versions for CI --- molecule/clients/molecule.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/molecule/clients/molecule.yml b/molecule/clients/molecule.yml index ea756e2..8af276a 100644 --- a/molecule/clients/molecule.yml +++ b/molecule/clients/molecule.yml @@ -14,11 +14,6 @@ platforms: 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 @@ -29,11 +24,6 @@ platforms: 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 @@ -78,14 +68,10 @@ provisioner: 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: From 97faa7429cd2610696222bcf15f7ffdcf3b40a4f Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 10:33:14 +0100 Subject: [PATCH 15/27] Replace goss tests with testinfra --- .gitignore | 3 + .travis.yml | 2 +- molecule/clients/molecule.yml | 4 +- molecule/clients/tests | 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/molecule.yml | 6 +- molecule/folders/tests | 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/tests/.flake8 | 2 + molecule/generic_files/tests/test_all.py | 6 + molecule/generic_files/tests/test_all.yml | 9 - molecule/generic_files/tests/test_client.py | 45 ++++ molecule/generic_files/tests/test_client.yml | 38 ---- .../tests/test_client_folders.py | 9 + .../tests/test_client_restore.py | 24 +++ .../tests/test_client_restore.yml | 18 -- molecule/generic_files/tests/test_lamp.py | 16 ++ molecule/generic_files/tests/test_mgt.py | 18 ++ molecule/generic_files/tests/test_server.py | 23 ++ molecule/generic_files/tests/test_server.yml | 28 --- molecule/lamp/molecule.yml | 4 +- molecule/lamp/tests | 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/molecule.yml | 4 +- molecule/mgt/tests | 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/molecule.yml | 4 +- molecule/multiple/tests | 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 ------------- 65 files changed, 163 insertions(+), 1281 deletions(-) create mode 100644 .gitignore create mode 120000 molecule/clients/tests delete mode 120000 molecule/clients/tests/test_all.yml delete mode 120000 molecule/clients/tests/test_client.yml delete mode 120000 molecule/clients/tests/test_client_restore.yml delete mode 120000 molecule/clients/tests/test_server.yml delete mode 100644 molecule/clients/verify.yml delete mode 120000 molecule/commands/Dockerfile.j2 delete mode 100644 molecule/commands/INSTALL.rst delete mode 100644 molecule/commands/molecule.yml delete mode 120000 molecule/commands/playbook.yml delete mode 120000 molecule/commands/prepare.yml delete mode 120000 molecule/commands/restore.sh.j2 delete mode 120000 molecule/commands/side_effect.yml delete mode 120000 molecule/commands/tests/test_all.yml delete mode 120000 molecule/commands/tests/test_client.yml delete mode 100644 molecule/commands/tests/test_client_commands.yml delete mode 120000 molecule/commands/tests/test_client_restore.yml delete mode 120000 molecule/commands/tests/test_server.yml delete mode 100644 molecule/commands/verify.yml create mode 120000 molecule/folders/tests delete mode 120000 molecule/folders/tests/test_all.yml delete mode 120000 molecule/folders/tests/test_client.yml delete mode 100644 molecule/folders/tests/test_client_folders.yml delete mode 120000 molecule/folders/tests/test_client_restore.yml delete mode 120000 molecule/folders/tests/test_server.yml delete mode 100644 molecule/folders/verify.yml create mode 100644 molecule/generic_files/tests/.flake8 create mode 100644 molecule/generic_files/tests/test_all.py delete mode 100644 molecule/generic_files/tests/test_all.yml create mode 100644 molecule/generic_files/tests/test_client.py delete mode 100644 molecule/generic_files/tests/test_client.yml create mode 100644 molecule/generic_files/tests/test_client_folders.py create mode 100644 molecule/generic_files/tests/test_client_restore.py delete mode 100644 molecule/generic_files/tests/test_client_restore.yml create mode 100644 molecule/generic_files/tests/test_lamp.py create mode 100644 molecule/generic_files/tests/test_mgt.py create mode 100644 molecule/generic_files/tests/test_server.py delete mode 100644 molecule/generic_files/tests/test_server.yml create mode 120000 molecule/lamp/tests delete mode 120000 molecule/lamp/tests/test_all.yml delete mode 120000 molecule/lamp/tests/test_client.yml delete mode 120000 molecule/lamp/tests/test_client_restore.yml delete mode 100644 molecule/lamp/tests/test_lamp.yml delete mode 120000 molecule/lamp/tests/test_server.yml delete mode 100644 molecule/lamp/verify.yml create mode 120000 molecule/mgt/tests delete mode 120000 molecule/mgt/tests/test_all.yml delete mode 120000 molecule/mgt/tests/test_client.yml delete mode 120000 molecule/mgt/tests/test_client_restore.yml delete mode 100644 molecule/mgt/tests/test_mgt.yml delete mode 120000 molecule/mgt/tests/test_server.yml delete mode 100644 molecule/mgt/verify.yml create mode 120000 molecule/multiple/tests delete mode 120000 molecule/multiple/tests/test_all.yml delete mode 120000 molecule/multiple/tests/test_client.yml delete mode 120000 molecule/multiple/tests/test_client_restore.yml delete mode 120000 molecule/multiple/tests/test_server.yml delete mode 100644 molecule/multiple/verify.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02b9af6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.pytest_cache/ +__pycache__/ +pytestdebug.log diff --git a/.travis.yml b/.travis.yml index b30e632..bc27898 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ script: - molecule test --scenario-name lamp - molecule test --scenario-name mgt - molecule test --scenario-name multiple - - molecule test --scenario-name clients +# - molecule test --scenario-name clients diff --git a/molecule/clients/molecule.yml b/molecule/clients/molecule.yml index 8af276a..cde375d 100644 --- a/molecule/clients/molecule.yml +++ b/molecule/clients/molecule.yml @@ -81,6 +81,4 @@ provisioner: scenario: name: clients verifier: - name: goss - lint: - name: yamllint + name: testinfra diff --git a/molecule/clients/tests b/molecule/clients/tests new file mode 120000 index 0000000..630b75e --- /dev/null +++ b/molecule/clients/tests @@ -0,0 +1 @@ +../generic_files/tests \ No newline at end of file diff --git a/molecule/clients/tests/test_all.yml b/molecule/clients/tests/test_all.yml deleted file mode 120000 index 50b87ac..0000000 --- a/molecule/clients/tests/test_all.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 865fba3..0000000 --- a/molecule/clients/tests/test_client.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 01a0351..0000000 --- a/molecule/clients/tests/test_client_restore.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 1c4e7c6..0000000 --- a/molecule/clients/tests/test_server.yml +++ /dev/null @@ -1 +0,0 @@ -../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/clients/verify.yml b/molecule/clients/verify.yml deleted file mode 100644 index cdc44c2..0000000 --- a/molecule/clients/verify.yml +++ /dev/null @@ -1,154 +0,0 @@ ---- -# 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 deleted file mode 120000 index 0373a45..0000000 --- a/molecule/commands/Dockerfile.j2 +++ /dev/null @@ -1 +0,0 @@ -../generic_files/Dockerfile.j2 \ No newline at end of file diff --git a/molecule/commands/INSTALL.rst b/molecule/commands/INSTALL.rst deleted file mode 100644 index 3904805..0000000 --- a/molecule/commands/INSTALL.rst +++ /dev/null @@ -1,26 +0,0 @@ -******* -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 deleted file mode 100644 index 8adb38e..0000000 --- a/molecule/commands/molecule.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -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 deleted file mode 120000 index ace0a3d..0000000 --- a/molecule/commands/playbook.yml +++ /dev/null @@ -1 +0,0 @@ -../generic_files/playbook.yml \ No newline at end of file diff --git a/molecule/commands/prepare.yml b/molecule/commands/prepare.yml deleted file mode 120000 index 28e9479..0000000 --- a/molecule/commands/prepare.yml +++ /dev/null @@ -1 +0,0 @@ -../generic_files/prepare.yml \ No newline at end of file diff --git a/molecule/commands/restore.sh.j2 b/molecule/commands/restore.sh.j2 deleted file mode 120000 index 07356a7..0000000 --- a/molecule/commands/restore.sh.j2 +++ /dev/null @@ -1 +0,0 @@ -../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 deleted file mode 120000 index 9bfbda0..0000000 --- a/molecule/commands/side_effect.yml +++ /dev/null @@ -1 +0,0 @@ -../generic_files/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 deleted file mode 120000 index 50b87ac..0000000 --- a/molecule/commands/tests/test_all.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 865fba3..0000000 --- a/molecule/commands/tests/test_client.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 100644 index 5667f74..0000000 --- a/molecule/commands/tests/test_client_commands.yml +++ /dev/null @@ -1,19 +0,0 @@ -# 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 deleted file mode 120000 index 01a0351..0000000 --- a/molecule/commands/tests/test_client_restore.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 1c4e7c6..0000000 --- a/molecule/commands/tests/test_server.yml +++ /dev/null @@ -1 +0,0 @@ -../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/commands/verify.yml b/molecule/commands/verify.yml deleted file mode 100644 index 393cd1c..0000000 --- a/molecule/commands/verify.yml +++ /dev/null @@ -1,151 +0,0 @@ ---- -# 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/molecule.yml b/molecule/folders/molecule.yml index 0f6369c..2ed5726 100644 --- a/molecule/folders/molecule.yml +++ b/molecule/folders/molecule.yml @@ -9,6 +9,8 @@ platforms: image: debian:stretch networks: - name: ${MOLECULE_SCENARIO_NAME}-borg + groups: + - folders - name: ${MOLECULE_SCENARIO_NAME}-sds hostname: ${MOLECULE_SCENARIO_NAME}-sds image: debian:stretch @@ -45,6 +47,6 @@ provisioner: scenario: name: folders verifier: - name: goss + name: testinfra lint: - name: yamllint + name: flake8 diff --git a/molecule/folders/tests b/molecule/folders/tests new file mode 120000 index 0000000..630b75e --- /dev/null +++ b/molecule/folders/tests @@ -0,0 +1 @@ +../generic_files/tests \ No newline at end of file diff --git a/molecule/folders/tests/test_all.yml b/molecule/folders/tests/test_all.yml deleted file mode 120000 index 50b87ac..0000000 --- a/molecule/folders/tests/test_all.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 865fba3..0000000 --- a/molecule/folders/tests/test_client.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 100644 index 4978699..0000000 --- a/molecule/folders/tests/test_client_folders.yml +++ /dev/null @@ -1,11 +0,0 @@ -# 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 deleted file mode 120000 index 01a0351..0000000 --- a/molecule/folders/tests/test_client_restore.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 1c4e7c6..0000000 --- a/molecule/folders/tests/test_server.yml +++ /dev/null @@ -1 +0,0 @@ -../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/folders/verify.yml b/molecule/folders/verify.yml deleted file mode 100644 index 393cd1c..0000000 --- a/molecule/folders/verify.yml +++ /dev/null @@ -1,151 +0,0 @@ ---- -# 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/tests/.flake8 b/molecule/generic_files/tests/.flake8 new file mode 100644 index 0000000..e44b810 --- /dev/null +++ b/molecule/generic_files/tests/.flake8 @@ -0,0 +1,2 @@ +[flake8] +ignore = E501 diff --git a/molecule/generic_files/tests/test_all.py b/molecule/generic_files/tests/test_all.py new file mode 100644 index 0000000..a3a2c9b --- /dev/null +++ b/molecule/generic_files/tests/test_all.py @@ -0,0 +1,6 @@ +def test_borg_binary(host): + borg = host.file("/usr/local/bin/borg") + assert borg.exists + assert borg.user == "root" + assert borg.group == "root" + assert borg.mode == 0o755 diff --git a/molecule/generic_files/tests/test_all.yml b/molecule/generic_files/tests/test_all.yml deleted file mode 100644 index 6b73f0c..0000000 --- a/molecule/generic_files/tests/test_all.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Molecule managed - ---- -file: - /usr/local/bin/borg: - exists: true - owner: root - group: root - mode: "0755" diff --git a/molecule/generic_files/tests/test_client.py b/molecule/generic_files/tests/test_client.py new file mode 100644 index 0000000..8835fa6 --- /dev/null +++ b/molecule/generic_files/tests/test_client.py @@ -0,0 +1,45 @@ +import os +import pytest +import re +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = ["ansible://all:!borgbackup_servers"] + + +def test_log(host): + logfile = host.file("/var/log/borg-backup.log") + assert logfile.contains("Backup succeeded") + assert logfile.user == "root" + assert logfile.group == "root" + + +# to do read inventory variable : export BORG_PASSPHRASE="{{ borgbackup_passphrase }}" +def test_passphrase(host): + pfile = host.file("/root/.borg.passphrase") + assert pfile.contains("BORG_PASSPHRASE=") + assert pfile.user == "root" + assert pfile.group == "root" + + +@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers')) +def test_sshconfig(host, server): + sshconf = host.file("/root/.ssh/config") + assert sshconf.contains(" ANSIBLE MANAGED BLOCK %s " % server) + assert sshconf.contains("Host %s" % server) + assert sshconf.user == "root" + assert sshconf.group == "root" + + +def test_scriptfile(host): + script = host.file("/usr/local/bin/borg-backup") + assert script.user == "root" + assert script.group == "root" + assert script.mode == 0o744 + + +@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers')) +def test_list_backups(host, server): + command = host.run("bash /usr/local/bin/borg-backup list") + assert command.rc == 0 + assert command.stderr == '' + assert re.match("Archives on %s :\n[0-9]{8}-[0-9]{4}.*" % server, command.stdout) is not None diff --git a/molecule/generic_files/tests/test_client.yml b/molecule/generic_files/tests/test_client.yml deleted file mode 100644 index 1d9bf31..0000000 --- a/molecule/generic_files/tests/test_client.yml +++ /dev/null @@ -1,38 +0,0 @@ -# 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_folders.py b/molecule/generic_files/tests/test_client_folders.py new file mode 100644 index 0000000..c1c692f --- /dev/null +++ b/molecule/generic_files/tests/test_client_folders.py @@ -0,0 +1,9 @@ +testinfra_hosts = ["ansible://folders"] + + +def test_include_exclude(host): + script = host.file("/usr/local/bin/borg-backup") + assert script.contains("/var/cache") + assert script.contains("--exclude '/var/cache/apt'") + assert script.user == "root" + assert script.group == "root" diff --git a/molecule/generic_files/tests/test_client_restore.py b/molecule/generic_files/tests/test_client_restore.py new file mode 100644 index 0000000..6e95090 --- /dev/null +++ b/molecule/generic_files/tests/test_client_restore.py @@ -0,0 +1,24 @@ +import os +import pytest +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = ["ansible://all:!borgbackup_servers"] + + +def test_client_sample_file(host): + sample = host.file("/root/sample.txt") + assert sample.is_file + + +@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers')) +def test_client_dir(host, server): + command = host.run("diff -s /root/sample.txt /root/restore/%s/root/sample.txt" % server) + assert command.rc == 0 + assert "Files /root/sample.txt and /root/restore/%s/root/sample.txt are identical" % server in command.stdout + + +@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers')) +def test_client_verify(host, server): + vcommand = host.run("/root/restore.sh verify") + assert vcommand.rc == 0 + assert vcommand.stdout.rstrip("verifying on %s" % server) diff --git a/molecule/generic_files/tests/test_client_restore.yml b/molecule/generic_files/tests/test_client_restore.yml deleted file mode 100644 index 746c0b0..0000000 --- a/molecule/generic_files/tests/test_client_restore.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -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_lamp.py b/molecule/generic_files/tests/test_lamp.py new file mode 100644 index 0000000..20a9423 --- /dev/null +++ b/molecule/generic_files/tests/test_lamp.py @@ -0,0 +1,16 @@ +testinfra_hosts = ["ansible://lamp"] + + +def test_lamp_default(host): + script = host.file("/usr/local/bin/borg-backup") + assert script.contains("/usr/sbin/automysqlbackup") + assert script.contains("/var/lib/automysqlbackup") + assert script.contains("/var/www") + assert script.user == "root" + assert script.group == "root" + + +def test_lamp_automysqlbackup(host): + backup_dir = host.file("/var/lib/automysqlbackup/daily") + assert backup_dir.exists + assert backup_dir.is_directory diff --git a/molecule/generic_files/tests/test_mgt.py b/molecule/generic_files/tests/test_mgt.py new file mode 100644 index 0000000..b9d9189 --- /dev/null +++ b/molecule/generic_files/tests/test_mgt.py @@ -0,0 +1,18 @@ +import os +import pytest +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = ["ansible://borgbackup_management"] + + +# to do read inventory variable : export BORG_PASSPHRASE="{{ borgbackup_passphrase }}" +@pytest.mark.parametrize('client', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all:!borgbackup_management:!borgbackup_servers')) +def test_prune_script(host, client): + prune = host.file("/root/prune.sh") + assert prune.user == "root" + assert prune.group == "root" + assert prune.mode == 0o700 + assert prune.contains("/usr/local/bin/borg prune") + assert prune.contains("export BORG_PASSPHRASE=") + assert prune.contains("Host: %s" % client) + assert prune.contains(":/var/backup/repos/%s" % client) diff --git a/molecule/generic_files/tests/test_server.py b/molecule/generic_files/tests/test_server.py new file mode 100644 index 0000000..f1e4f9b --- /dev/null +++ b/molecule/generic_files/tests/test_server.py @@ -0,0 +1,23 @@ +import os +import pytest +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = ["ansible://borgbackup_servers"] + + +def test_client_parent_dir(host): + parentdir = host.file("/var/backup/repos") + assert parentdir.is_directory + + +@pytest.mark.parametrize('client', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all:!borgbackup_servers')) +def test_client_dir(host, client): + clientdir = host.file("/var/backup/repos/%s" % client) + assert clientdir.is_directory + + +@pytest.mark.parametrize('client', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all:!borgbackup_servers')) +def test_ssh_client_conf(host, client): + sshconf = host.file("/var/backup/.ssh/authorized_keys") + assert sshconf.is_file + assert sshconf.contains("%s;borg serve" % client) diff --git a/molecule/generic_files/tests/test_server.yml b/molecule/generic_files/tests/test_server.yml deleted file mode 100644 index 31856d4..0000000 --- a/molecule/generic_files/tests/test_server.yml +++ /dev/null @@ -1,28 +0,0 @@ -# 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/molecule.yml b/molecule/lamp/molecule.yml index 534ebc0..c854dee 100644 --- a/molecule/lamp/molecule.yml +++ b/molecule/lamp/molecule.yml @@ -39,6 +39,6 @@ provisioner: scenario: name: lamp verifier: - name: goss + name: testinfra lint: - name: yamllint + name: flake8 diff --git a/molecule/lamp/tests b/molecule/lamp/tests new file mode 120000 index 0000000..630b75e --- /dev/null +++ b/molecule/lamp/tests @@ -0,0 +1 @@ +../generic_files/tests \ No newline at end of file diff --git a/molecule/lamp/tests/test_all.yml b/molecule/lamp/tests/test_all.yml deleted file mode 120000 index 50b87ac..0000000 --- a/molecule/lamp/tests/test_all.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 865fba3..0000000 --- a/molecule/lamp/tests/test_client.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 01a0351..0000000 --- a/molecule/lamp/tests/test_client_restore.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 100644 index 01fbf62..0000000 --- a/molecule/lamp/tests/test_lamp.yml +++ /dev/null @@ -1,17 +0,0 @@ -# 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 deleted file mode 120000 index 1c4e7c6..0000000 --- a/molecule/lamp/tests/test_server.yml +++ /dev/null @@ -1 +0,0 @@ -../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/lamp/verify.yml b/molecule/lamp/verify.yml deleted file mode 100644 index 5342bc0..0000000 --- a/molecule/lamp/verify.yml +++ /dev/null @@ -1,200 +0,0 @@ ---- -# 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/molecule.yml b/molecule/mgt/molecule.yml index bad6774..d0d656e 100644 --- a/molecule/mgt/molecule.yml +++ b/molecule/mgt/molecule.yml @@ -71,6 +71,6 @@ provisioner: scenario: name: mgt verifier: - name: goss + name: testinfra lint: - name: yamllint + name: flake8 diff --git a/molecule/mgt/tests b/molecule/mgt/tests new file mode 120000 index 0000000..630b75e --- /dev/null +++ b/molecule/mgt/tests @@ -0,0 +1 @@ +../generic_files/tests \ No newline at end of file diff --git a/molecule/mgt/tests/test_all.yml b/molecule/mgt/tests/test_all.yml deleted file mode 120000 index 50b87ac..0000000 --- a/molecule/mgt/tests/test_all.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 865fba3..0000000 --- a/molecule/mgt/tests/test_client.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 01a0351..0000000 --- a/molecule/mgt/tests/test_client_restore.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 100644 index ce09c27..0000000 --- a/molecule/mgt/tests/test_mgt.yml +++ /dev/null @@ -1,16 +0,0 @@ -# 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 deleted file mode 120000 index 1c4e7c6..0000000 --- a/molecule/mgt/tests/test_server.yml +++ /dev/null @@ -1 +0,0 @@ -../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/mgt/verify.yml b/molecule/mgt/verify.yml deleted file mode 100644 index 7ebf8a2..0000000 --- a/molecule/mgt/verify.yml +++ /dev/null @@ -1,200 +0,0 @@ ---- -# 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/molecule.yml b/molecule/multiple/molecule.yml index a160855..b3d1b3c 100644 --- a/molecule/multiple/molecule.yml +++ b/molecule/multiple/molecule.yml @@ -66,6 +66,6 @@ provisioner: scenario: name: multiple verifier: - name: goss + name: testinfra lint: - name: yamllint + name: flake8 diff --git a/molecule/multiple/tests b/molecule/multiple/tests new file mode 120000 index 0000000..630b75e --- /dev/null +++ b/molecule/multiple/tests @@ -0,0 +1 @@ +../generic_files/tests \ No newline at end of file diff --git a/molecule/multiple/tests/test_all.yml b/molecule/multiple/tests/test_all.yml deleted file mode 120000 index 50b87ac..0000000 --- a/molecule/multiple/tests/test_all.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 865fba3..0000000 --- a/molecule/multiple/tests/test_client.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 01a0351..0000000 --- a/molecule/multiple/tests/test_client_restore.yml +++ /dev/null @@ -1 +0,0 @@ -../../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 deleted file mode 120000 index 1c4e7c6..0000000 --- a/molecule/multiple/tests/test_server.yml +++ /dev/null @@ -1 +0,0 @@ -../../generic_files/tests/test_server.yml \ No newline at end of file diff --git a/molecule/multiple/verify.yml b/molecule/multiple/verify.yml deleted file mode 100644 index 393cd1c..0000000 --- a/molecule/multiple/verify.yml +++ /dev/null @@ -1,151 +0,0 @@ ---- -# 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 }}" From 00f9f5d5d1a2b371e34822b7f6b057924653b712 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 10:36:10 +0100 Subject: [PATCH 16/27] Dont specify ansible version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bc27898..3de7be4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_install: - sudo apt-get -qq update install: - pip install molecule - - pip install ansible==2.7 + - pip install ansible - pip install docker script: - molecule test --scenario-name commands From dc4d30ba7a0fe949fdeb079a895f9fd54e92b839 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 12:12:43 +0100 Subject: [PATCH 17/27] Setting testinfra to verbose, its nicer --- molecule/clients/molecule.yml | 4 ++++ molecule/folders/molecule.yml | 2 ++ molecule/lamp/molecule.yml | 2 ++ molecule/mgt/molecule.yml | 2 ++ molecule/multiple/molecule.yml | 4 +++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/molecule/clients/molecule.yml b/molecule/clients/molecule.yml index cde375d..5e81832 100644 --- a/molecule/clients/molecule.yml +++ b/molecule/clients/molecule.yml @@ -82,3 +82,7 @@ scenario: name: clients verifier: name: testinfra + options: + verbose: true + lint: + name: flake8 diff --git a/molecule/folders/molecule.yml b/molecule/folders/molecule.yml index 2ed5726..4881e9e 100644 --- a/molecule/folders/molecule.yml +++ b/molecule/folders/molecule.yml @@ -48,5 +48,7 @@ scenario: name: folders verifier: name: testinfra + options: + verbose: true lint: name: flake8 diff --git a/molecule/lamp/molecule.yml b/molecule/lamp/molecule.yml index c854dee..810f148 100644 --- a/molecule/lamp/molecule.yml +++ b/molecule/lamp/molecule.yml @@ -40,5 +40,7 @@ scenario: name: lamp verifier: name: testinfra + options: + verbose: true lint: name: flake8 diff --git a/molecule/mgt/molecule.yml b/molecule/mgt/molecule.yml index d0d656e..c7c3bfc 100644 --- a/molecule/mgt/molecule.yml +++ b/molecule/mgt/molecule.yml @@ -72,5 +72,7 @@ scenario: name: mgt verifier: name: testinfra + options: + verbose: true lint: name: flake8 diff --git a/molecule/multiple/molecule.yml b/molecule/multiple/molecule.yml index b3d1b3c..ef0a37b 100644 --- a/molecule/multiple/molecule.yml +++ b/molecule/multiple/molecule.yml @@ -46,7 +46,7 @@ provisioner: - fqdn: ${MOLECULE_SCENARIO_NAME}-sub user: borgux type: normal - home: /var/backup-jail/ + home: /var/backup/ pool: repos options: "" borgbackup_include: @@ -67,5 +67,7 @@ scenario: name: multiple verifier: name: testinfra + options: + verbose: true lint: name: flake8 From dada2d4556452fb4d026a595809edc3ea10f8c10 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 12:14:10 +0100 Subject: [PATCH 18/27] slim down docker container, doing everything in prepare.yml --- molecule/generic_files/Dockerfile.j2 | 8 ++---- molecule/generic_files/prepare.yml | 42 ++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/molecule/generic_files/Dockerfile.j2 b/molecule/generic_files/Dockerfile.j2 index 2a39d9e..c2bd953 100644 --- a/molecule/generic_files/Dockerfile.j2 +++ b/molecule/generic_files/Dockerfile.j2 @@ -1,14 +1,10 @@ # 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; \ +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && 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 yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && 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/prepare.yml b/molecule/generic_files/prepare.yml index eb8c72c..f8aa51a 100644 --- a/molecule/generic_files/prepare.yml +++ b/molecule/generic_files/prepare.yml @@ -1,17 +1,41 @@ --- -- name: prepare servers - Debian only - hosts: borgbackup_servers - gather_facts: true +- name: prepare debian-based systems + hosts: all:!centos + gather_facts: false tasks: + - name: install required packages + apt: + name: + - bash + - ca-certificates + - cron + - iputils-ping + - openssh-client + +- name: prepare centos-based systems + hosts: centos + gather_facts: false + tasks: + - name: install required packages + yum: + name: + - anacron + - iputils + - openssh-clients + +- name: prepare debian-based backupservers + hosts: borgbackup_servers + gather_facts: false + tasks: + - name: install required packages + apt: + name: + - openssh-server - 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 all - hosts: all:!borgbackup_servers:!centos +- name: prepare lamp + hosts: lamp tasks: - name: Install required packages apt: From 829e1585fb8c729dbd90e9bceb854739bf08902d Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 12:14:47 +0100 Subject: [PATCH 19/27] Trying to nicen up travis-ci --- .travis.yml | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3de7be4..724605f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,33 @@ --- sudo: required + language: python + services: - docker + before_install: - sudo apt-get -qq update + install: - pip install molecule - pip install ansible - pip install docker -script: - - molecule test --scenario-name commands - - molecule test --scenario-name folders - - molecule test --scenario-name lamp - - molecule test --scenario-name mgt - - molecule test --scenario-name multiple -# - molecule test --scenario-name clients + +jobs: + include: + - stage: "Exclude / Include paths" + name: "Exclude / Include paths" + script: molecule test --scenario-name folders + - stage: "Test default LAMP" + name: "Test default LAMP" + script: molecule test --scenario-name lamp + - stage: "Test Management Station" + name: "Test Management Station" + script: molecule test --scenario-name mgt + - stage: "Test Multiple Backup Targets" + name: "Test Multiple Backup Targets" + script: molecule test --scenario-name multiple + - stage: "Testing a variety of different platforms" + name: "Testing a variety of different platforms" + script: molecule test --scenario-name clients From 020766632d205bcb4e90bd76f0146751b123fab2 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 12:33:37 +0100 Subject: [PATCH 20/27] Parallelize travis --- .travis.yml | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 724605f..7aec557 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,20 +14,11 @@ install: - pip install ansible - pip install docker -jobs: - include: - - stage: "Exclude / Include paths" - name: "Exclude / Include paths" - script: molecule test --scenario-name folders - - stage: "Test default LAMP" - name: "Test default LAMP" - script: molecule test --scenario-name lamp - - stage: "Test Management Station" - name: "Test Management Station" - script: molecule test --scenario-name mgt - - stage: "Test Multiple Backup Targets" - name: "Test Multiple Backup Targets" - script: molecule test --scenario-name multiple - - stage: "Testing a variety of different platforms" - name: "Testing a variety of different platforms" - script: molecule test --scenario-name clients +env: + - SCENARIO=folders + - SCENARIO=lamp + - SCENARIO=mgt + - SCENARIO=multiple + - SCENARIO=clients + +script: "molecule test --scenario-name $SCENARIO" From 5a082be8a2ae90c2e4e446530d5f639658a88a5c Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 12:52:12 +0100 Subject: [PATCH 21/27] Fix multiple client test --- molecule/generic_files/tests/test_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule/generic_files/tests/test_client.py b/molecule/generic_files/tests/test_client.py index 8835fa6..ed729f0 100644 --- a/molecule/generic_files/tests/test_client.py +++ b/molecule/generic_files/tests/test_client.py @@ -42,4 +42,4 @@ def test_list_backups(host, server): command = host.run("bash /usr/local/bin/borg-backup list") assert command.rc == 0 assert command.stderr == '' - assert re.match("Archives on %s :\n[0-9]{8}-[0-9]{4}.*" % server, command.stdout) is not None + assert "Archives on %s :\n2" % server in command.stdout From 8157a3b3dbaa77623ad89eabb25e8c68cc85c84a Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 12:57:29 +0100 Subject: [PATCH 22/27] Dont import re when its not used --- molecule/generic_files/tests/test_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/molecule/generic_files/tests/test_client.py b/molecule/generic_files/tests/test_client.py index ed729f0..f43bbd0 100644 --- a/molecule/generic_files/tests/test_client.py +++ b/molecule/generic_files/tests/test_client.py @@ -1,6 +1,5 @@ import os import pytest -import re from testinfra.utils.ansible_runner import AnsibleRunner testinfra_hosts = ["ansible://all:!borgbackup_servers"] From 0a8c4601221f13f63b8addf5ed6c664a6a2b1493 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 13:18:04 +0100 Subject: [PATCH 23/27] Reflecting build-status in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc7783f..17a9714 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/dverhelst/borgbackup.svg?branch=feature/molecule)](https://travis-ci.com/dverhelst/borgbackup) +[![Build Status](https://travis-ci.com/dverhelst/borgbackup.svg)](https://travis-ci.com/dverhelst/borgbackup) # Borg backup role This role installs Borg backup on borgbackup\_servers and clients. The role contains a wrapper-script 'borg-backup' to ease the usage on the client. Supported options include borg-backup info | init | list | backup | mount. Automysqlbackup will run as pre-backup command if it's installed. From 3237335b6db17c3fd48c535656d095a438da5e5a Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 14:00:01 +0100 Subject: [PATCH 24/27] Rename scenario to extra_opts indicating flexible use --- .travis.yml | 2 +- molecule/{folders => extra_opts}/Dockerfile.j2 | 0 molecule/{folders => extra_opts}/INSTALL.rst | 0 molecule/{folders => extra_opts}/molecule.yml | 8 ++++++-- molecule/{folders => extra_opts}/playbook.yml | 0 molecule/{folders => extra_opts}/prepare.yml | 0 molecule/{folders => extra_opts}/restore.sh.j2 | 0 .../{folders => extra_opts}/side_effect.yml | 0 molecule/{folders => extra_opts}/tests | 0 .../tests/test_client_extra_opts.py | 17 +++++++++++++++++ .../generic_files/tests/test_client_folders.py | 9 --------- 11 files changed, 24 insertions(+), 12 deletions(-) rename molecule/{folders => extra_opts}/Dockerfile.j2 (100%) rename molecule/{folders => extra_opts}/INSTALL.rst (100%) rename molecule/{folders => extra_opts}/molecule.yml (87%) rename molecule/{folders => extra_opts}/playbook.yml (100%) rename molecule/{folders => extra_opts}/prepare.yml (100%) rename molecule/{folders => extra_opts}/restore.sh.j2 (100%) rename molecule/{folders => extra_opts}/side_effect.yml (100%) rename molecule/{folders => extra_opts}/tests (100%) create mode 100644 molecule/generic_files/tests/test_client_extra_opts.py delete mode 100644 molecule/generic_files/tests/test_client_folders.py diff --git a/.travis.yml b/.travis.yml index 7aec557..29b9480 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,8 @@ install: - pip install docker env: - - SCENARIO=folders - SCENARIO=lamp + - SCENARIO=extra_opts - SCENARIO=mgt - SCENARIO=multiple - SCENARIO=clients diff --git a/molecule/folders/Dockerfile.j2 b/molecule/extra_opts/Dockerfile.j2 similarity index 100% rename from molecule/folders/Dockerfile.j2 rename to molecule/extra_opts/Dockerfile.j2 diff --git a/molecule/folders/INSTALL.rst b/molecule/extra_opts/INSTALL.rst similarity index 100% rename from molecule/folders/INSTALL.rst rename to molecule/extra_opts/INSTALL.rst diff --git a/molecule/folders/molecule.yml b/molecule/extra_opts/molecule.yml similarity index 87% rename from molecule/folders/molecule.yml rename to molecule/extra_opts/molecule.yml index 4881e9e..dc1c80b 100644 --- a/molecule/folders/molecule.yml +++ b/molecule/extra_opts/molecule.yml @@ -10,7 +10,7 @@ platforms: networks: - name: ${MOLECULE_SCENARIO_NAME}-borg groups: - - folders + - extra_opts - name: ${MOLECULE_SCENARIO_NAME}-sds hostname: ${MOLECULE_SCENARIO_NAME}-sds image: debian:stretch @@ -42,10 +42,14 @@ provisioner: - "/var/cache" borgbackup_exclude: - "/var/cache/apt" + borgbackup_pre_commands: + - "dpkg --get-selections" + borgbackup_post_commands: + - "apt list" lint: name: ansible-lint scenario: - name: folders + name: extra_opts verifier: name: testinfra options: diff --git a/molecule/folders/playbook.yml b/molecule/extra_opts/playbook.yml similarity index 100% rename from molecule/folders/playbook.yml rename to molecule/extra_opts/playbook.yml diff --git a/molecule/folders/prepare.yml b/molecule/extra_opts/prepare.yml similarity index 100% rename from molecule/folders/prepare.yml rename to molecule/extra_opts/prepare.yml diff --git a/molecule/folders/restore.sh.j2 b/molecule/extra_opts/restore.sh.j2 similarity index 100% rename from molecule/folders/restore.sh.j2 rename to molecule/extra_opts/restore.sh.j2 diff --git a/molecule/folders/side_effect.yml b/molecule/extra_opts/side_effect.yml similarity index 100% rename from molecule/folders/side_effect.yml rename to molecule/extra_opts/side_effect.yml diff --git a/molecule/folders/tests b/molecule/extra_opts/tests similarity index 100% rename from molecule/folders/tests rename to molecule/extra_opts/tests diff --git a/molecule/generic_files/tests/test_client_extra_opts.py b/molecule/generic_files/tests/test_client_extra_opts.py new file mode 100644 index 0000000..28cd2d3 --- /dev/null +++ b/molecule/generic_files/tests/test_client_extra_opts.py @@ -0,0 +1,17 @@ +testinfra_hosts = ["ansible://extra_opts"] + + +def test_include_exclude(host): + script = host.file("/usr/local/bin/borg-backup") + assert script.contains("/var/cache") + assert script.contains("--exclude '/var/cache/apt'") + assert script.user == "root" + assert script.group == "root" + + +def test_pre_post_commands(host): + script = host.file("/usr/local/bin/borg-backup") + assert script.contains("dpkg --get-selection") + assert script.contains("apt list") + assert script.user == "root" + assert script.group == "root" diff --git a/molecule/generic_files/tests/test_client_folders.py b/molecule/generic_files/tests/test_client_folders.py deleted file mode 100644 index c1c692f..0000000 --- a/molecule/generic_files/tests/test_client_folders.py +++ /dev/null @@ -1,9 +0,0 @@ -testinfra_hosts = ["ansible://folders"] - - -def test_include_exclude(host): - script = host.file("/usr/local/bin/borg-backup") - assert script.contains("/var/cache") - assert script.contains("--exclude '/var/cache/apt'") - assert script.user == "root" - assert script.group == "root" From 2a071ab5eb99c74b9633ff199c14a78c6df30827 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 14:00:30 +0100 Subject: [PATCH 25/27] Document the molecule layout --- molecule/README.md | 88 +++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/molecule/README.md b/molecule/README.md index 2432cd1..b673254 100644 --- a/molecule/README.md +++ b/molecule/README.md @@ -1,27 +1,39 @@ # Borg backup role - Molecule testing -Requirements: +## Requirements -Ansible 2.4 or higher +Ansible 2.4 or higher Molecule 2.17.0 or higher Docker host (local or remote through shell environment) -## Available tests +## Available tests run on all scenarios -All scenarios run the same tests by default defined in generic_tests +All scenarios run the same tests by default defined in generic_tests. If a test applies to a certain group only, group filtering is done through testinfra with the ansible:// url. +Eg: +``` +testinfra_hosts = ["ansible://borgbackup_servers"] +``` ### all +[generic\_files/tests/test_all.py](generic_files/tests/test_all.py) + Verify the borg-binary is present + ### client +Testinfra: [generic\_files/tests/test_client.py](generic_files/tests/test_client.py) 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. +Testinfra: [generic\_files/tests/test_client_restore.py](generic_files/tests/test_client_restore.py) +Verifies if the restore functionality works correctly. + ### server +Testinfra: [generic\_files/tests/test_server.py](generic_files/tests/test_server.py) Verifies if all server-related configurations are in place and if the backup is working from a server perspective. @@ -29,7 +41,7 @@ Verifies if all server-related configurations are in place and if the backup is ### clients -This tests spins up supported platforms and verifies the basic functionality of both server and client with the generic_tests. +This tests spins up supported platforms and verifies the basic functionality of both server and client with the generic_tests on a number of platforms and linux distributions. ``` borgbackup_appendonly: @@ -38,35 +50,6 @@ 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. @@ -75,9 +58,40 @@ Testing whether backing up to multiple targets works properly. borgbackup_servers: ``` +### extra_opts + +Testinfra: [generic\_files/tests/test_server.py](generic_files/tests/test_server.py) + +Verify if both pre and post commands are configured at backup time and are run. + + +``` +borgbackup_pre_commands: +borgbackup_post_commands: +``` + +Verify if both inclusion and exclusion of folders is working as expected + +``` +borgbackup_include: +borgbackup_exclude: +``` + +### lamp + +Testinfra: [generic\_files/tests/test_lamp.py](generic_files/tests/test_lamp.py) +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 +``` + ### mgt -Testing whether the management-station functionality works +Testinfra: [generic\_files/tests/test_mgt.py](generic_files/tests/test_mgt.py) +Testing whether the management-station functionality works and all clients are listed. ``` borgbackup_management: @@ -85,6 +99,6 @@ borgbackup_management_user: borgbackup_management_sshkey: ``` -### restore - +## restore +A restore is tested by default in every scenario by the use of the side-effect playbook. [generic\_files/side_effect.yml](generic_files/side_effect.yml) From a17c68563b5ce5ad7300b6b8d0f791ac180380d4 Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Tue, 12 Mar 2019 14:00:51 +0100 Subject: [PATCH 26/27] Dont gather facts --- molecule/generic_files/prepare.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/molecule/generic_files/prepare.yml b/molecule/generic_files/prepare.yml index f8aa51a..ef259ac 100644 --- a/molecule/generic_files/prepare.yml +++ b/molecule/generic_files/prepare.yml @@ -36,6 +36,7 @@ - name: prepare lamp hosts: lamp + gather_facts: false tasks: - name: Install required packages apt: From 305f7b484f8363e98516d8c8ff12d77dafc3deeb Mon Sep 17 00:00:00 2001 From: Dieter Verhelst Date: Mon, 18 Mar 2019 11:36:11 +0100 Subject: [PATCH 27/27] Reflect build url to be FiaasCo/Borgbackup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 17a9714..5e60556 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/dverhelst/borgbackup.svg)](https://travis-ci.com/dverhelst/borgbackup) +[![Build Status](https://travis-ci.com/FiaasCo/borgbackup.svg?branch=master)](https://travis-ci.com/FiaasCo/borgbackup) # Borg backup role This role installs Borg backup on borgbackup\_servers and clients. The role contains a wrapper-script 'borg-backup' to ease the usage on the client. Supported options include borg-backup info | init | list | backup | mount. Automysqlbackup will run as pre-backup command if it's installed.