Initial molecule WIP

This commit is contained in:
Dieter Verhelst 2018-08-30 23:34:04 +02:00
parent 4475c07bc2
commit 3e1b0473cc
86 changed files with 1904 additions and 0 deletions

12
.yamllint Normal file
View File

@ -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

90
molecule/README.md Normal file
View File

@ -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

View File

@ -0,0 +1 @@
../generic_files/Dockerfile.j2

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
../generic_files/playbook.yml

View File

@ -0,0 +1 @@
../generic_files/prepare.yml

View File

@ -0,0 +1 @@
../generic_files/restore.sh.j2

View File

@ -0,0 +1 @@
../restore/side_effect.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_all.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client_restore.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_server.yml

154
molecule/clients/verify.yml Normal file
View File

@ -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 }}"

View File

@ -0,0 +1 @@
../generic_files/Dockerfile.j2

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
../generic_files/playbook.yml

View File

@ -0,0 +1 @@
../generic_files/prepare.yml

View File

@ -0,0 +1 @@
../generic_files/restore.sh.j2

View File

@ -0,0 +1 @@
../restore/side_effect.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_all.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client.yml

View File

@ -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"

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client_restore.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_server.yml

View File

@ -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 }}"

View File

@ -0,0 +1 @@
../generic_files/Dockerfile.j2

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
../generic_files/playbook.yml

View File

@ -0,0 +1 @@
../generic_files/prepare.yml

View File

@ -0,0 +1 @@
../generic_files/restore.sh.j2

View File

@ -0,0 +1 @@
../restore/side_effect.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_all.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client.yml

View File

@ -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'"

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client_restore.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_server.yml

151
molecule/folders/verify.yml Normal file
View File

@ -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 }}"

View File

@ -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

View File

@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: borgbackup

View File

@ -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

View File

@ -0,0 +1 @@
../restore/restore.sh.j2

View File

@ -0,0 +1,9 @@
# Molecule managed
---
file:
/usr/local/bin/borg:
exists: true
owner: root
group: root
mode: "0755"

View File

@ -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}.*/"

View File

@ -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 %}

View File

@ -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 %}

1
molecule/lamp/Dockerfile.j2 Symbolic link
View File

@ -0,0 +1 @@
../generic_files/Dockerfile.j2

26
molecule/lamp/INSTALL.rst Normal file
View File

@ -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

View File

@ -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

1
molecule/lamp/playbook.yml Symbolic link
View File

@ -0,0 +1 @@
../generic_files/playbook.yml

1
molecule/lamp/prepare.yml Symbolic link
View File

@ -0,0 +1 @@
../generic_files/prepare.yml

1
molecule/lamp/restore.sh.j2 Symbolic link
View File

@ -0,0 +1 @@
../generic_files/restore.sh.j2

View File

@ -0,0 +1 @@
../restore/side_effect.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_all.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client_restore.yml

View File

@ -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

View File

@ -0,0 +1 @@
../../generic_files/tests/test_server.yml

200
molecule/lamp/verify.yml Normal file
View File

@ -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 }}"

1
molecule/mgt/Dockerfile.j2 Symbolic link
View File

@ -0,0 +1 @@
../generic_files/Dockerfile.j2

26
molecule/mgt/INSTALL.rst Normal file
View File

@ -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

76
molecule/mgt/molecule.yml Normal file
View File

@ -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

1
molecule/mgt/playbook.yml Symbolic link
View File

@ -0,0 +1 @@
../generic_files/playbook.yml

1
molecule/mgt/prepare.yml Symbolic link
View File

@ -0,0 +1 @@
../generic_files/prepare.yml

1
molecule/mgt/restore.sh.j2 Symbolic link
View File

@ -0,0 +1 @@
../generic_files/restore.sh.j2

View File

@ -0,0 +1 @@
../restore/side_effect.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_all.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client_restore.yml

View File

@ -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"

View File

@ -0,0 +1 @@
../../generic_files/tests/test_server.yml

200
molecule/mgt/verify.yml Normal file
View File

@ -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 }}"

View File

@ -0,0 +1 @@
../generic_files/Dockerfile.j2

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
../generic_files/playbook.yml

View File

@ -0,0 +1 @@
../generic_files/prepare.yml

View File

@ -0,0 +1 @@
../generic_files/restore.sh.j2

View File

@ -0,0 +1 @@
../restore/side_effect.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_all.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_client_restore.yml

View File

@ -0,0 +1 @@
../../generic_files/tests/test_server.yml

View File

@ -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 }}"