lookup using computed path?

21 views
Skip to first unread message

Roy Smith

unread,
Jan 4, 2015, 12:05:00 PM1/4/15
to ansible...@googlegroups.com
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?


--
Roy Smith

Timothy Gerla

unread,
Jan 4, 2015, 2:03:35 PM1/4/15
to ansible-project
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/BA7D579C-CE60-4162-ADD3-F59FA4BFBDA8%40panix.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages