2019-06-21 00:03:22 +02:00
|
|
|
- name: Check name of gpg2 binary
|
2017-08-15 00:19:40 +02:00
|
|
|
command: which gpg2
|
|
|
|
register: gpg2_check
|
|
|
|
ignore_errors: true
|
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
- name: Set gpg2 binary name
|
2017-08-15 00:19:40 +02:00
|
|
|
set_fact:
|
2017-11-27 23:58:08 +01:00
|
|
|
gpg2_bin: '{{ "gpg2" if gpg2_check is successful else "gpg" }}'
|
2017-08-15 00:19:40 +02:00
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
- name: Stop gpg-agent so we can remove any locks on the GnuPG dir
|
|
|
|
command: gpgconf --kill gpg-agent
|
|
|
|
ignore_errors: yes
|
2017-08-15 00:19:40 +02:00
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
- name: Remove previous password files and directory
|
|
|
|
file:
|
|
|
|
dest: "{{ item }}"
|
|
|
|
state: absent
|
|
|
|
loop:
|
|
|
|
- "~/.gnupg"
|
|
|
|
- "~/.password-store"
|
2017-08-15 00:19:40 +02:00
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
# How to generate a new GPG key:
|
|
|
|
# gpg2 --batch --gen-key input # See templates/input
|
|
|
|
# gpg2 --list-secret-keys --keyid-format LONG
|
|
|
|
# gpg2 --armor --export-secret-keys [key id]
|
|
|
|
# # Get the fingerprint
|
|
|
|
# gpg2 --fingerprint --keyid-format LONG | grep [key id] -A 1 | tail -1 | tr -d '[:space:]' | awk -F '=' '{print $2":6:"}'
|
2017-08-15 00:19:40 +02:00
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
- name: Import GPG private key
|
|
|
|
shell: echo "{{ passwordstore_privkey }}" | {{ gpg2_bin }} --import --allow-secret-key-import -
|
2017-08-15 00:19:40 +02:00
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
- name: Trust key
|
|
|
|
shell: echo "D3E1CC8934E97270CEB066023AF1BD3619AB496A:6:" | {{ gpg2_bin }} --import-ownertrust
|
|
|
|
|
|
|
|
- name: Initialise passwordstore
|
|
|
|
command: pass init ansible-test
|
|
|
|
|
|
|
|
- name: Create a password
|
2017-08-15 00:19:40 +02:00
|
|
|
set_fact:
|
|
|
|
newpass: "{{ lookup('passwordstore', 'test-pass length=8 create=yes') }}"
|
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
- name: Fetch password from an existing file
|
2017-08-15 00:19:40 +02:00
|
|
|
set_fact:
|
|
|
|
readpass: "{{ lookup('passwordstore', 'test-pass') }}"
|
|
|
|
|
2019-06-21 00:03:22 +02:00
|
|
|
- name: Verify password
|
2017-08-15 00:19:40 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2019-06-21 00:03:22 +02:00
|
|
|
- readpass == newpass
|