Re: [ansible-project] finding a phrase through ansible script

2018-04-11 Thread Matt Martz
The following task will find that:

- debug:
msg: "{{ hostinfo|dictsort|selectattr('1.hostclass', 'equalto',
'ess')|first|first }}"

That takes the `hostinfo` dict, turns it into a list of tuples, selects
where `hostclass` equals `ess`, gets the first result (there should only be
one here), and then gets the first element.

If you don't have jinja2 version with the `equalto` test, you can replace
that with `search` or `match`

It outputs:

TASK [debug] 


*
ok: [localhost] => {
"msg": "host002"
}

On Wed, Apr 11, 2018 at 10:24 AM, Bishwajit Samanta <
bishwajitsamanta1...@gmail.com> wrote:

> i am having a problem in finding solution. I have a piece of file which
> contains data in below format (json type with quotes)::-
>
> hostinfo:
>   'host001':
> ip: x.x.x.x
> hostclass: 'puppet'
>   'host002':
> ip: y.y.y.y
> hostclass: 'ess'
>   'host003':
> ip: z.z.z.z
> hostclass: 'mdb'
>
> Now my task is to find out the hostname of the system belong to hostclass
> 'ess' , which in this case the answer in host002. I have to write an
> ansible script to find out the result. Can anyone help me in finding out,
> or any idea to approach for the problem.
>
> Issue Type:: Finding a phrase through ansible
> Ansible Version:: Ansible 2.4.0
> Component Name:: It looks similar to json type file.
>
>
>
> --
> 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/f0e5742d-cdcd-473d-854d-decff5b2b283%40googlegroups.
> com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Matt Martz
@sivel
sivel.net

-- 
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/CAD8N0v8PTiV7f%2Bd5fmnC2CPO-7%3DLHJTGg8ygzRioaJmBSSKr9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] finding a phrase through ansible script

2018-04-11 Thread Bishwajit Samanta


i am having a problem in finding solution. I have a piece of file which 
contains data in below format (json type with quotes)::-

hostinfo:
  'host001':
ip: x.x.x.x
hostclass: 'puppet'
  'host002':
ip: y.y.y.y
hostclass: 'ess'
  'host003':
ip: z.z.z.z
hostclass: 'mdb'

Now my task is to find out the hostname of the system belong to hostclass 
'ess' , which in this case the answer in host002. I have to write an 
ansible script to find out the result. Can anyone help me in finding out, 
or any idea to approach for the problem.

Issue Type:: Finding a phrase through ansible
Ansible Version:: Ansible 2.4.0
Component Name:: It looks similar to json type file.



-- 
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/f0e5742d-cdcd-473d-854d-decff5b2b283%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.