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

2018-04-11 Thread Bishwajit Samanta
Hi, thanks for sharing the docs link. In the meanwhile i am not able to go 
in the right direction of solving the problem. so far what i have done is ::

1. converted the text file to json through python.
2. write some ansible codes, which in return it is dumping the contents but 
i am not able to get the thing i want.



---

- hosts: devops
  gather_facts: no
  vars:
contents: "{{ lookup('file', '/root/ansible/sample_1.json') | from_json 
}}"

  tasks:

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

- debug:
   msg: "{{ contents }}"



Can you guide in my problem please.. 



On Wednesday, April 11, 2018 at 10:26:47 PM UTC+5:30, Matt Martz wrote:
>
> Templating in Ansible is handled by Jinja2.  You can find documentation on 
> Jinja2 at http://jinja.pocoo.org/docs/dev/templates/
>
> For the `first` filter specifically: 
> http://jinja.pocoo.org/docs/dev/templates/#first
>
> On Wed, Apr 11, 2018 at 11:47 AM, Bishwajit Samanta <
> bishwajits...@gmail.com > wrote:
>
>> @Matt Martz : I am sorry to ask silly questions, regarding ansible as by 
>> seeing the small piece of code, i can understand you must be an ansible 
>> expert. If possible you can help me in my problem explanation a bit. 
>>
>> And any such links for learning you want to refer, please refer me. As i 
>> googled selectattr but first|first parameter which you have passed i am not 
>> getting any good document. If you can help me in referring such, it would 
>> be of very nice help.
>>
>>
>>
>> On Wednesday, April 11, 2018 at 9:36:13 PM UTC+5:30, Bishwajit Samanta 
>> wrote:
>>>
>>> I am glad you replied so fast, but sorry to say i am not an ansible 
>>> expert . I am just a beginner . I just typed the code. Can you help me in 
>>> understanding  where i am not correct.
>>>
>>> ---
>>>
>>> - hosts: devops
>>>
>>>   tasks:
>>> - debug:
>>>msg: "{{ hostinfo|dictsort|selectattr('1.hostclass', 'equalto', 
>>> 'ess')|first|first }}"
>>>
>>> ~
>>> ~
>>>
>>>
>>>
>>>
>>> On Wednesday, April 11, 2018 at 8:54:15 PM UTC+5:30, Bishwajit Samanta 
>>> 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-proje...@googlegroups.com .
>> To post to this group, send email to ansible...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/e685426e-a978-4ae9-be43-6ed342d3225a%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/d49d691b-9234-424b-ad2a-b06dbc0ccc1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-04-11 Thread Matt Martz
Templating in Ansible is handled by Jinja2.  You can find documentation on
Jinja2 at http://jinja.pocoo.org/docs/dev/templates/

For the `first` filter specifically:
http://jinja.pocoo.org/docs/dev/templates/#first

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

> @Matt Martz : I am sorry to ask silly questions, regarding ansible as by
> seeing the small piece of code, i can understand you must be an ansible
> expert. If possible you can help me in my problem explanation a bit.
>
> And any such links for learning you want to refer, please refer me. As i
> googled selectattr but first|first parameter which you have passed i am not
> getting any good document. If you can help me in referring such, it would
> be of very nice help.
>
>
>
> On Wednesday, April 11, 2018 at 9:36:13 PM UTC+5:30, Bishwajit Samanta
> wrote:
>>
>> I am glad you replied so fast, but sorry to say i am not an ansible
>> expert . I am just a beginner . I just typed the code. Can you help me in
>> understanding  where i am not correct.
>>
>> ---
>>
>> - hosts: devops
>>
>>   tasks:
>> - debug:
>>msg: "{{ hostinfo|dictsort|selectattr('1.hostclass', 'equalto',
>> 'ess')|first|first }}"
>>
>> ~
>> ~
>>
>>
>>
>>
>> On Wednesday, April 11, 2018 at 8:54:15 PM UTC+5:30, Bishwajit Samanta
>> 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/e685426e-a978-4ae9-be43-6ed342d3225a%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/CAD8N0v_4ORtzwLKugC%2B65sREp%3D6awndkQjzao2V2Eu_zn5O2Gw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-04-11 Thread Bishwajit Samanta
@Matt Martz : I am sorry to ask silly questions, regarding ansible as by 
seeing the small piece of code, i can understand you must be an ansible 
expert. If possible you can help me in my problem explanation a bit. 

And any such links for learning you want to refer, please refer me. As i 
googled selectattr but first|first parameter which you have passed i am not 
getting any good document. If you can help me in referring such, it would 
be of very nice help.


On Wednesday, April 11, 2018 at 9:36:13 PM UTC+5:30, Bishwajit Samanta 
wrote:
>
> I am glad you replied so fast, but sorry to say i am not an ansible expert 
> . I am just a beginner . I just typed the code. Can you help me in 
> understanding  where i am not correct.
>
> ---
>
> - hosts: devops
>
>   tasks:
> - debug:
>msg: "{{ hostinfo|dictsort|selectattr('1.hostclass', 'equalto', 
> 'ess')|first|first }}"
>
> ~
> ~
>
>
>
>
> On Wednesday, April 11, 2018 at 8:54:15 PM UTC+5:30, Bishwajit Samanta 
> 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/e685426e-a978-4ae9-be43-6ed342d3225a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2018-04-11 Thread Bishwajit Samanta
I am glad you replied so fast, but sorry to say i am not an ansible expert 
. I am just a beginner . I just typed the code. Can you help me in 
understanding  where i am not correct.

---

- hosts: devops

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

~
~




On Wednesday, April 11, 2018 at 8:54:15 PM UTC+5:30, Bishwajit Samanta 
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/b649014c-236d-43ab-993b-3ec643fa8cda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.