Can't use fields available in API - e.g. host_template - has_agent
astaruch opened this issue · 4 comments
Hi, really nice project over here :).
I was trying to create host_template for my linux-agent
object and I needed to use field in Director "Icinga Agent and zone settings -> Icinga2 Agent". I couldn't find it in your Ansible docs whether it is supported - then stumbled upon implementation and saw that it is not implemented.
Is there possibility to define in icinga_host_template
somehow has_agent=y
parameter right now?
Right now my workaround:
- name: create linux-agent template
icinga_host_template:
state: present
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
object_name: "linux-agent"
imports:
- generic-host
- name: enable Icinga2 agent field on linux-agent host template
uri:
url: "{{ icinga_url }}/director/host?name=linux-agent"
headers:
Accept: application/json
method: POST
user: "{{ icinga_user }}"
password: "{{ icinga_pass }}"
return_content: true
body:
has_agent: y
master_should_connect: y
accept_config: y
body_format: json
status_code:
- 200 # OK
- 304 # Not modified
I really appreciate this collection, thanks for sharing.
Hi @astaruch,
I just looked into the API:
> curl 'https://icinga/director/host?name=foo-live-app02&withNull=true' -H "Accept: application/json"
{
"accept_config": null,
"action_url": null,
"address": "172.29.114.8",
"address6": null,
"api_key": null,
"check_command": null,
"check_interval": null,
"check_period": null,
"check_timeout": null,
"command_endpoint": null,
"disabled": false,
"display_name": null,
"enable_active_checks": null,
"enable_event_handler": null,
"enable_flapping": null,
"enable_notifications": null,
"enable_passive_checks": null,
"enable_perfdata": null,
"event_command": null,
"flapping_threshold_high": null,
"flapping_threshold_low": null,
"groups": [],
"has_agent": null,
"icon_image": null,
"icon_image_alt": null,
"imports": [
"Standardserver"
],
"master_should_connect": null,
"max_check_attempts": null,
"notes": null,
"notes_url": null,
"object_name": "foo-live-app02",
"object_type": "object",
"retry_interval": null,
"template_choice": null,
"vars": {},
"volatile": null,
"zone": null
}
I guess you mean these three parameters, right?
"has_agent": null,
"master_should_connect": null,
"accept_config": null,
If you mean these, then yes, we can implement them.
To add, we want and should support all of these fields. However there was no need and no time to do that yet.
Hi @rndmh3ro,
Yes, these three parameters:
body:
has_agent: y
master_should_connect: y
accept_config: y
I understand that it would be time consuming to provide 1:1 mapping for the whole director API, especially when there is no need from your side, and since I have a working workaround, it doesn't need to bother you right now.
If you want to help with it, you probably just need to add the new parameters to these 4 places:
- docs: https://github.com/T-Systems-MMS/ansible-collection-icinga-director/blob/master/plugins/modules/icinga_host.py#L165
- example: https://github.com/T-Systems-MMS/ansible-collection-icinga-director/blob/master/plugins/modules/icinga_host.py#L188
- argument spec: https://github.com/T-Systems-MMS/ansible-collection-icinga-director/blob/master/plugins/modules/icinga_host.py#L222
- data: https://github.com/T-Systems-MMS/ansible-collection-icinga-director/blob/master/plugins/modules/icinga_host.py#L250
Then install yq on your system and run hacking/update_examples_and_tests.sh
. This updates the tests and example playbooks.