Re: [ansible-project] Iterating through stdout_lines (jinja formatted data) and returning data

2019-01-29 Thread John Harmon
Thank you... much easier than what I was doing.

-- 
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/f39303c0-3c68-4eaa-883e-30df777155cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Iterating through stdout_lines (jinja formatted data) and returning data

2019-01-29 Thread Kai Stian Olstad

On 29.01.2019 21:19, John Harmon wrote:
I wish to automate user removal from nagios.  This can be done via 
their
REST api; however, I first need to find the user, grab their user_id, 
and
then I can perform the delete based on the user_id.  Their API returns 
the

info in jinja format.


It's not Jinja, its JSON.



I don't know how to iterate through the output, find
the username, and grab the correlating user_id.  For example, how can I
obtain the user_id for the user: somegal?

My playbook:
---
- hosts: nagios
  gather_facts: false

  tasks:
- name: Get nagios user info
  shell: 'curl -XGET
"http://nagios/nagiosxi/api/v1/system/user?apikey=key>=1"'

  register: nagios_userid


You should use the uri module since it gives you the result in .json
Never used Nagios api, but looks like is just a ordinary REST api.
So this should work.

  - name: Get nagios user infouri:
url: http://nagios/nagiosxi/api/v1/system/user?apikey=
headers:
  Content-Type: application/json
register: nagios_userid

Then you can use nagios_userid.json as an ordinary variable in Ansible.


--
Kai Stian Olstad

--
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/c63ba3a7130f80e080a87a8c809bdb52%40olstad.com.
For more options, visit https://groups.google.com/d/optout.