You'd need to show what's registered to cacti_query. It appears to be 
saying it doesn't contain anything named "hostname". It may not contain "
query_result" either. Like I said before, it makes me question what's 
registered by your query *in that particular run*. Stick another debug task 
before that showing what's being registered by the db query task.
On Thursday, July 20, 2023 at 2:10:11 PM UTC-4 Alex Wanderley wrote:

> Yes, I'm afraid we indeed are still in a transition  process...
>
> But you did help a lot: I didn't think straight and did not try to run the 
> same playbook on one of our future servers, running 2.14.3.
>
> However, it did not like the map solution.
>
> msg: "{{ cacti_query.query_result | map(attribute='hostname') }}"
>
> Is giving me:
> "The task includes an option with an undefined variable. The error was: 
> list object has no element AnsibleUndefined(hint=None, obj=missing, 
> name='hostname').
>
> Could you give one last insight about that?
> (I have no intention to drag this out for longer and keep bothering our 
> list with something that I understand is simple but I don't have yet the 
> knowledge to solve.)
>
> Regards,
>
> Alex
>
> On Thu, Jul 20, 2023 at 11:17 AM Todd Lewis <[email protected]> wrote:
>
>> That's twice this morning a working solution was inapplicable b/c someone 
>> was still running Ansible 2.9. I know people don't always get to pick the 
>> version of whatever software they have to use because of factors beyond 
>> their control. We were stuck on 2.9 far longer than we would have liked.
>>
>> However, if it's at all possible, IMO, any time spent trying to make 
>> stuff work under 2.9 *rather than moving to a later version* is time 
>> seriously wasted. There have been so very many improvements.
>>
>> Adding "| list" as you did should have been enough, though. It makes me 
>> wonder what was in your registered result on that particular run.
>>
>> Sorry I can't offer any actionable suggestions. Good luck,
>> --
>> Todd
>>
>> On Thursday, July 20, 2023 at 12:43:50 PM UTC-4 Alex Wanderley wrote:
>>
>>> Hi Todd,
>>>
>>> Thanks for helping...
>>>
>>> {{ cacti_query.query_result | map(attribute='hostname') }}
>>> Gave me the output:
>>> "msg": "<generator object do_map at 0x7fe0c4e9f2b0>"
>>>
>>> Looking around I found that {{ cacti_query.query_result | 
>>> map(attribute='hostname') | list }} would be the solution for the 
>>> message above, but instead I got:
>>> "msg": "[AnsibleUndefined]"
>>>
>>> Would that possibly be caused by Ansible/Python versions?
>>> We have Ansible 2.9.7 and Python 3.6.8.
>>>
>>> Regards,
>>>
>>> Alex
>>>
>>> On Thu, Jul 20, 2023 at 9:52 AM Todd Lewis <[email protected]> wrote:
>>>
>>>> {{ cacti_query.query_result | map(attribute='hostname') }}
>>>>
>>>>
>>>> On 7/20/23 11:42 AM, Alex Wanderley wrote:
>>>>
>>>> Hello, 
>>>>
>>>> I need to collect some hostnames from a MariaDB database but don't know 
>>>> exactly how to properly parse the result of my query... Could somebody 
>>>> help?
>>>>
>>>> This how the tasks look like:
>>>>
>>>>         - name: Collect devices in down state
>>>>           community.mysql.mysql_query:
>>>>              login_db: cacti
>>>>              query: SELECT hostname FROM host WHERE status=1
>>>>              login_unix_socket: /run/mysqld/mysqld.sock
>>>>           register: cacti_query
>>>>
>>>>         - name: print query result
>>>>           debug:
>>>>                   msg: "{{ cacti_query.query_result }}"
>>>>
>>>> And this is the output:
>>>>
>>>> ok: [xxxxxxxxx] => {
>>>>     "msg": [
>>>>         [
>>>>             {
>>>>                 "hostname": "host_A"
>>>>             },
>>>>             {
>>>>                 "hostname": "host_B"
>>>>             },
>>>>             {
>>>>                 "hostname": "host_C"
>>>>             },
>>>>             {
>>>>                 "hostname": "host_D"
>>>>             }
>>>>         ]
>>>>     ]
>>>> }
>>>>
>>>> How could I create a list with just the actual host names "host_A  host_
>>>> *B * host_C  host_D" to be used/referenced in a loop further down my 
>>>> playbook?
>>>>
>>>> Thanks a lot,
>>>>
>>>> Alex
>>>>
>>>>
>>>> -- 
>>>> 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 view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/ansible-project/7cbbf374-1d36-1fa6-c7ed-15b133d656f6%40gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/ansible-project/7cbbf374-1d36-1fa6-c7ed-15b133d656f6%40gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>>
>>> -- 
>>>
>>>  
>>>
>>> [image: Edmonton_sig_RGB_S.jpg]
>>>
>>> Alex Wanderley
>>>
>>> Application and Infrastructure Analyst II
>>> Acting Team Lead Server Solutions & Automation
>>>
>>> Financial and Corporate Services | Open City and Technology  
>>>
>>>  
>>>
>>> 780-496-4156 <(780)%20496-4156>  Office
>>>
>>> 780-819-0273 <(780)%20819-0273>  Mobile
>>>
>>>  
>>>
>>> City of Edmonton 
>>>
>>> Century Place, 19th Floor
>>>
>>> 9803 102A Avenue NW
>>>
>>> Edmonton AB, T5J 3A3
>>>
>>>  
>>>
>>> All information contained in this email post is proprietary to the City 
>>> of Edmonton, confidential and intended only for the addressed recipient. If 
>>> you have received this post in error, please disregard the contents, inform 
>>> the sender of the misdirection, and remove it from your system. The 
>>> copying, dissemination or distribution of this email, if misdirected, is 
>>> strictly prohibited.
>>>
>>> *The contents of this message and any attachment(s) are confidential, 
>>> proprietary to the City of Edmonton, and are intended only for the 
>>> addressed recipient. If you have received this in error, please disregard 
>>> the contents, inform the sender of the misdirection, and remove it from 
>>> your system. The copying, dissemination, or distribution of this message, 
>>> if misdirected, is strictly prohibited.*
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/7c145dfa-5d9f-44b6-a7b1-4020d039a00fn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/7c145dfa-5d9f-44b6-a7b1-4020d039a00fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
>
>  
>
> [image: Edmonton_sig_RGB_S.jpg]
>
> Alex Wanderley
>
> Application and Infrastructure Analyst II
> Acting Team Lead Server Solutions & Automation
>
> Financial and Corporate Services | Open City and Technology  
>
>  
>
> 780-496-4156 <(780)%20496-4156>  Office
>
> 780-819-0273 <(780)%20819-0273>  Mobile
>
>  
>
> City of Edmonton 
>
> Century Place, 19th Floor
>
> 9803 102A Avenue NW
>
> Edmonton AB, T5J 3A3
>
>  
>
> All information contained in this email post is proprietary to the City of 
> Edmonton, confidential and intended only for the addressed recipient. If 
> you have received this post in error, please disregard the contents, inform 
> the sender of the misdirection, and remove it from your system. The 
> copying, dissemination or distribution of this email, if misdirected, is 
> strictly prohibited.
>
> *The contents of this message and any attachment(s) are confidential, 
> proprietary to the City of Edmonton, and are intended only for the 
> addressed recipient. If you have received this in error, please disregard 
> the contents, inform the sender of the misdirection, and remove it from 
> your system. The copying, dissemination, or distribution of this message, 
> if misdirected, is strictly prohibited.*

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/894210ad-f95c-4f95-9e20-c96fbe8de1a9n%40googlegroups.com.

Reply via email to