Variable Definition

Playbook:

vars:
host: [ ‘xyz’, ‘gvv’ ]
tasks:

  • name: check ping
    shell: ping -c 2 {{ host }} >> /tmp/test
    with_items: host

o/p:

failed: [10.100.100.187] (item=host) => {“changed”: true, “cmd”: “ping -c 2 [u’xyz’, u’gvv’] >> /tmp/test”, “delta”: “0:00:00.010502”, “end”: “2017-08-01 11:44:35.355523”, “failed”: true, “item”: “host”, “rc”: 2, “start”: “2017-08-01 11:44:35.345021”, “stderr”: “ping: unknown host [uxyz,”, “stderr_lines”: [“ping: unknown host [uxyz,”], “stdout”: “”, “stdout_lines”: }
to retry, use: --limit @/home/sara.bckup.priv/ssh.retry

I defined the varaible correctly in vars but when its getting passsed, there is an extra character ‘u’ in the variable. What am I doing wrong here?

You need to use {{ item }} in the ping command not {{ host }}.