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: falsetasks:
- name: Get nagios user info
shell: 'curl -XGET
"http://nagios/nagiosxi/api/v1/system/user?apikey=<my api >&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.