I need to install my ssh public key on a host. I’ve got my public key checked into my source tree. I don’t want to hard-wire the location of my source tree, so I use lookup(‘pipe’, ‘hg root’) to find the root of my tree and all my file references are relative to that. So, I’ve got something like
vars:
local_base_dir: “{{ lookup(‘pipe’, ‘hg root’) }}/…”
path: “{{ local_base_dir }}/source/deploy/ansible/id_rsa.pub”
ssh_key: “{{ lookup(‘file’, path) }}”
tasks:
- name: add authorized ssh keys
sudo: yes
authorized_key: user=xxx key=“{{ ssh_key }}”
This works, but it seems needlessly complicated. Is there some way to avoid having to generate the temporary path and ssh_key variables?