API Calls for external commands with Ansible
Posted: Tue Feb 11, 2020 5:34 pm
I am trying to run an external command to shut off notifications before an event on a remote Nagios XI server via Ansible.
Here is the playbook:
And here is the response:
It seems it does not like the format of the external command. Any ideas on how to do this?
Here is the playbook:
Code: Select all
# patch_nagios.yml -I am using the proposed name here.
- hosts: '{{ target }}'
vars_prompt:
- name: "target"
prompt: "Enter the Nagios hostname to patch"
private: no
tasks:
# Disable Nagios notifications for patching
- name: Disable Nagios XI Notifications
uri:
url: http://{{ target }}/nagiosxi/api/v1/system/corecommand?apikey={{ NagiosAPIKey }}
method: POST
body: 'DISABLE_NOTIFICATIONS'
force_basic_auth: yes
status_code: 201
...Code: Select all
TASK [Disable Nagios XI Notifications] ****************************************************************************************************************************
fatal: [onshore-tim-netmon-dev]: FAILED! => {"access_control_allow_methods": "*", "access_control_allow_orgin": "*", "changed": false, "connection": "close", "content": "{\"error\":\"You must specify an external command.\"}\n", "content_length": "50", "content_type": "application/json", "cookies": {}, "cookies_string": "", "date": "Tue, 11 Feb 2020 22:30:35 GMT", "elapsed": 0, "json": {"error": "You must specify an external command."}, "msg": "Status code was 200 and not [201]: OK (50 bytes)", "redirected": false, "server": "Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16", "status": 200, "url": "http://onshore-tim-netmon-dev/nagiosxi/api/v1/system/corecommand?apikey=REDACTED", "x_powered_by": "PHP/5.4.16"}