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

Commit 71b368d

Browse files
committed
Propagate changes from cloudalchemy roles (#52)
* 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
1 parent b264be2 commit 71b368d

13 files changed

+113
-18
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ env:
88
- ANSIBLE=2.5
99
- ANSIBLE=2.6
1010
- ANSIBLE=2.7
11+
matrix:
12+
fast_finish: true
1113
install:
1214
- pip install tox-travis git-semver
1315
script:
14-
- tox
16+
- ./.travis/test.sh
1517
deploy:
1618
provider: script
1719
skip_cleanup: true

.travis/test.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
4+
tox -- molecule test --all
5+
else
6+
tox -- molecule test -s default --destroy always
7+
tox -- molecule test -s alternative --destroy never
8+
fi

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ For example, if you have a restic repository named `testrepo`, you could use the
5959
Use it in a playbook as follows:
6060
```yaml
6161
- hosts: all
62-
become: yes
6362
roles:
6463
- paulfantom.restic
6564
```

molecule/alternative/playbook.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
roles:
66
- ansible-restic
77
vars:
8-
restic_version: 'latest'
98
restic_user: restic
109
restic_group: restic
1110
restic_install_path: "/opt"

molecule/default/playbook.yml

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
roles:
66
- ansible-restic
77
vars:
8-
restic_user: restic
9-
restic_group: restic
108
restic_repos:
119
- name: local-example
1210
url: "/tmp/restic"

molecule/latest/molecule.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
lint:
7+
name: yamllint
8+
platforms:
9+
- name: stretch
10+
image: paulfantom/debian-molecule:9
11+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
12+
privileged: true
13+
volumes:
14+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
15+
- name: fedora
16+
image: paulfantom/fedora-molecule:27
17+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
18+
privileged: true
19+
volumes:
20+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
21+
provisioner:
22+
name: ansible
23+
lint:
24+
name: ansible-lint
25+
playbooks:
26+
create: ../default/create.yml
27+
prepare: ../default/prepare.yml
28+
converge: playbook.yml
29+
destroy: ../default/destroy.yml
30+
scenario:
31+
name: latest
32+
verifier:
33+
name: testinfra
34+
lint:
35+
name: flake8
36+
enabled: true

molecule/latest/playbook.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
- name: Default use-case scenario
3+
hosts: all
4+
any_errors_fatal: true
5+
roles:
6+
- ansible-restic
7+
vars:
8+
restic_version: latest
9+
restic_user: restic
10+
restic_group: restic
11+
restic_repos:
12+
- name: local-example
13+
url: "/tmp/restic"
14+
password: "correcthorsebatterystaple"
15+
jobs:
16+
- command: 'restic backup /srv'
17+
at: '0 1 * * *'
18+
retention_time: '17 5 * * *'
19+
retention:
20+
last: 2
21+
hourly: 4
22+
weekly: 9
23+
monthly: 3
24+
yearly: 10
25+
tags:
26+
- special
27+
- test
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import testinfra.utils.ansible_runner
3+
4+
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
5+
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
6+
7+
8+
def test_binary(host):
9+
binary = host.file("/usr/local/bin/restic")
10+
assert binary.exists
11+
assert binary.is_file
12+
assert binary.mode == 0o750

tasks/install.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@
4848
- name: Download client binary
4949
become: false
5050
get_url:
51-
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"
52-
dest: "/tmp/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.bz2"
51+
url: "https://github.com/restic/restic/releases/download/v{{ restic_version }}/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch }}.bz2"
52+
dest: "/tmp/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch }}.bz2"
5353
checksum: "sha256:{{ restic_checksum }}"
5454
delegate_to: localhost
5555
run_once: true
5656
check_mode: false
5757

5858
- name: Decompress the binary
5959
become: false
60-
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) }}"
60+
shell: "bzip2 -dc /tmp/restic_{{ restic_version }}_{{ ansible_system | lower }}_{{ go_arch }}.bz2 > /tmp/restic_{{ restic_version }}_{{ go_arch }}"
6161
args:
62-
creates: "/tmp/restic_{{ restic_version }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
62+
creates: "/tmp/restic_{{ restic_version }}_{{ go_arch }}"
6363
delegate_to: localhost
6464
run_once: true
6565
check_mode: false
6666

6767
- name: Propagate restic binary
6868
copy:
69-
src: "/tmp/restic_{{ restic_version }}_{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
69+
src: "/tmp/restic_{{ restic_version }}_{{ go_arch }}"
7070
dest: '{{ restic_install_path }}/restic'
7171
mode: '0750'
7272
owner: 'root'

tasks/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
---
22
- include: preflight.yml
3+
tags:
4+
- restic_install
5+
- restic_configure
36

47
- include: install.yml
8+
become: true
9+
tags:
10+
- restic_install
511

612
- include: configure.yml
13+
become: true
14+
tags:
15+
- restic_configure

tasks/preflight.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
restic_version: "{{ _latest_release.json.tag_name[1:] }}"
2020
when: restic_version == "latest"
2121

22-
- name: "Get checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture"
22+
- name: Get checksum list from github
23+
set_fact:
24+
_checksums: "{{ lookup('url', 'https://github.com/restic/restic/releases/download/v' + restic_version + '/SHA256SUMS', wantlist=True) | list }}"
25+
run_once: true
26+
27+
- name: "Get checksum for {{ go_arch }} architecture"
2328
set_fact:
2429
restic_checksum: "{{ item.split(' ')[0] }}"
25-
with_items:
26-
- "{{ lookup('url', 'https://github.com/restic/restic/releases/download/v' + restic_version + '/SHA256SUMS', wantlist=True) | list }}"
27-
when: "('restic_' + restic_version + '_linux_' + (go_arch_map[ansible_architecture] | default(ansible_architecture)) + '.bz2') in item"
30+
with_items: "{{ _checksums }}"
31+
when: "('restic_' + restic_version + '_linux_' + go_arch + '.bz2') in item"

test-requirements.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
ansible-lint>=3.4.0
2-
docker
3-
jmespath
41
molecule>=2.15.0
5-
pytest==3.9.3
2+
docker
3+
ansible-lint>=3.4.0
64
testinfra>=1.7.0
5+
jmespath

vars/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ go_arch_map:
55
aarch64: arm64
66
armv7l: arm
77
armv6l: arm
8+
9+
go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"

0 commit comments

Comments
 (0)