I hit this yesterday too.  

Sorry to resurrect very old thread but thought I would add that in the end 
I wound up with the following syntax (to retrieve a list of conmmit 
messages from a jenkins build).  Note that I wound up with single quotes 
around items:

     - name: collect the commit messages
       set_fact:
          commit_messages: "{{ 
build_info.json.changeSet['items']|map(attribute='msg')|list }}"



On Monday, February 10, 2014 at 8:45:40 PM UTC, Michael DeHaan wrote:
>
> This could be true, actually.   It wouldn't call the method without parens 
> but it would have errored out.
>
>
>
>
> On Mon, Feb 10, 2014 at 2:53 PM, Brent Langston <[email protected] 
> <javascript:>> wrote:
>
>> This appears to work:
>>
>>       debug: var="{{jenkinsStatus.json.changeSet["items"][0].comment}}”
>>
>> My theory is that when the parser reached “items” in the json output, it 
>> called the python method “items” and received it’s output as a list.
>>
>> In this case, it was necessary to surround the variable with “{{ }}”, and 
>> expressly reference [“items”], to get it to interpret correctly.
>>
>>
>>
>> On February 10, 2014 at 2:29:41 PM, Michael DeHaan ([email protected] 
>> <javascript:>) wrote:
>>
>> Nope. 
>>
>> Save it in a sample Python test.py file and get the right python syntax 
>> to survive a print statement, and then you'll be on the right track.
>>
>>
>>
>>
>> On Mon, Feb 10, 2014 at 2:28 PM, Brent Langston <[email protected] 
>> <javascript:>> wrote:
>>
>>> So I downloaded the json to a file, and tried to access that value using 
>>> ‘jq’:
>>>
>>> cat document.json | jq .json.changeSet.items[0].comment
>>>
>>> that works fine, so I think you’re right about the syntax.  Is it 
>>> possible that Ansible can’t access objects nested that deep?
>>>
>>>
>>>
>>> On February 10, 2014 at 2:14:18 PM, Brent Langston ([email protected] 
>>> <javascript:>) wrote:
>>>
>>> I was wondering about that. I *did* try that earlier (with so many other 
>>> combinations as well.) This is what I have now:
>>>
>>>       debug: var=jenkinsStatus.json.changeSet.items[0].comment
>>>
>>> result:
>>>
>>>     "jenkinsStatus.json.changeSet.items[0].comment": "{{ 
>>> jenkinsStatus.json.changeSet.items[0].comment }}"
>>>
>>> I can’t figure out what’s wrong with that statement, though.
>>>
>>>
>>> On February 10, 2014 at 2:08:28 PM, Michael DeHaan ([email protected] 
>>> <javascript:>) wrote:
>>>
>>> It seems like you need to index your array like so: 
>>>
>>> jenkinsStatus.json.changeSet.items[0].comment 
>>>
>>> Since the ".0." would be looking for a hash member named "0" versus an 
>>> array index.
>>>
>>>
>>>
>>>
>>> On Mon, Feb 10, 2014 at 2:02 PM, Brent Langston <[email protected] 
>>> <javascript:>> wrote:
>>>
>>>> I'm sure this is probably something I'm doing wrong, but I can't seem 
>>>> to figure out the right thing, so hopefully someone else can. 
>>>>
>>>> This is the value of the registered variable "jenkinsStatus": 
>>>> http://hastebin.com/cacusiwiki.tex
>>>>
>>>> Given the following playbook:
>>>>
>>>> ---
>>>> - name: Jenkins Status Info
>>>>   hosts: localhost
>>>>   connection: local
>>>>   user: root
>>>>   gather_facts: False
>>>>   vars:
>>>>     jenkins_url: http://jenkins.example.com:8080/job/
>>>>     project: member-web-dev
>>>>
>>>>   tasks:
>>>>
>>>>     - name: Get jenkins status
>>>>       uri: url={{ jenkins_url }}/{{ project }}/lastBuild/api/json 
>>>> return_content=yes status_code=200
>>>>       register: jenkinsStatus
>>>>
>>>>     - name: show the output
>>>>       debug: var=jenkinsStatus.json.changeSet.items.0.comment
>>>>
>>>> I'm trying to access the comment data, but am not getting back any 
>>>> value:
>>>> ok: [127.0.0.1] => {
>>>>     "jenkinsStatus.json.changeSet.items.0.comment": "{{ 
>>>> jenkinsStatus.json.changeSet.items.0.comment }}"
>>>> }
>>>>
>>>> and if I just use debug: var=jenkinsStatus.json.changeSet.items
>>>>
>>>> ok: [127.0.0.1] => {
>>>>     "jenkinsStatus.json.changeSet.items": "<built-in method items of 
>>>> dict object at 0x7fd259a89ae0>"
>>>> }
>>>>
>>>> So how can I access/use the value stored in comment?
>>>>
>>>> > ansible-playbook --version
>>>> ansible-playbook 1.5,
>>>> --
>>>> 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] <javascript:>.
>>>> To post to this group, send email to [email protected] 
>>>> <javascript:>.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>> --
>>> 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] <javascript:>.
>>> To post to this group, send email to [email protected] 
>>> <javascript:>.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>
>

-- 
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/2014b840-fd3a-432f-af04-b163b6b8ce6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to