summaryrefslogtreecommitdiffstats
path: root/modules/borgmatic/manifests/init.pp
blob: 7b409d664b01d376d8903a5c39b9dcfa53de3d5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class borgmatic($host = 'partofme', $extra_paths = []) {
  package { 'borgmatic':
    ensure => installed;
  }

  $current_hostname = "${facts['networking']['hostname']}"
  $borgmatic_host = $host
  $borgmatic_passphrase = secret::value('borgmatic_passphrase')
  $escaped_borgmatic_passphrase = regsubst($borgmatic_passphrase, "'", "''", 'G')
  file {
    "/etc/borgmatic":
      ensure => directory;
    "/etc/borgmatic/config.yaml":
      content => template('borgmatic/config.yaml'),
      require => File["/etc/borgmatic"];
  }

  secret { "/etc/borgmatic/borg_ssh_key":
    source => 'borg_ssh_key',
    require => File["/etc/borgmatic"];
  }

  exec { '/usr/bin/borgmatic init --encryption repokey':
    environment => [
      "BORG_PASSPHRASE=${borgmatic_passphrase}",
    ],
    unless => '/usr/bin/borgmatic info --archive latest > /dev/null',
    require => [
      Package['borgmatic'],
      File['/etc/borgmatic/config.yaml'],
      File['/etc/borgmatic/borg_ssh_key'],
    ]
  }

  service { 'borgmatic.timer':
    ensure => running,
    enable => true,
    require => [
      Package['borgmatic'],
      File['/etc/borgmatic/config.yaml'],
      Exec['/usr/bin/borgmatic init --encryption repokey'],
    ];
  }
}