lookup using computed path?

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?

You could certainly do this all in one expression:

{{ lookup(‘file’, lookup(‘pipe’, ‘hg root’) + ‘…/source/deploy/ansible/id_rsa.pub’) }}

Or if you could find the pub key file relative to the location of the playbook instead, use the playbook_dir magic variable (http://docs.ansible.com/playbooks_variables.html) to resolve the path.

-Tim