Thanks!
I cant get it to behave as a 'normal' list though, so obviously I'm doing something wrong.
If I run this playbook without extra vars:
---
- hosts: localhost
connection: local
gather_facts: false
vars:
listname:
- name: ble
version: 1
path: /some/path
tasks:
- name: test extravars
debug: msg="version - {{ item.version }}"
#debug: msg=""
with_items: listname
It works as expected, and I get this:
TASK: [test extravars] ********************************************************
ok: [localhost] => (item={'path': '/some/path', 'version': 1, 'name': 'ble'}) => {
"item": {
"name": "ble",
"path": "/some/path",
"version": 1
},
"msg": "version - 1"
}
However, if I try to do this
ansible-playbook extravar.yml -e '{"listname":["name: foo, path: /asd/bsdfr, version: 2"]}'
PLAY [localhost] **************************************************************
TASK: [test extravars] ********************************************************
fatal: [localhost] => One or more undefined variables: 'unicode object' has no attribute 'version'
And I guess that is because everything in 'item' is treated like one string
TASK: [test extravars] ********************************************************
ok: [localhost] => (item=name: foo, path: /asd/bsdfr, version: 2) => {
"item": "name: foo, path: /asd/bsdfr, version: 2",
"msg": ""
}
If I quote each pair, I get 3 different 'items'
ansible-playbook extravar.yml -e '{"listname":["name: foo", "path: /asd/bsdfr", "version: 2"]}'
PLAY [localhost] **************************************************************
TASK: [test extravars] ********************************************************
ok: [localhost] => (item=name: foo) => {
"item": "name: foo",
"msg": ""
}
ok: [localhost] => (item=path: /asd/bsdfr) => {
"item": "path: /asd/bsdfr",
"msg": ""
}
ok: [localhost] => (item=version: 2) => {
"item": "version: 2",
"msg": ""
So, how should the quotes be placed to get it to behave like a 'normal' list? Or is there something else I need to do?
regards
/M