diff --git a/roles/borgmatic/.travis.yml b/roles/borgmatic/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/roles/borgmatic/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/roles/borgmatic/.yamllint b/roles/borgmatic/.yamllint new file mode 100644 index 0000000..8827676 --- /dev/null +++ b/roles/borgmatic/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable diff --git a/roles/borgmatic/README.md b/roles/borgmatic/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/borgmatic/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/borgmatic/defaults/main.yml b/roles/borgmatic/defaults/main.yml new file mode 100644 index 0000000..eff2217 --- /dev/null +++ b/roles/borgmatic/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for borgmatic diff --git a/roles/borgmatic/handlers/main.yml b/roles/borgmatic/handlers/main.yml new file mode 100644 index 0000000..6314fb8 --- /dev/null +++ b/roles/borgmatic/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for borgmatic diff --git a/roles/borgmatic/molecule/default/INSTALL.rst b/roles/borgmatic/molecule/default/INSTALL.rst new file mode 100644 index 0000000..0c4bf5c --- /dev/null +++ b/roles/borgmatic/molecule/default/INSTALL.rst @@ -0,0 +1,23 @@ +********************************* +Vagrant driver installation guide +********************************* + +Requirements +============ + +* Vagrant +* Virtualbox, Parallels, VMware Fusion, VMware Workstation or VMware Desktop + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ pip install 'molecule_vagrant' diff --git a/roles/borgmatic/molecule/default/converge.yml b/roles/borgmatic/molecule/default/converge.yml new file mode 100644 index 0000000..e3e84d0 --- /dev/null +++ b/roles/borgmatic/molecule/default/converge.yml @@ -0,0 +1,13 @@ +--- +- name: Converge + hosts: all + become: yes + pre_tasks: + - name: Update apt cache + apt: + update_cache: yes + + tasks: + - name: "Include borgmatic" + include_role: + name: "borgmatic" diff --git a/roles/borgmatic/molecule/default/molecule.yml b/roles/borgmatic/molecule/default/molecule.yml new file mode 100644 index 0000000..2e06323 --- /dev/null +++ b/roles/borgmatic/molecule/default/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: vagrant + provider: + name: virtualbox +platforms: + - name: Debian + box: "debian/bullseye64" + pre_build_image: true +provisioner: + name: ansible +verifier: + name: testinfra + options: + sudo: true + v: 3 diff --git a/roles/borgmatic/molecule/default/tests/conftest.py b/roles/borgmatic/molecule/default/tests/conftest.py new file mode 100644 index 0000000..f7ddb3f --- /dev/null +++ b/roles/borgmatic/molecule/default/tests/conftest.py @@ -0,0 +1,22 @@ +"""PyTest Fixtures.""" +from __future__ import absolute_import + +import os + +import pytest + + +def pytest_runtest_setup(item): + """Run tests only when under molecule with testinfra installed.""" + try: + import testinfra + except ImportError: + pytest.skip("Test requires testinfra", allow_module_level=True) + if "MOLECULE_INVENTORY_FILE" in os.environ: + pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] + ).get_hosts("all") + else: + pytest.skip( + "Test should run only from inside molecule.", allow_module_level=True + ) diff --git a/roles/borgmatic/molecule/default/tests/test_default.py b/roles/borgmatic/molecule/default/tests/test_default.py new file mode 100644 index 0000000..d4a27bd --- /dev/null +++ b/roles/borgmatic/molecule/default/tests/test_default.py @@ -0,0 +1,8 @@ +"""Role testing files using testinfra.""" +import pytest + +def test_installed_packages(host): + borgbackup = host.package("borgbackup") + assert borgbackup.is_installed + borgmatic = host.package("borgmatic") + assert borgmatic.is_installed diff --git a/roles/borgmatic/tasks/main.yml b/roles/borgmatic/tasks/main.yml new file mode 100644 index 0000000..f186934 --- /dev/null +++ b/roles/borgmatic/tasks/main.yml @@ -0,0 +1,9 @@ +--- +# tasks file for borgmatic +- name: Install borg and borgmatic + apt: + name: "{{ item }}" + state: present + with_items: + - borg + - borgmatic diff --git a/roles/borgmatic/tests/inventory b/roles/borgmatic/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/borgmatic/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/borgmatic/tests/test.yml b/roles/borgmatic/tests/test.yml new file mode 100644 index 0000000..b362fc9 --- /dev/null +++ b/roles/borgmatic/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - borgmatic diff --git a/roles/borgmatic/vars/main.yml b/roles/borgmatic/vars/main.yml new file mode 100644 index 0000000..053c567 --- /dev/null +++ b/roles/borgmatic/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for borgmatic