# lookup using computed path?

**URL:** <https://forum.ansible.com/t/lookup-using-computed-path/17179>\
**Category:** Ansible Project\
**Created:** [January 4, 2015, 5:04pm UTC](https://forum.ansible.com/t/lookup-using-computed-path/17179 "2015-01-04T17:04:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy\_Smith](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Roy\_Smith](https://forum.ansible.com/u/Roy_Smith)\
**Post date:** [January 4, 2015, 5:04pm UTC](https://forum.ansible.com/t/lookup-using-computed-path/17179/1 "2015-01-04T17:04:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Timothy\_Gerla](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Timothy\_Gerla](https://forum.ansible.com/u/Timothy_Gerla)\
**Post date:** [January 4, 2015, 7:03pm UTC](https://forum.ansible.com/t/lookup-using-computed-path/17179/2 "2015-01-04T19:03:11Z")

</div>

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](http://docs.ansible.com/playbooks_variables.html)) to resolve the path.

-Tim
