diff options
| -rw-r--r-- | group_vars/all.yml.example | 6 | ||||
| -rw-r--r-- | roles/gpg/meta/argument_specs.yml | 7 | ||||
| -rw-r--r-- | roles/gpg/tasks/main.yml | 12 |
3 files changed, 24 insertions, 1 deletions
diff --git a/group_vars/all.yml.example b/group_vars/all.yml.example index 5fc30d82..1550b397 100644 --- a/group_vars/all.yml.example +++ b/group_vars/all.yml.example @@ -6,6 +6,12 @@ user_public_keys: network_wifi_ssid: "TEST_WIFI_SSID" network_wifi_pass: "TEST_WIFI_PASS" ssh_port: 39901 +gpg_public_keys: + - | + -----BEGIN PGP PUBLIC KEY BLOCK----- + + generate using: gpg --export --armor keyID + -----END PGP PUBLIC KEY BLOCK----- timezone: "UTC" diff --git a/roles/gpg/meta/argument_specs.yml b/roles/gpg/meta/argument_specs.yml index 040853f6..f02299bc 100644 --- a/roles/gpg/meta/argument_specs.yml +++ b/roles/gpg/meta/argument_specs.yml @@ -3,4 +3,9 @@ argument_specs: main: short_description: "Install gpg and pinentry packages" description: "Install gpg and pinentry packages" - options: {} + options: + gpg_public_keys: + type: "list" + elements: "str" + required: false + description: "List of GPG public keys (ASCII armored) to import" diff --git a/roles/gpg/tasks/main.yml b/roles/gpg/tasks/main.yml index c16ec636..6419d88d 100644 --- a/roles/gpg/tasks/main.yml +++ b/roles/gpg/tasks/main.yml @@ -7,3 +7,15 @@ ansible.builtin.package: name: "{{ gpg_packages }}" state: "present" + +- name: "Import GPG public keys" + ansible.builtin.shell: | + set -euo pipefail + echo "{{ item }}" | gpg --import + args: + executable: /bin/bash + loop: "{{ gpg_public_keys }}" + when: gpg_public_keys is defined + register: gpg_import_result + changed_when: "'imported' in gpg_import_result.stderr" + failed_when: gpg_import_result.rc != 0 and 'already in secret keyring' not in gpg_import_result.stderr |
