Ask for variable value if variable not defined.

2683 views
Skip to first unread message

Marcin Prączko

unread,
Jan 28, 2014, 9:25:50 AM1/28/14
to ansible...@googlegroups.com
Hi,

Have question whether is possible (ansible 1.4.2 >) setup prompt for volue for variable in variable is not defined.

For example:
First run of playbook:
- variable is not defined
- ask for value
- task write value of variable to some ansible vars file

... Do other tasks...

Next run of playbook:
- variable is read from ansible vars file
- no prompt for value


... Do other tasks ....

Tried find this in ansible help, but so far no luck.

Best regards,
Marcin Praczko

Michael DeHaan

unread,
Jan 28, 2014, 9:42:14 AM1/28/14
to ansible...@googlegroups.com
There's no mechanism for this.

vars_prompt always prompts for the variable.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Adam Heath

unread,
Jan 28, 2014, 12:25:12 PM1/28/14
to ansible...@googlegroups.com
The following is pseudo code, parts of it may not be entirely correct.
But the real trick is to use when.

==
- name: ask for variable
when: my_var_name is not defined
register: my_var_name_result
vars_prompt: .....

- name: save vars
when: my_var_name_result.changed
$action:

==
> <mailto:ansible-project%2Bunsu...@googlegroups.com>.
> To post to this group, send email to
> ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> Michael DeHaan <mic...@ansibleworks.com <mailto:mic...@ansibleworks.com>>
> CTO, AnsibleWorks, Inc.
> http://www.ansibleworks.com/
>

Serkan C.

unread,
Sep 10, 2014, 4:59:32 AM9/10/14
to ansible...@googlegroups.com
Hi Micheal,
Do you have any advice for it? It doesn't accept when condition.
Best.

Michael DeHaan

unread,
Sep 10, 2014, 9:21:41 AM9/10/14
to ansible...@googlegroups.com
As politely as possible... Please don't share made-up syntax on this list, it confuses everyone :)



    To post to this group, send email to

    For more options, visit https://groups.google.com/groups/opt_out.




--

CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

--
You received this message because you are subscribed to the Google
Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Michael DeHaan

unread,
Sep 10, 2014, 9:23:00 AM9/10/14
to ansible...@googlegroups.com
Nope, it doesn't do this.  Simple as that :)

I'd suggest setting a role default instead, or putting a good default value in group_vars/all, and you can override that on the CLI with "-e".

vars_prompt in Ansible is not *usually* a good idea as it limits the ability of someone to automate a workflow in Ansible, since it's interactive.






Serkan C.

unread,
Sep 12, 2014, 6:45:03 AM9/12/14
to ansible...@googlegroups.com
Hi,
You're right, i was using default variables and extra parameters to override but i thought that maybe i can also use it for basic system playbooks.
Thanks.
Reply all
Reply to author
Forward
0 new messages