On Tue, Mar 25, 2014 at 6:54 PM, Garrett Plasky <[email protected]>wrote:

> Can you explain why you think this is a "better way to go" in nearly all
> cases?
>


For one, because it can be used non-interactively.   For two, for the
question you raise below...



> I recently found out the hard way (after a bit of head-banging) that
> vars_prompt only applies to the current play and also doesn't apply to
> included playbooks.
>


This is implied by the fact that vars_prompt is an attribute of the play.
 It's just the same as if doing "vars" or "vars_files" in that play.





> Since you also cannot pass parameterized options to included playbooks as
> you can with roles, there's effectively no way to pass a variable gathered
> via vars_prompt to a child playbook without using -e. I've resorted to
> using -e for now, but I find it rather odd that I now have to wrap
> Ansible in "something else" (Shell script, Python, etc.) in order to
> programmatically input a simple variable to the playbook and have it
> accessible in places one could reasonably expect it to be.
>

Sorry!

There's no construct for asking questions at "overall playbook" level since
playbooks are just a list data structure of plays, there is no where to
attach this.

We could add a 'vars_prompt_global' kind of thing that left them in global
scope, but I'd be worried a bit more about language sprawl, so you may be
stuck.


>
>
> On Friday, April 12, 2013 6:49:37 AM UTC-7, Michael DeHaan wrote:
>
>> vars_prompt variables are set on the play.
>>
>> In nearly all cases, --extra-vars on the ansible-playbook command line is
>> a better way to go.
>>
>>
>>
>>
>>
>>
>> On Thu, Apr 11, 2013 at 9:43 PM, <[email protected]> wrote:
>>
>>> Prompt variable working scope is inventory host scope or playbook scope?
>>> Basically, variable is inventory host scope. But prompt vars seem not.
>>>
>>> main.yml includes 1.yml and 2.yml.
>>> 1.yml creates prompt variable var1 and its target hosts are host1 and
>>> host2.
>>> 2.yml wants to use the var1 and its target host is host1.
>>>
>>> I suppose 2.yml can get var1, but indeed not. Who can confirm it?
>>>
>>> *main.yml*
>>> ---
>>> - include: 1.yml
>>> - include: 2.yml
>>>
>>>
>>> *1.yml*
>>> ---
>>> - name: test prompt
>>>   hosts: test
>>>   gather_facts: false
>>>   user: root
>>>   sudo: false
>>>   vars_prompt:
>>>   - name: "password"
>>>     prompt: "Please enter password"
>>>     private: yes
>>>     confirm: yes
>>>
>>>   tasks:
>>>   - action: debug msg="$password"
>>>   - action: shell echo -n $password
>>>
>>> *2.yml*
>>> ---
>>> - hosts: 192.168.126.143
>>>   user: root
>>>   sudo: false
>>>
>>>   tasks:
>>>   - action: shell echo -n $password
>>>
>>>   - action: template src=template.conf dest=/root/out.conf owner=root
>>> group=root mode=0644
>>>
>>> *template.conf*
>>> {{ password }}
>>>
>>> *playbook execute result:*
>>> PLAY [test prompt] *********************
>>>
>>> TASK: [debug msg="123"] *********************
>>> ok: [192.168.126.143]
>>> ok: [192.168.126.150]
>>>
>>> TASK: [shell echo -n 123] *********************
>>> changed: [192.168.126.150]
>>> changed: [192.168.126.143]
>>>
>>> PLAY [192.168.126.143] *********************
>>>
>>> GATHERING FACTS *********************
>>> ok: [192.168.126.143]
>>>
>>> TASK: [shell echo -n $password] *********************
>>> changed: [192.168.126.143]
>>>
>>> TASK: [template src=template.conf dest=/root/out.conf owner=root
>>> group=root mode=0644] *********************
>>> ok: [192.168.126.143]
>>>
>>> PLAY RECAP *********************
>>> 192.168.126.143                : ok=5    changed=2    unreachable=0
>>>  failed=0
>>> 192.168.126.150                : ok=2    changed=1    unreachable=0
>>>  failed=0
>>>
>>> In out.conf, there is nothing.
>>>
>>>
>>>
>>>  --
>>> 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 [email protected].
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>>
>> --
>> Michael DeHaan <[email protected]>
>>
>> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6aa22e77-59c1-4419-bada-f7ab8a409989%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/6aa22e77-59c1-4419-bada-f7ab8a409989%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAEVJ8QNufPE_sw6huSa4xRxJ-C9%3DNHgZvz%2BgG3C3GqubZLBZbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to