How do I pass a list as an --extra-vars

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:

  1. Use quoted JSON
  2. 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!

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 :slight_smile:

Well, I guess that helps :wink: it’s been a long day…

All good now, thanks!
/M

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