# vars\_prompt in Ansible

**URL:** <https://forum.ansible.com/t/vars-prompt-in-ansible/23691>\
**Category:** Ansible Project\
**Created:** [February 9, 2017, 12:00pm UTC](https://forum.ansible.com/t/vars-prompt-in-ansible/23691 "2017-02-09T12:00:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stepan\_Harutyunyan](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@Stepan\_Harutyunyan](https://forum.ansible.com/u/Stepan_Harutyunyan)\
**Post date:** [February 9, 2017, 12:00pm UTC](https://forum.ansible.com/t/vars-prompt-in-ansible/23691/1 "2017-02-09T12:00:37Z")

</div>

Hi All,

I want to create Ansible script which will create user on linux servers, so I use vars\_propt for entering values of username, groupname, shell. For groupname variable I want to use username’s value as a default value, but when I wrote default: {{username}} in my script I got syntax error, (I tried to write default: “{{username}}” , default: ‘{{username}}’ but in this cases script doesn’t understand that this is variable.

- hosts: servers  
vars\_prompt:

- name: “username”  
prompt: “Enter new username”  
private: no

- name: “groupname”  
prompt: “Please enter group name for user”  
private: no  
default: {{username}}

- name: “usershell”  
prompt: “Please enter shell name for user”  
private: no  
default: “/bin/bash”

---

<div class="post-metadata">

**Author:** ![Stankovic\_Marko](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Stankovic\_Marko](https://forum.ansible.com/u/Stankovic_Marko)\
**Post date:** [February 9, 2017, 12:49pm UTC](https://forum.ansible.com/t/vars-prompt-in-ansible/23691/2 "2017-02-09T12:49:53Z")

</div>

Hi,

I'm not getting a syntax error with

default: "{{ username }}"

It works (the default value is assigned if no input),  
but the default value is not templated in the prompt.  
This is printed instead:

Please enter group name for user: [{{ username }}]:

I believe it's related to this issue:  
[https://github.com/ansible/ansible/issues/16675](https://github.com/ansible/ansible/issues/16675)

Cheers,  
Marko  
CONFIDENTIALITY NOTICE: This message is the property of International Game Technology PLC and/or its subsidiaries and may contain proprietary, confidential or trade secret information. This message is intended solely for the use of the addressee. If you are not the intended recipient and have received this message in error, please delete this message from your system. Any unauthorized reading, distribution, copying, or other use of this message or its attachments is strictly prohibited.

---

<div class="post-metadata">

**Author:** ![Stepan\_Harutyunyan](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@Stepan\_Harutyunyan](https://forum.ansible.com/u/Stepan_Harutyunyan)\
**Post date:** [February 9, 2017, 1:03pm UTC](https://forum.ansible.com/t/vars-prompt-in-ansible/23691/3 "2017-02-09T13:03:50Z")

</div>

Hi Marko,

When script printed "Please enter group name for user: [{{ username }}]:" I thought that it understood {{ username }} as a string, but after your reply I tried to debug groupname value it works thank you, but now I have other issue I want to use {{ username }} in my group's prompt msg, when I wrote:

- name: "groupname"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prompt: "Please enter group name for user {{ username }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private: no  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default: "{{ username }}"

msg of promt is:

Please enter group name for user {{ username }} [{{ username }}]:

I want to see typed user name instead of {{ username }}

---

<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:** [February 9, 2017, 1:56pm UTC](https://forum.ansible.com/t/vars-prompt-in-ansible/23691/4 "2017-02-09T13:56:36Z")

</div>

You don't have hostvars available at that point, you can use extra\_vars though.

If you want to default to the user currently running Ansible, you can do this:

default: "{{lookup('env', 'USER')}}"
