Skip to content

Commit

Permalink
accept ssh key contents, rather than file patsh
Browse files Browse the repository at this point in the history
  • Loading branch information
dylancwood committed Oct 30, 2015
1 parent 021f81a commit 4666656
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Here is a list of tricky variables with a detailed description:

* **barman_group** is the primary group name to be assigned to the `barman_user` (optional)`

* **barman_ssh_private_key_path** is the pathname to a file containing the private ssh key to be installed for the barman user. (optional)
* **barman_ssh_private_key** is the private ssh key to be installed for the barman user. (optional)

* **barman_ssh_public_key_path** is the pathname to a file containing the public ssh key to be installed for the barman user. (optional)
* **barman_ssh_public_key_path** is the public ssh key to be installed for the barman user. (optional)

* **barman_ssh_authorized_key_path** is the pathname to a file containing the public ssh key to be used by the postgres instance when syncing WAL archives via rsync. This will be appended to the `authorized_keys` file if it exists. (optional)
* **barman_ssh_authorized_key_path** is a list of public ssh keys to be used by the postgres instance when syncing WAL archives via rsync. Each key will be appended to the `authorized_keys` file if it exists. (optional)

* **barman_upstreams** is a list of upstream server specifications. Here is an annotated example:
``` yml
Expand All @@ -43,7 +43,7 @@ barman_upstreams:
backup_cron_interval: '0 0 * * 0' #optional will not run automatic backups if not specified
```
* **barman_pg_pass_content** is the content that should be inserted into the `barman_user`'s .pgpass file. This is the safest way to use md5 or password authentication when connecting to the upstream postgres servers. Look at https://wiki.postgresql.org/wiki/Pgpass for more info. Example:
* **barman_pg_pass_content** is the content that should be inserted into the `barman_user`'s .pgpass file. This is the safest way to use md5 or password authentication when connecting to the upstream postgres servers. Look at https://wiki.postgresql.org/wiki/Pgpass for more info. Example:
```yml
barman_pg_pass_content: "*:*:*:barman_bot:{{ lookup('file', '/path/to/file/containing/password.pwd') }}"
```
Expand Down Expand Up @@ -84,13 +84,15 @@ Example Playbook
- hosts: servers
roles:
- role: dylancwood.ansible-barman
vars:
barman_ssh_private_key_path: "~/.ssh/id_rsa.postgres"
barman_ssh_public_key_path: "~/.ssh/id_rsa.postgres.pub"
barman_ssh_authorized_keys_path: "~/.ssh/id_rsa.postgres.pub"
vars:
barman_ssh_private_key: "..."
barman_ssh_public_key: "{{ lookup('file', 'path/to/key.pub') }}"
barman_ssh_authorized_keys:
- "{{ lookup('file', 'path/to/key.pub') }}"
- "{{ lookup('file', 'path/to/key2.pub') }}"
barman_pg_pass_content: "*:*:*:barman_bot:{{ lookup('file', '/secret/path/to/barman_bot.pwd') }}"
barman_backup_options: concurrent_backup
barman_upstreams:
barman_backup_options: concurrent_backup
barman_upstreams:
- name: 'productiondb'
description: 'Production Database: be careful'
hostname: 'productiondb.example.com'
Expand All @@ -101,7 +103,7 @@ Example Playbook
```

Note that the `postgres_user` matches the username section of the `barman_pg_pass_content` var.


License
-------
Expand All @@ -112,4 +114,3 @@ Author Information
------------------

Feel free to reach out via Github Issues or Pull Requests

12 changes: 6 additions & 6 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ barman_home: /var/lib/barman
# This user will be used to create the barman_home dir if it doesn't exist
barman_home_creation_user: root
barman_user: barman
barman_uid:
barman_uid:
barman_groups: "{{barman_user}}"
barman_group: "{{barman_user}}"
barman_ssh_private_key_path:
barman_ssh_public_key_path:
barman_ssh_authorized_key_path:
barman_ssh_private_key:
barman_ssh_public_key:
barman_ssh_authorized_keys: #list of strings
barman_pg_pass_content:
barman_log_file: /var/log/barman/barman.log
barman_compression: None
Expand All @@ -21,15 +21,15 @@ barman_configuration_files_directory: /etc/barman.d
barman_minimum_redundancy: 0
barman_retention_policy: ""
barman_bandwidth_limit: 0
barman_immediate_checkpoint: false
barman_imm ediate_checkpoint: false
barman_network_compression: false
barman_backup_options: exclusive_backup
barman_basebackup_retry_times: 0
barman_basebackup_retry_sleep: 30
barman_last_backup_maximum_age: ""
barman_upstreams: []
# Example barman upstream (default values used)
# barman_upstreams:
# barman_upstreams:
# - name: main
# description: 'Main PG server'
# hostname: prod_db.example.com
Expand Down
19 changes: 10 additions & 9 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Barman | Add barman user group
group:
group:
name: '{{barman_group}}'
gid: '{{barman_uid}}'

- name: Barman | Add barman user
user:
user:
name: '{{barman_user}}'
uid: '{{barman_uid}}'
groups: '{{barman_groups}}'
Expand All @@ -21,27 +21,28 @@

- name: Barman | Add barman id_rsa
copy:
src: '{{barman_ssh_private_key_path}}'
dest: /home/{{barman_user}}/.ssh/id_rsa
content: '{{ barman_ssh_private_key }}'
dest: /home/{{barman_user}}/.ssh/id_rsa
owner: '{{barman_user}}'
group: '{{barman_group}}'
mode: 0600
when: barman_ssh_private_key_path
when: barman_ssh_private_key

- name: Barman | Add barman id_rsa.pub
copy:
src: '{{barman_ssh_public_key_path}}'
content: '{{ barman_ssh_public_key }}'
dest: /home/{{barman_user}}/.ssh/id_rsa.pub
owner: '{{barman_user}}'
group: '{{barman_group}}'
mode: 0644
when: barman_ssh_public_key_path
when: barman_ssh_public_key

- name: Barman | Add barman authorized_key
authorized_key:
key: "{{ lookup('file', {{barman_ssh_authorized_key_path}}) }}"
key: "{{ item }}"
user: '{{barman_user}}'
when: barman_ssh_authorized_key_path
when: barman_ssh_authorized_keys
with_items: barman_ssh_authorized_keys

- name: Barman | Add .pgpass file
copy:
Expand Down

0 comments on commit 4666656

Please sign in to comment.