Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
Propagate changes from cloudalchemy roles (#52)
Browse files Browse the repository at this point in the history
* more efficient checksum handling; clearer CPU architecture management

* align test-requirements with cloudalchemy/skeleton

* do not change default user and group in default test scenario

* add "latest" test scenario

* add tags

* specify which parts need elevated privileges

* fix tests

* [minor] release
  • Loading branch information
paulfantom committed Mar 28, 2019
1 parent b264be2 commit 71b368d
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ env:
- ANSIBLE=2.5
- ANSIBLE=2.6
- ANSIBLE=2.7
matrix:
fast_finish: true
install:
- pip install tox-travis git-semver
script:
- tox
- ./.travis/test.sh
deploy:
provider: script
skip_cleanup: true
Expand Down
8 changes: 8 additions & 0 deletions .travis/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
tox -- molecule test --all
else
tox -- molecule test -s default --destroy always
tox -- molecule test -s alternative --destroy never
fi
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ For example, if you have a restic repository named `testrepo`, you could use the
Use it in a playbook as follows:
```yaml
- hosts: all
become: yes
roles:
- paulfantom.restic
```
Expand Down
1 change: 0 additions & 1 deletion molecule/alternative/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
roles:
- ansible-restic
vars:
restic_version: 'latest'
restic_user: restic
restic_group: restic
restic_install_path: "/opt"
Expand Down
2 changes: 0 additions & 2 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
roles:
- ansible-restic
vars:
restic_user: restic
restic_group: restic
restic_repos:
- name: local-example
url: "/tmp/restic"
Expand Down
36 changes: 36 additions & 0 deletions molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: stretch
image: paulfantom/debian-molecule:9
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: fedora
image: paulfantom/fedora-molecule:27
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
create: ../default/create.yml
prepare: ../default/prepare.yml
converge: playbook.yml
destroy: ../default/destroy.yml
scenario:
name: latest
verifier:
name: testinfra
lint:
name: flake8
enabled: true
27 changes: 27 additions & 0 deletions molecule/latest/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Default use-case scenario
hosts: all
any_errors_fatal: true
roles:
- ansible-restic
vars:
restic_version: latest
restic_user: restic
restic_group: restic
restic_repos:
- name: local-example
url: "/tmp/restic"
password: "correcthorsebatterystaple"
jobs:
- command: 'restic backup /srv'
at: '0 1 * * *'
retention_time: '17 5 * * *'
retention:
last: 2
hourly: 4
weekly: 9
monthly: 3
yearly: 10
tags:
- special
- test
12 changes: 12 additions & 0 deletions molecule/latest/tests/test_alternative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_binary(host):
binary = host.file("/usr/local/bin/restic")
assert binary.exists
assert binary.is_file
assert binary.mode == 0o750
10 changes: 5 additions & 5 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@
- name: Download client binary
become: false
get_url:
url: "https://github.com/restic/restic/releases/download/v{{ restic_version }}/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.bz2"
dest: "/tmp/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.bz2"
url: "https://github.com/restic/restic/releases/download/v{{ restic_version }}/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch }}.bz2"
dest: "/tmp/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch }}.bz2"
checksum: "sha256:{{ restic_checksum }}"
delegate_to: localhost
run_once: true
check_mode: false

- name: Decompress the binary
become: false
shell: "bzip2 -dc /tmp/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.bz2 > /tmp/restic_{{ restic_version }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
shell: "bzip2 -dc /tmp/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch }}.bz2 > /tmp/restic_{{ restic_version }}_{{ go_arch }}"
args:
creates: "/tmp/restic_{{ restic_version }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
creates: "/tmp/restic_{{ restic_version }}_{{ go_arch }}"
delegate_to: localhost
run_once: true
check_mode: false

- name: Propagate restic binary
copy:
src: "/tmp/restic_{{ restic_version }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
src: "/tmp/restic_{{ restic_version }}_{{ go_arch }}"
dest: '{{ restic_install_path }}/restic'
mode: '0750'
owner: 'root'
Expand Down
9 changes: 9 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
---
- include: preflight.yml
tags:
- restic_install
- restic_configure

- include: install.yml
become: true
tags:
- restic_install

- include: configure.yml
become: true
tags:
- restic_configure
12 changes: 8 additions & 4 deletions tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
restic_version: "{{ _latest_release.json.tag_name[1:] }}"
when: restic_version == "latest"

- name: "Get checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture"
- name: Get checksum list from github
set_fact:
_checksums: "{{ lookup('url', 'https://github.com/restic/restic/releases/download/v' + restic_version + '/SHA256SUMS', wantlist=True) | list }}"
run_once: true

- name: "Get checksum for {{ go_arch }} architecture"
set_fact:
restic_checksum: "{{ item.split(' ')[0] }}"
with_items:
- "{{ lookup('url', 'https://github.com/restic/restic/releases/download/v' + restic_version + '/SHA256SUMS', wantlist=True) | list }}"
when: "('restic_' + restic_version + '_linux_' + (go_arch_map[ansible_architecture] | default(ansible_architecture)) + '.bz2') in item"
with_items: "{{ _checksums }}"
when: "('restic_' + restic_version + '_linux_' + go_arch + '.bz2') in item"
7 changes: 3 additions & 4 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ansible-lint>=3.4.0
docker
jmespath
molecule>=2.15.0
pytest==3.9.3
docker
ansible-lint>=3.4.0
testinfra>=1.7.0
jmespath
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ go_arch_map:
aarch64: arm64
armv7l: arm
armv6l: arm

go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"

0 comments on commit 71b368d

Please sign in to comment.