Interpolation in Jinja2 default() values

42 views
Skip to first unread message

Mike Dillon

unread,
Sep 3, 2015, 1:02:00 PM9/3/15
to Ansible Project

I'd like to do something like the following, but I couldn't find anything in the docs or on the mailing list that made it clear whether this should be possible or not:

---
- name: add user keys from GitHub
  authorized_key:
    user: "{{item.user}}"
    key: "{{item.ssh_public_key | default(\"https://github.myenterprise.com/{{item.user}}.keys\")}}"
  with_items: users

When I tried to do this, I got an error message about not being able to fetch the key:

msg: Error getting key from: https://github.myenterprise.com/{# item.user #}.keys

I tried both escaping the default value with \" and using ', but got the same error each time.


Thanks!


-md

Brian Coca

unread,
Sep 3, 2015, 1:03:13 PM9/3/15
to Ansible Project
no mustache stacking!!!!

key: "{{item.ssh_public_key |
default('https://github.myenterprise.com/' + item.user + '.keys')}}"



--
Brian Coca

Mike Dillon

unread,
Sep 8, 2015, 7:03:50 PM9/8/15
to Ansible Project
Thanks Brian! For some reason I didn't get a notification for your response, so sorry for the delay.

-md
Reply all
Reply to author
Forward
0 new messages