I need to remove multiple servers from multiple nagios monitoring via api keys with ansible. so I tried below solution but not able to get api key section in command and get the success output
example- hosts file -->
[nagios_server]
10.0.0.1 apikey=XXXXXXXX
10.0.0.2 apikey=YYYYYYYY
10.0.0.3 apikey=ZZZZZZZZ
[Linux_remove_machine]
192.168.0.1
192.168.0.2
Main.yml -->
---
- name: remove server from monitoring
hosts: localhost
vars:
output_path: "./reports/"
filename: "device_report_{{ date }}.csv"
tasks:
- include_tasks: nagios.yml
loop: "{{ groups['nagios_server'] }}"
loop_control:
loop_var: outer_item
register: check
- debug:
var=check
nagios.yml -->
- name: execute command in loop
shell:
curl -XDELETE "http://{{ outer_item }}/nagiosxi/api/v1/config/host?apikey=**{{apikey }}**&host_name={{ item }}&applyconfig=1
loop: "{{groups['Linux_remove_machine']}}"
register: remove_nagios
Expected below output
curl -XDELETE "http://10.0.0.1/......./XXXXXX/&host_name=192.168.0.1&applyconfig=1
curl -XDELETE "http://10.0.0.2/......./YYYYYY/&host_name=192.168.0.1&applyconfig=1
curl -XDELETE "http://10.0.0.3/......./ZZZZZZ/&host_name=192.168.0.1&applyconfig=1
curl -XDELETE "http://10.0.0.1/......./XXXXXX/&host_name=192.168.0.2&applyconfig=1
curl -XDELETE "http://10.0.0.2/......./YYYYYY/&host_name=192.168.0.2&applyconfig=1
curl -XDELETE "http://10.0.0.3/......./ZZZZZZ/&host_name=192.168.0.2&applyconfig=1