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”
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.
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"
prompt: "Please enter group name for user {{ username }}"
private: no
default: "{{ username }}"
msg of promt is:
Please enter group name for user {{ username }} [{{ username }}]:
I want to see typed user name instead of {{ username }}