---
- name: Install gnupg
  pacman:
    name: gnupg
    state: present

- name: Enable gpg-agent.socket
  systemd:
    name: gpg-agent.socket
    scope: user
    enabled: yes
    state: started
  become: yes
  become_user: "{{ user.name }}"
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}"
  when: gnupg.enable_agent == True

- name: Enable dirmngr.socket
  systemd:
    name: dirmngr.socket
    scope: user
    enabled: yes
    state: started
  become: yes
  become_user: "{{ user.name }}"
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}"
  when: gnupg.enable_agent == True

- name: Enable gpg-agent-ssh.socket
  systemd:
    name: gpg-agent-ssh.socket
    scope: user
    enabled: yes
    state: started
  become: yes
  become_user: "{{ user.name }}"
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}"
  when: gnupg.enable_agent == True and gnupg.emulate_ssh == True
