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




Den torsdagen den 11:e december 2014 kl. 18:36:19 UTC+1 skrev James 
Cammarata:
>
> 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!
>
> On Thu, Dec 11, 2014 at 11:22 AM, Mikael Sandström <ora...@gmail.com 
> <javascript:>> wrote:
>
>> 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
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to ansible-proje...@googlegroups.com <javascript:>.
>> To post to this group, send email to ansible...@googlegroups.com 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/bd3b24c6-0936-41a6-87ed-581142f0b354%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/bd3b24c6-0936-41a6-87ed-581142f0b354%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c670d5db-060a-4208-9aff-d921b6bf258b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to