From 383abb4458972903604b30257db2ad6448da1a36 Mon Sep 17 00:00:00 2001 From: jreichmann Date: Thu, 2 May 2019 19:51:20 +0200 Subject: [PATCH] Use the latest version of the agent file, externalize common strings into var in defaults --- roles/gnupg/defaults/main.yml | 2 ++ roles/gnupg/files/gnupg_agent | 14 -------------- roles/gnupg/tasks/main.yml | 15 ++++++++++----- roles/gnupg/templates/gnupg_agent.j2 | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 19 deletions(-) delete mode 100755 roles/gnupg/files/gnupg_agent diff --git a/roles/gnupg/defaults/main.yml b/roles/gnupg/defaults/main.yml index 4687fc3..2ca58dc 100644 --- a/roles/gnupg/defaults/main.yml +++ b/roles/gnupg/defaults/main.yml @@ -5,3 +5,5 @@ gpg_cache_ttl_ssh: 300 # Array of all keygrips to pass to sshcontrol gpg_keygrips: [] +gpg_folder: "~/.gnupg" + diff --git a/roles/gnupg/files/gnupg_agent b/roles/gnupg/files/gnupg_agent deleted file mode 100755 index 1de5761..0000000 --- a/roles/gnupg/files/gnupg_agent +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -rc=$(pgrep gpg-agent) -if [ "$rc" != 0 ]; then - export GPG_AGENT_INFO - export SSH_AUTH_SOCK - export SSH_AGENT_PID -else - eval $(gpg-agent --daemon) -fi - -gpg-connect-agent /bye -export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) - diff --git a/roles/gnupg/tasks/main.yml b/roles/gnupg/tasks/main.yml index 65b2599..590ab04 100644 --- a/roles/gnupg/tasks/main.yml +++ b/roles/gnupg/tasks/main.yml @@ -16,21 +16,26 @@ - name: Configure gpg.conf (behaviour of gpg) template: src: gpg.conf.j2 - dest: ~/.gnupg/gpg.conf + dest: "(( gpg_folder ))/gpg.conf" - name: Configure gpg-agent.conf (agent configuration) template: src: gpg-agent.conf.j2 - dest: ~/.gnupg/gpg-agent.conf + dest: "(( gpg_folder }}/gpg-agent.conf" - name: Configure ssh-control (in order for gpg-agent to act as ssh-agent) template: src: sshcontrol.j2 - dest: ~/.gnupg/sshcontrol + dest: "{{ gpg_folder }}/sshcontrol" - name: Copy gnupg_agent script, which makes gpg-agent responsible for ssh-auth copy: - src: "{{ role_path }}/files/gpg_agent" - dest: ~/.gnupg/gpg_agent + src: gpg_agent.j2 + dest: "{{ gpg_folder }}/gpg_agent" mode: 0700 + + + + + diff --git a/roles/gnupg/templates/gnupg_agent.j2 b/roles/gnupg/templates/gnupg_agent.j2 index e69de29..1de5761 100644 --- a/roles/gnupg/templates/gnupg_agent.j2 +++ b/roles/gnupg/templates/gnupg_agent.j2 @@ -0,0 +1,14 @@ +#!/bin/bash + +rc=$(pgrep gpg-agent) +if [ "$rc" != 0 ]; then + export GPG_AGENT_INFO + export SSH_AUTH_SOCK + export SSH_AGENT_PID +else + eval $(gpg-agent --daemon) +fi + +gpg-connect-agent /bye +export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) +