---
- name: Ensure .gnupg config directory exists with right permissions
  become: true
  file: dest={{ gpg_home }}/.gnupg state=directory mode=0700 owner="{{ rootUser }}"

## Note: matching on realname or email doesn't allow to create multiple keys. alternative?
- name: check existing secret key
  shell: "gpg --list-secret-keys | grep '{{ gpg_realname }}'"
  changed_when: false
  ignore_errors: true
  become: yes
  become_user: "{{ rootUser }}"
  register: gpgkeys

- include: gpg-gen-key.yaml
  when: gpgkeys.stdout_lines|length < 1
