This is a log file stored in Yaml Format.
My job is to find out the hostname which belongs to hostclass ess, which in this case the answer is host002.
hostinfo:
'host001':
ip: 192.168.43.10
hostclass: 'puppet'
'host002':
ip: 192.168.43.11
hostclass: 'ess'
'host003':
ip: 192.168.43.21
hostclass: 'mdb'
i got one solution from some friend, but i am unable to fit it my ansible playbook.
- debug:
msg: "{{ hostinfo|dictsort|selectattr('1.hostclass', 'equalto', 'ess')|first|first }}"
My playbook i am writing, It is wrong but i am not able to figure out how to fit the code in my playbook. Can anyone help me in modifying the code of mine.
---
- hosts: somehost
gather_facts: no
vars_files:
file: sometext.yaml
name: sometext
- debug:
msg: "{{ hostinfo|dictsort|selectattr('1.hostclass', 'equalto', 'ess')|first|first }}"