# Struggling with optional arguments to a playbook

**URL:** <https://forum.ansible.com/t/struggling-with-optional-arguments-to-a-playbook/24576>\
**Category:** Ansible Project\
**Created:** [May 25, 2017, 1:20pm UTC](https://forum.ansible.com/t/struggling-with-optional-arguments-to-a-playbook/24576 "2017-05-25T13:20:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Brooks](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Martin\_Brooks](https://forum.ansible.com/u/Martin_Brooks)\
**Post date:** [May 25, 2017, 1:20pm UTC](https://forum.ansible.com/t/struggling-with-optional-arguments-to-a-playbook/24576/1 "2017-05-25T13:20:04Z")

</div>

Hello

I have a simple playbook that distributes my SSH key. I tried to make a more generic version of the playbook that would accept arguments via -e so that the same playbook could distribute either a different key or a key for a different user. This is what I have so far:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 25, 2017, 4:29pm UTC](https://forum.ansible.com/t/struggling-with-optional-arguments-to-a-playbook/24576/2 "2017-05-25T16:29:24Z")

</div>

rule #1 of templating: moustaches do not stack!

you cannot have {{ }} inside {{ }}. rewrite as:

username: "{{ username if username is defined else ansible\_user\_id }}"

or

username: {{ username|default(ansible\_user\_id) }}

or

vars\_prompt:  
&nbsp;&nbsp;&nbsp;name: username  
&nbsp;&nbsp;&nbsp;default: "{{ansible\_user\_id}}

^ vars prompt is automatically overridden by -e.

---

<div class="post-metadata">

**Author:** ![Martin\_Brooks](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Martin\_Brooks](https://forum.ansible.com/u/Martin_Brooks)\
**Post date:** [May 25, 2017, 5:48pm UTC](https://forum.ansible.com/t/struggling-with-optional-arguments-to-a-playbook/24576/3 "2017-05-25T17:48:29Z")

</div>

Thanks for that. I eventually managed to get it working via this method:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 25, 2017, 7:00pm UTC](https://forum.ansible.com/t/struggling-with-optional-arguments-to-a-playbook/24576/4 "2017-05-25T19:00:19Z")

</div>

you are still stacking:

ssh\_public\_key: "{{ lookup('file', '{{ keyfile }}') }}"

should be:

ssh\_public\_key: "{{ lookup('file', keyfile) }}"
