Ansible vars_prompt with_items and split

105 views
Skip to first unread message

srinivas a

unread,
Nov 30, 2018, 7:12:17 AM11/30/18
to Ansible Project
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.

- 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}}"

Kai Stian Olstad

unread,
Nov 30, 2018, 9:52:01 AM11/30/18
to ansible...@googlegroups.com
On Friday, 30 November 2018 13:12:17 CET srinivas a wrote:
> - add_host:
> name: "{{ip_addr}}"
> groups: dynamically_created_hosts
> with_items: "{{ip_addr.split(',')}}"

with_items returns a variable containing the value.
So your name: need to be
name: "{{ item }}"

--
Kai Stian Olstad


srinivas a

unread,
Nov 30, 2018, 9:58:43 AM11/30/18
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages