# How to setup a Yes in a Yes or No to repeat and entry

**URL:** <https://forum.ansible.com/t/how-to-setup-a-yes-in-a-yes-or-no-to-repeat-and-entry/5185>\
**Category:** Get Help\
**Created:** [April 27, 2024, 10:34pm UTC](https://forum.ansible.com/t/how-to-setup-a-yes-in-a-yes-or-no-to-repeat-and-entry/5185 "2024-04-27T22:34:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Codger](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@Codger](https://forum.ansible.com/u/Codger)\
**Post date:** [April 27, 2024, 10:34pm UTC](https://forum.ansible.com/t/how-to-setup-a-yes-in-a-yes-or-no-to-repeat-and-entry/5185/1 "2024-04-27T22:34:14Z")

</div>

Hi All,  
I’m new to Ansible and am learning as I go. I’m trying to create a playbook that will prompt the user to add a new VLAN number and Name to be populated on all my switches (in an inventory file). It then prompts them if they want to add another VLAN. If they type “yes” it should prompt them with the questions again and add. Is it possible to do this in Ansible? I am struggling with the looping feature. I can get it to add a single update, but not multiple.

Current playbook:

- name: Add VLAN and Name  
hosts: Ansible4\_Switch  
gather\_facts: no  
vars:  
vlan\_data:

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [April 28, 2024, 3:37am UTC](https://forum.ansible.com/t/how-to-setup-a-yes-in-a-yes-or-no-to-repeat-and-entry/5185/2 "2024-04-28T03:37:49Z")

</div>

Hi, your playbook is mostly finished 😃

The last step is, to separate yours into two files.

```yaml
# loop_vlan_input.yml
---
- name: Prompt for VLAN number
  ansible.builtin.pause:
    prompt: "Please enter a VLAN number"
  register: vlan_number

- name: Prompt for VLAN name
  ansible.builtin.pause:
    prompt: "Please enter a name for VLAN {{ vlan_number.user_input }}"
  register: vlan_name

- name: Add VLAN data to list
  ansible.builtin.set_fact:
    vlan_data: "{{ vlan_data + [{'vlan_id': vlan_number.user_input, 'name': vlan_name.user_input}] }}"

- name: Ask if user wants to add another VLAN
  ansible.builtin.pause:
    prompt: "Do you want to add another VLAN? (yes/no)"
  register: add_more

- name: Repeat VLAN configuration loop
  ansible.builtin.include_tasks: loop_vlan_input.yml
  when: add_more.user_input | lower == 'yes'

```

Then include this file from your playbook:

```yaml
# Add_a_vlan_interactive.yaml
---
- name: Add VLAN and Name
  hosts: Ansible4_Switch
  gather_facts: false
  vars:
    vlan_data: []
  tasks:
    - name: Ask users to input vlans to be created
      ansible.builtin.include_tasks: loop_vlan_input.yml

    - name: Display VLAN data
      ansible.builtin.debug:
        var: vlan_data

```

Hope this helps 😃

---

<div class="post-metadata">

**Author:** ![Codger](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@Codger](https://forum.ansible.com/u/Codger)\
**Post date:** [April 28, 2024, 2:53pm UTC](https://forum.ansible.com/t/how-to-setup-a-yes-in-a-yes-or-no-to-repeat-and-entry/5185/3 "2024-04-28T14:53:16Z")

</div>

@kurokobo - thank you so much for your assistance. That worked great and I was able to add multiple variables and then retrieve them to add to my task. Your help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 28, 2024, 2:53pm UTC](https://forum.ansible.com/t/how-to-setup-a-yes-in-a-yes-or-no-to-repeat-and-entry/5185/4 "2024-05-28T14:53:44Z")

</div>

Closed on May 28, 2024, 2:53pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
