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

Commit

Permalink
Repository initialization (#10)
Browse files Browse the repository at this point in the history
[minor] Repository initialization
  • Loading branch information
paulfantom authored May 15, 2018
1 parent cc0d374 commit af338a3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ restic_group: "{{ restic_user }}"

restic_install_path: '/usr/local/bin'

restic_initialize_repos: true

restic_repos: []
# restic_repos:
# - name: s3-example
Expand Down
2 changes: 2 additions & 0 deletions molecule/alternative/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
restic_version: 'latest'
restic_user: restic
restic_group: restic
restic_install_path: "/opt"
restic_initialize_repos: false
restic_repos:
- name: s3-example
url: "s3:s3.amazonaws.com/bucket_name/restic"
Expand Down
7 changes: 4 additions & 3 deletions molecule/alternative/tests/test_alternative.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_binary(host):
binary = host.file("/usr/local/bin/restic")
binary = host.file("/opt/restic")
assert binary.exists
assert binary.is_file
assert binary.mode == 0o750
Expand All @@ -22,8 +22,9 @@ def test_cronfiles(host):
assert f.exists
assert f.is_file
assert f.mode == 0o640
with host.sudo():
assert f.contains('RESTIC_PASSWORD="correcthorsebatterystaple"')
# assert f.contains('RESTIC_PASSWORD="correcthorsebatterystaple"')
# # with host.sudo():
# assert f.contains('RESTIC_PASSWORD="correcthorsebatterystaple"')
#
#
# def test_logdir(host):
Expand Down
19 changes: 2 additions & 17 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
restic_user: restic
restic_group: restic
restic_repos:
- name: s3-example
url: "s3:s3.amazonaws.com/bucket_name/restic"
- name: local-example
url: "/tmp/restic"
password: "correcthorsebatterystaple"
remote_credentials:
aws_secret_key_id: "AWS_ACCESS_KEY_ID"
aws_secret_access_key: "AWS_SECRET_ACCESS_KEY"
jobs:
- command: 'restic backup /srv'
at: '0 1 * * *'
Expand All @@ -27,15 +24,3 @@
tags:
- special
- test
- name: backblaze-example
url: "b2:bucketname:path/to/repo"
password: "correcthorsebatterystaple"
remote_credentials:
b2_account_id: "B2_ACCOUNT_ID"
b2_account_key: "B2_ACCOUNT_KEY"
jobs:
- command: 'restic backup /var'
at: '0 4 * * *'
- command: 'restic backup /home'
at: '0 3 * * *'
user: 'restic'
6 changes: 2 additions & 4 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ def test_binary(host):

def test_cronfiles(host):
cronfiles = [
"/etc/cron.d/restic-backblaze-example",
"/etc/cron.d/restic-s3-example"
"/etc/cron.d/restic-local-example"
]
for file in cronfiles:
f = host.file(file)
assert f.exists
assert f.is_file
assert f.mode == 0o640
with host.sudo():
assert f.contains('RESTIC_PASSWORD="correcthorsebatterystaple"')
# assert f.contains('RESTIC_PASSWORD="correcthorsebatterystaple"')
#
#
# def test_logdir(host):
Expand Down
12 changes: 12 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@
mode: '0640'
no_log: true
with_items: '{{ restic_repos }}'
register: _cronfiles

- name: Initialize restic repositories
command: "{{ restic_install_path }}/restic -r {{ item.url }} init"
environment:
RESTIC_PASSWORD: "{{ item.password }}"
no_log: true
ignore_errors: true
with_items: "{{ restic_repos }}"
when:
- _cronfiles is changed
- restic_initialize_repos

0 comments on commit af338a3

Please sign in to comment.