]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blame - roles/gnupg/tasks/main.yml
Cleanup item loop controls
[perso/Immae/Config/Ansible.git] / roles / gnupg / tasks / main.yml
CommitLineData
397c4fed 1---
587b6dd6
IB
2- name: Config dirs
3 file:
4 state: directory
e1c588d3 5 path: "$XDG_CONFIG_HOME/{{ item }}"
587b6dd6
IB
6 mode: 0700
7 loop:
8 - gnupg
397c4fed 9- name: Config files
eac82f28 10 copy:
e1c588d3
IB
11 src: "gnupg/{{ item }}"
12 dest: "$XDG_CONFIG_HOME/gnupg/{{ item }}"
eac82f28
IB
13 loop:
14 - gpg-agent.conf
15 - gpg.conf
397c4fed 16- name: Get gnupg runtime folder name
b6984948 17 shell: 'gpgconf --list-dirs socketdir | sed -e "s@$XDG_RUNTIME_DIR/gnupg/@@"'
397c4fed 18 register: gnupg_runtime_dir_cmd
b6984948 19 changed_when: false
d03cede6 20 check_mode: no
b6984948
IB
21- name: check existing secret key
22 shell: "gpg --list-secret-keys | grep '{{ gpg_useremail }}'"
23 changed_when: false
24 ignore_errors: true
25 register: gpgkeys
d03cede6 26 check_mode: no
cf86d448
IB
27- name: Ask for gpg password
28 when: gpgkeys.stdout == ""
29 block:
30 - name: Ask for gpg password
31 pause:
32 prompt: "Chose gpg password"
33 echo: false
34 register: gpg_password
35 - name: Confirm gpg password
36 pause:
37 prompt: "Confirm gpg password"
38 echo: false
39 register: gpg_password_confirm
40 - name: check gpg password
41 assert:
42 that: gpg_password_confirm.user_input == gpg_password.user_input
43- name: Generate gpg key
44 when: gpgkeys.stdout == ""
45 block:
46 - name: Copy default template for gpg key generation
47 template:
48 src: gen-key-script.j2
49 dest: "$XDG_CONFIG_HOME/gnupg/gen-key-script-{{ gpg_user }}"
50 mode: 0600
51 no_log: true
52 - name: Generate gpg key
53 command: "gpg --batch --gen-key $XDG_CONFIG_HOME/gnupg/gen-key-script-{{ gpg_user }}"
54 register: genkey
55 always:
56 - name: Remove template file
57 file:
58 path: "$XDG_CONFIG_HOME/gnupg/gen-key-script-{{ gpg_user }}"
59 state: absent
b6984948
IB
60- name: get keygrip
61 shell: "gpg -K --with-colons {{ gpg_useremail }} | grep '^grp' | cut -d':' -f10"
62 register: keygrip
cf86d448 63 when: gpgkeys.stdout == ""
b6984948
IB
64 notify:
65 - notify add key to immae@immae.eu
66 - send key to immae@immae.eu
67 - notify add key to password store
eac82f28 68- meta: flush_handlers
b6984948
IB
69- name: add keygrip to sshcontrol
70 lineinfile:
71 line: "{{ keygrip.stdout }}"
72 insertafter: EOF
73 dest: "$XDG_CONFIG_HOME/gnupg/sshcontrol"
74 create: true
75 state: present
76 when: keygrip is defined and "stdout" in keygrip and keygrip.stdout != ""
77 notify:
78 - restart gpg-agent
eac82f28 79- meta: flush_handlers
cf86d448
IB
80- name: Override the gpg socket directory
81 block:
82 - name: Add systemd overrides
83 template:
e1c588d3
IB
84 src: "systemd/{{ item }}.conf.j2"
85 dest: "$XDG_CONFIG_HOME/systemd/user/{{ item }}.socket.d/override.conf"
cf86d448
IB
86 register: results
87 loop:
88 - dirmngr
89 - gpg-agent
90 - gpg-agent-browser
91 - gpg-agent-extra
92 - gpg-agent-ssh
93 - name: Restart systemd units
94 systemd:
95 daemon_reload: true
96 scope: user
97 state: restarted
e1c588d3 98 name: "{{ item }}.socket"
cf86d448 99 loop: "{{ results.results|selectattr('changed')|map(attribute='item')|list }}"