Placement of vars_promt

128 views
Skip to first unread message

Tiglath

unread,
Sep 9, 2014, 1:25:31 PM9/9/14
to ansible...@googlegroups.com
 
 
My test playbook for the flow I want is shown below:
 
I want some work done, then prompt the user, then more work, a pause, and the end. 
 
The thing is that the prompt comes up even before gathering facts, not as suggested by its placement in the playbook. 
 
Can the prompting be done between tasks? 
 
Thanks
 
 
 

---

hosts: "{{ target }}"

tasks:

      - name: boo

        debug: msg="vars {{ inventory_hostname }} , env {{ env }} op {{ op }} rel {{ rel }}"

      - name: build the release

        debug: msg="building"

      - name: installing/updating

        debug: msg="installing"

 

hosts: "{{ target }}"

      vars_prompt:

      ltvup: "Is the app up on {{ target }} ? (y/n): "

      tasks:

           - name: Stop app

             debug: msg="the server is {{ ltvup }}"

           - name: postinstall

             debug: msg="post"

           - name: wait

             pause: prompt="Have admins do sudo blah blah blah"

  cleanup tasks here.  

 

 

 

Michael DeHaan

unread,
Sep 9, 2014, 3:17:29 PM9/9/14
to ansible...@googlegroups.com
Ansible plays are hashes, they are a collection of attributes.

Tasks are an ordered list.

Thus including "vars_prompt" ahead or behind "tasks" makes no difference.

vars_prompt happens before the current play runs, every time.

You can solve this problem by stopping the current play, starting a new one with a vars_prompt in it, and then continuing, since a playbook can contain multiple plays in a single file.




--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e78ba643-6db5-4ffb-9af5-ab90daf811d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tiglath

unread,
Sep 10, 2014, 12:57:44 AM9/10/14
to ansible...@googlegroups.com


On Tuesday, September 9, 2014 3:17:29 PM UTC-4, Michael DeHaan wrote:
Ansible plays are hashes, they are a collection of attributes.

Tasks are an ordered list.

Thus including "vars_prompt" ahead or behind "tasks" makes no difference.

vars_prompt happens before the current play runs, every time.

You can solve this problem by stopping the current play, starting a new one with a vars_prompt in it, and then continuing, since a playbook can contain multiple plays in a single file.

 
Many thanks.   I apologize but I am not proficient enough to know what you mean exactly. 

Something like this?


---

- name: play 1
  hosts: myhost
  task:
       -name task1
         debug: msg='111111'

- name: play 2
  hosts: myhost
  vars_prompt:
       yesno: 'Yes or No (y/n): '


- name: play 3
  hosts: myhost
  task:
       -name task2
         debug: msg='YesNo = {{ yesno }}'





Michael DeHaan

unread,
Sep 10, 2014, 8:30:44 AM9/10/14
to ansible...@googlegroups.com
On Wed, Sep 10, 2014 at 12:57 AM, Tiglath <te...@tiglath.net> wrote:


On Tuesday, September 9, 2014 3:17:29 PM UTC-4, Michael DeHaan wrote:
Ansible plays are hashes, they are a collection of attributes.

Tasks are an ordered list.

Thus including "vars_prompt" ahead or behind "tasks" makes no difference.

vars_prompt happens before the current play runs, every time.

You can solve this problem by stopping the current play, starting a new one with a vars_prompt in it, and then continuing, since a playbook can contain multiple plays in a single file.

 
Many thanks.   I apologize but I am not proficient enough to know what you mean exactly. 

Something like this?


---

- name: play 1
  hosts: myhost
  task:
       -name task1
         debug: msg='111111'

- name: play 2
  hosts: myhost
  vars_prompt:
       yesno: 'Yes or No (y/n): '


- name: play 3
  hosts: myhost
  task:
       -name task2
         debug: msg='YesNo = {{ yesno }}'

Basically.

You can consolidate and get the same effect:


--- 

- name: play 1
  hosts: myhost
  task: 
       -name task1
         debug: msg='111111'

- name: play 3
  hosts: myhost
  vars_prompt: 
       yesno: 'Yes or No (y/n): ' 

Michael DeHaan

unread,
Sep 10, 2014, 8:33:51 AM9/10/14
to ansible...@googlegroups.com
Hi Petros, 

Seems you are asking a bit of a different question....

I don't particularly like this suggested approach because it conflates two very different concepts - prompting with setting variables, in one line that is hard to read.  Also, ansible only accepts *one* value for each argument, so specifying prompt twice is weird, and specifying the name of the variable in the prompt string is very un-ansible-like as well.

Two, it sounds like what you really would want is a new action plugin called "prompt", which I would be open to, which would look a lot like the source to pause.py

- prompt: var="foo" message="foo?"
- prompt: var="spork" message="Sporks are cool?"
- set_fact: combined="{{ foo }}-{{ spork }}" 

On Wed, Sep 10, 2014 at 7:12 AM, Petros Moisiadis <erne...@yahoo.gr> wrote:

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

I think it could be useful if 'set_fact' (and 'set_global' if it is implemented) were extended to take a special 'prompt' parameter that would make it easy for asking for user input at whatever step of a deployment process.

E.g.:
- set_fact: prompt="somevar:Enter your value" prompt="anothervar:Enter another value"  combined_fact="{{ somevar }} - {{ anothervar }}"

What do you think?


Tiglath

unread,
Sep 10, 2014, 11:05:12 AM9/10/14
to ansible...@googlegroups.com

On Wednesday, September 10, 2014 8:33:51 AM UTC-4, Michael DeHaan wrote:
Hi Petros, 
 
I'm Joseph, actually.
 
Gratitude for all your replies. 

Michael DeHaan

unread,
Sep 10, 2014, 12:14:36 PM9/10/14
to ansible...@googlegroups.com
You are welcome, though that particular reply about new set_fact syntax was for Petros :)

The other was for you though :)



Reply all
Reply to author
Forward
0 new messages