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. 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 - debug: var: nagios_userid.stdout_lines Partial output: ok: [nagios] => { "nagios_userid": { "changed": true, "cmd": "curl -XGET \"http://nagios/nagiosxi/api/v1/system/user?apikey=<my api key>&pretty=1\"", "delta": "0:00:00.263619", "end": "2019-01-29 12:54:17.693892", "failed": false, "rc": 0, ... "stdout_lines": [ "{", " \"records\": 27,", " \"users\": [", " {", " \"user_id\": \"37\",", " \"username\": \"someguy\",", " \"name\": \"Some Guy\",", " \"email\": \"s...@example.com\",", " \"enabled\": \"1\"", " },", " {", " \"user_id\": \"36\",", " \"username\": \"somegal\",", " \"name\": \"Some Gal\",", " \"email\": \"s...@example.com\",", " \"enabled\": \"1\"", " },", " {", " \"user_id\": \"34\",", " \"username\": \"gpyle\",", " \"name\": \"Gomer Pyle\",", " \"email\": \"gp...@example.com\",", " \"enabled\": \"1\"", " },", .... -- 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/dd4c1b8c-d5cb-434b-b577-a563f09fd8e1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.