summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
Diffstat (limited to 'roles')
-rw-r--r--roles/gnupg/handlers/main.yml15
-rw-r--r--roles/gnupg/tasks/main.yml62
-rw-r--r--roles/gnupg/templates/gen-key-script.j26
-rw-r--r--roles/init/tasks/main.yml1
-rw-r--r--roles/tools/tasks/main.yml5
5 files changed, 88 insertions, 1 deletions
diff --git a/roles/gnupg/handlers/main.yml b/roles/gnupg/handlers/main.yml
new file mode 100644
index 0000000..d32d321
--- /dev/null
+++ b/roles/gnupg/handlers/main.yml
@@ -0,0 +1,15 @@
1---
2- name: restart gpg-agent
3 systemd:
4 state: restarted
5 name: gpg-agent.service
6 scope: user
7- name: notify add key to immae@immae.eu
8 pause:
9 prompt: "gpg key will be sent to immae.eu, please login to tmux and give passwords there."
10 seconds: 3
11- name: send key to immae@immae.eu
12 shell: "gpg --armor --export ismael@flony | ssh immae@immae.eu add_workstation_key | gpg --import -"
13- name: notify add key to password store
14 pause:
15 prompt: "Please add the key to the password store and push: pass init -p Folder/Folder <key> <key>. Press key when done"
diff --git a/roles/gnupg/tasks/main.yml b/roles/gnupg/tasks/main.yml
index 8adaf69..d1289f5 100644
--- a/roles/gnupg/tasks/main.yml
+++ b/roles/gnupg/tasks/main.yml
@@ -12,8 +12,64 @@
12 state: directory 12 state: directory
13 mode: 0700 13 mode: 0700
14- name: Get gnupg runtime folder name 14- name: Get gnupg runtime folder name
15 shell: 'GNUPGHOME=$XDG_CONFIG_HOME/gnupg gpgconf --list-dirs socketdir | sed -e "s@$XDG_RUNTIME_DIR/gnupg/@@"' 15 shell: 'gpgconf --list-dirs socketdir | sed -e "s@$XDG_RUNTIME_DIR/gnupg/@@"'
16 register: gnupg_runtime_dir_cmd 16 register: gnupg_runtime_dir_cmd
17 changed_when: false
18- name: check existing secret key
19 shell: "gpg --list-secret-keys | grep '{{ gpg_useremail }}'"
20 changed_when: false
21 ignore_errors: true
22 register: gpgkeys
23- name: ask for gpg password
24 pause:
25 prompt: "Chose gpg password"
26 echo: false
27 register: gpg_password
28 when: gpgkeys is defined and "stdout" in gpgkeys and gpgkeys.stdout == ""
29- name: confirm gpg password
30 pause:
31 prompt: "Confirm gpg password"
32 echo: false
33 register: gpg_password_confirm
34 when: gpgkeys is defined and "stdout" in gpgkeys and gpgkeys.stdout == ""
35- name: check gpg password
36 assert:
37 that: gpg_password_confirm.user_input == gpg_password.user_input
38 when: gpgkeys is defined and "stdout" in gpgkeys and gpgkeys.stdout == ""
39- name: copy default template for gpg key generation
40 template:
41 src: gen-key-script.j2
42 dest: "$XDG_CONFIG_HOME/gnupg/gen-key-script-{{ gpg_user }}"
43 mode: 0600
44 no_log: true
45 when: gpgkeys is defined and "stdout" in gpgkeys and gpgkeys.stdout == ""
46- name: generate gpg key
47 command: "gpg --batch --gen-key $XDG_CONFIG_HOME/gnupg/gen-key-script-{{ gpg_user }}"
48 when: gpgkeys is defined and "stdout" in gpgkeys and gpgkeys.stdout == ""
49 register: genkey
50- name: remove template file
51 file:
52 path: "$XDG_CONFIG_HOME/gnupg/gen-key-script-{{ gpg_user }}"
53 state: absent
54 when: gpgkeys is defined and "stdout" in gpgkeys and gpgkeys.stdout == ""
55- name: get keygrip
56 shell: "gpg -K --with-colons {{ gpg_useremail }} | grep '^grp' | cut -d':' -f10"
57 register: keygrip
58 when: gpgkeys is defined and "stdout" in gpgkeys and gpgkeys.stdout == ""
59 notify:
60 - notify add key to immae@immae.eu
61 - send key to immae@immae.eu
62 - notify add key to password store
63- name: add keygrip to sshcontrol
64 lineinfile:
65 line: "{{ keygrip.stdout }}"
66 insertafter: EOF
67 dest: "$XDG_CONFIG_HOME/gnupg/sshcontrol"
68 create: true
69 state: present
70 when: keygrip is defined and "stdout" in keygrip and keygrip.stdout != ""
71 notify:
72 - restart gpg-agent
17- name: Add systemd overrides 73- name: Add systemd overrides
18 template: 74 template:
19 src: "systemd/{{ item }}.conf.j2" 75 src: "systemd/{{ item }}.conf.j2"
@@ -32,3 +88,7 @@
32 state: restarted 88 state: restarted
33 name: "{{ item }}.socket" 89 name: "{{ item }}.socket"
34 loop: "{{ results.results|selectattr('changed')|map(attribute='item')|list }}" 90 loop: "{{ results.results|selectattr('changed')|map(attribute='item')|list }}"
91- name: clone password store
92 register: clone_password_store
93 shell: "cd $(dirname $ANSIBLE_CONFIG ); git submodule update --init password_store"
94 changed_when: clone_password_store is defined and "stdout" in clone_password_store and clone_password_store.stdout != ""
diff --git a/roles/gnupg/templates/gen-key-script.j2 b/roles/gnupg/templates/gen-key-script.j2
new file mode 100644
index 0000000..0687068
--- /dev/null
+++ b/roles/gnupg/templates/gen-key-script.j2
@@ -0,0 +1,6 @@
1Key-Type: RSA
2Key-Length: 4096
3Key-Usage: cert encrypt auth
4Name-Real: {{ gpg_realname }}
5Name-Email: {{ gpg_useremail }}
6Passphrase: {{ gpg_password.user_input }}
diff --git a/roles/init/tasks/main.yml b/roles/init/tasks/main.yml
index 1baec91..edbd820 100644
--- a/roles/init/tasks/main.yml
+++ b/roles/init/tasks/main.yml
@@ -1,6 +1,7 @@
1--- 1---
2- name: Get gnupg runtime folder name 2- name: Get gnupg runtime folder name
3 shell: 'GNUPGHOME=$XDG_CONFIG_HOME/gnupg gpgconf --list-dirs socketdir | sed -e "s@$XDG_RUNTIME_DIR/gnupg/@@"' 3 shell: 'GNUPGHOME=$XDG_CONFIG_HOME/gnupg gpgconf --list-dirs socketdir | sed -e "s@$XDG_RUNTIME_DIR/gnupg/@@"'
4 changed_when: false
4 register: gnupg_runtime_dir_cmd 5 register: gnupg_runtime_dir_cmd
5- name: Add pam_environment 6- name: Add pam_environment
6 register: pam_environment 7 register: pam_environment
diff --git a/roles/tools/tasks/main.yml b/roles/tools/tasks/main.yml
index aa61aab..fe5b023 100644
--- a/roles/tools/tasks/main.yml
+++ b/roles/tools/tasks/main.yml
@@ -46,3 +46,8 @@
46 dest: $XDG_CONFIG_HOME/systemd/user/ 46 dest: $XDG_CONFIG_HOME/systemd/user/
47 notify: 47 notify:
48 - reload systemd 48 - reload systemd
49- name: Link password store
50 file:
51 path: "$XDG_DATA_HOME/pass"
52 src: "$XDG_CONFIG_HOME/ansible/password_store"
53 state: link