# vars\_prompt variables carry over into next tasks

**URL:** <https://forum.ansible.com/t/vars-prompt-variables-carry-over-into-next-tasks/38693>\
**Category:** Ansible Project\
**Created:** [February 20, 2024, 1:10pm UTC](https://forum.ansible.com/t/vars-prompt-variables-carry-over-into-next-tasks/38693 "2024-02-20T13:10:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [February 20, 2024, 1:10pm UTC](https://forum.ansible.com/t/vars-prompt-variables-carry-over-into-next-tasks/38693/1 "2024-02-20T13:10:26Z")

</div>

Good morning.

In the following playbook, i have prompts to capture certain information. The created variables work fine in the first set of tasks in the playbook. However, they don’t carry over into the second set of tasks in the playbook, based on what I’ve tried (as seen in the playbook, which is probably not the most efficient). Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [February 20, 2024, 2:14pm UTC](https://forum.ansible.com/t/vars-prompt-variables-carry-over-into-next-tasks/38693/2 "2024-02-20T14:14:54Z")

</div>

I _think_ the vars from vars\_prompt are tied to localhost in the first play, so if you need them in any next plays, you would need to reference them as localhost’s hostvars:

{{ hostvars[‘localhost’].pemno }}

(not tested)

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [February 21, 2024, 1:03pm UTC](https://forum.ansible.com/t/vars-prompt-variables-carry-over-into-next-tasks/38693/3 "2024-02-21T13:03:09Z")

</div>

Dick, I’m not getting that to work. For now, I’m prompting again for the pemno withing the second set of tasks. That works, but isn’t ideal. I’d like to see if I can “re-use” the pemno gathered from the first tasks prompt in the second set of tasks:

**- hosts: localhost**  
**connection: local**  
**gather\_facts: false**

**vars\_prompt:**  
**- name: “pemno”**  
**prompt: “Enter the number of the created pems”**  
**private: no**

**tasks:**

**- hosts: myhost**  
**become: yes**

**tasks:**  
 **\<----- use pemno here from above**

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [February 21, 2024, 1:13pm UTC](https://forum.ansible.com/t/vars-prompt-variables-carry-over-into-next-tasks/38693/4 "2024-02-21T13:13:04Z")

</div>

This works. The set\_fact makes a global variable for the entire playbook.

- hosts: localhost

connection: local

gather\_facts: false

become: false

vars\_prompt:

- name: “pemno”

prompt: “Enter the number of the created pems”

private: no

tasks:

- set\_fact:

pemno: “{{ pemno }}”

- hosts: all

gather\_facts: false

become: false

tasks:

- debug: var=pemno

Walter

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [February 21, 2024, 2:45pm UTC](https://forum.ansible.com/t/vars-prompt-variables-carry-over-into-next-tasks/38693/5 "2024-02-21T14:45:46Z")

</div>

Walter, I tried this, which is like what I think you posted:
