Struggling with optional arguments to a playbook

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:

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:
   name: username
   default: "{{ansible_user_id}}

^ vars prompt is automatically overridden by -e.

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

you are still stacking:

ssh_public_key: "{{ lookup('file', '{{ keyfile }}') }}"

should be:

ssh_public_key: "{{ lookup('file', keyfile) }}"