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=<my api
key>&pretty=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=<my api key>
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 [email protected].
To post to this group, send email to [email protected].
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.