oravirt
1
Hi,
I got a list that looks like this
listname:
- name: ble
version: 1
path: /some/path
…
…
which is accessed as
- name: do something
shell: run some command
with_items: listname
If I want to pass the list to a playbook as an --extra-vars, how would I do that?
regards
/M
Hi Mikael,
There are essentially two ways you can do this:
- Use quoted JSON
- Put the data in either a JSON or YAML file.
Please refer to the documentation here for more details: http://docs.ansible.com/playbooks_variables.html#passing-variables-on-the-command-line
Thanks!
oravirt
3
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:
`
JSON needs to be valid JSON
oravirt
5
Well, I guess that helps it’s been a long day…
All good now, thanks!
/M
oravirt
6
And just for completeness sake:
`
ansible-playbook extravar.yml -e ‘{“listname”:[{“name”:“foo”,“path”:“/asd/bsdfr”, “version”:“2”}]}’
PLAY [localhost] **************************************************************
TASK: [test extravars] ********************************************************
ok: [localhost] => (item={u’path’: u’/asd/bsdfr’, u’version’: u’2’, u’name’: u’foo’}) => {
“item”: {
“name”: “foo”,
“path”: “/asd/bsdfr”,
“version”: “2”
},
“msg”: “version - 2”
}
`
Thanks!
/M