# Ansible vars\_prompt with\_items and split

**URL:** <https://forum.ansible.com/t/ansible-vars-prompt-with-items-and-split/29162>\
**Category:** Ansible Project\
**Created:** [November 30, 2018, 12:12pm UTC](https://forum.ansible.com/t/ansible-vars-prompt-with-items-and-split/29162 "2018-11-30T12:12:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.srini](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@a.srini](https://forum.ansible.com/u/a.srini)\
**Post date:** [November 30, 2018, 12:12pm UTC](https://forum.ansible.com/t/ansible-vars-prompt-with-items-and-split/29162/1 "2018-11-30T12:12:17Z")

</div>

I want to pass multiple switch IP’s and single port number using vars\_prompt to perform the task on single port. I used with\_items: “{{ip\_addr.split(‘,’)}}”. But when i am passing multiple IP the task is not performing, when i try to pass single IP. The task performs successfully.

```auto
- hosts: localhost
  gather_facts: no
  vars_prompt:
  - name: ip_addr
    prompt: Please enter the switch name
    private: no
  - name: port_name
    prompt: Please enter the port name
    private: no

  vars_files:
    - ../vars/password.yml

  vars:
    port_speed: "8"

  tasks:
  - add_host:
      name: "{{ip_addr}}"
      groups: dynamically_created_hosts
    with_items: "{{ip_addr.split(',')}}" 
  - name: Change port speed
    port_speed_change:
      switch_ip: "{{ip_addr}}"
      user: "{{user}}"
      password: "{{password}}"
      checkmode: "{{ansible_check_mode}}"
      name: "{{port_name}}"
      speed: "{{port_speed}}"

```

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 30, 2018, 2:51pm UTC](https://forum.ansible.com/t/ansible-vars-prompt-with-items-and-split/29162/2 "2018-11-30T14:51:36Z")

</div>

with\_items returns a variable containing the value.  
So your name: need to be  
&nbsp;&nbsp;name: "{{ item }}"

---

<div class="post-metadata">

**Author:** ![a.srini](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@a.srini](https://forum.ansible.com/u/a.srini)\
**Post date:** [November 30, 2018, 2:58pm UTC](https://forum.ansible.com/t/ansible-vars-prompt-with-items-and-split/29162/3 "2018-11-30T14:58:43Z")

</div>

I have tried with name: “{{ item }}” still the same issue.

When i tried with this with\_items: “{{ip\_addr.split(’ ')}}”  
giving space it is executing on first IP address.
