I’d like to create a user and import a GPG key into its GPG keychain. I thought the easiest way to do this would be to impersonate him, so the configuration and key files created by the gpg tool have the right onwership and permissions. My playbook steps look like this:
- name: Create backup user
user: name={{ backup_user }} groups={{ backup_group }} append=yes - name: Copy public key
copy:
src: files/some_public_key.asc
dest: /home/{{ backup_user}}/some_public_key.asc
owner: “{{ backup_user }}” - name: Import public key
shell: gpg --import /home/{{ backup_user}}/some_public_key.asc
chdir: /home/{{ backup_user}}/
become: yes
become_user: “{{ backup_user }}”
However, I’m getting a “Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user” error message.
As a workaround I could call the gpg command a s a privileged user and later change the ownership of the .gnupg directory, but that feels kind of odd. Is there a better way to do this?