Well,  I guess that helps ;-) it's been a long day...

All good now, thanks!
/M


> On 11 dec 2014, at 20:44, Michael DeHaan <[email protected]> wrote:
> 
> JSON needs to be valid JSON :)
> 
> 
> 
>> On Thu, Dec 11, 2014 at 2:30 PM, Mikael Sandström <[email protected]> wrote:
>> 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 <[email protected]> 
>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/ansible-project/bd3b24c6-0936-41a6-87ed-581142f0b354%40googlegroups.com.
>>>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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.
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Ansible Project" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/ansible-project/Mm9qtgOrq7E/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgzKb0AfBUV2FBRP1COwKf94mkruSE9pO%3D-%2B7dJtofCYpQ%40mail.gmail.com.
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/AD978B2C-A652-4AE1-8A61-48B5290B679E%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to