telekom-mms/ansible-collection-icinga-director

updating objects - only give fields to change

zatroa opened this issue · 5 comments

when updating an object (e.g. Icinga Host), is there a way to specify only the fields that should change?

for example:

  • name: icinga host sync

    hosts: test.host.tld
    tasks:

    • name: icinga - host update
      t_systems_mms.icinga_director.icinga_host:
      state: present
      url: "{{ lookup('env', 'ICINGA_URL') }}"
      url_username: "{{ lookup('env', 'ICINGA_USERNAMEURL') }}"
      url_password: "{{ lookup('env', 'ICINGA_PASSWORD') }}"
      object_name: "{{ inventory_hostname }}"
      display_name: "to be changed`

reports the error that the "imports" section is missing, but I only want to change the "display_name":

TASK [icinga - host update] ********************************************************************************************************************************************************************************************************************************************************************************************************************************************** fatal: [test.host.tld]: FAILED! => {"changed": false, "msg": "state is present but all of the following are missing: imports"}

We already had a discussion about updating/appending to objects here: https://github.com/T-Systems-MMS/ansible-collection-icinga-director/issues/96

Check @schurzi's solution for this out: https://github.com/T-Systems-MMS/ansible-collection-icinga-director/issues/96#issuecomment-770026563

Though maybe I'll have to think about my opinion again, if it seems that people need that functionality.. Let's keep this ticket open.

First let me thank you for your great work. the ansible icinga collection is very helpful!

@schurzi's solution / workaround works for us too.
However, it is indeed not very elegant.
For example, if I forget to explicitly pass a newly added field when updating, it will be removed.
Or if a field is not always set, an error occurs quickly. For example, the field "display_name" is not always set, then the following error occurs:

fatal: [host.tld]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'display_name'\n\nThe error appears to be in '/home/ansible/sysadm/playbooks/icinga_test.yml': line 18, column 5, but may be elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n msg: "{{ result.objects[0] }}"\n - name: icinga - host update\n ^ here\n"}

In my opinion we don't need a complete delta logic, it would be perfectly sufficient to just specify the parameters which should be changed / overwritten.

The branch "append" has an initial solution for the icinga_host module.

This works. Notice that in the second task, there is no "address", but an "append: true".

- name: Create a host in icinga
  t_systems_mms.icinga_director.icinga_host:
    state: present
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
    object_name: "foohosta"
    address: "127.0.0.1"
    imports:
      - "foohosttemplate"

- name: Create a host in icinga
  t_systems_mms.icinga_director.icinga_host:
    state: present
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
    display_name: "foohosta"
    object_name: "foohosta"
    append: True

first task:
grafik

second task:
grafik

Without "append: true":

---
- name: Create a host in icinga
  t_systems_mms.icinga_director.icinga_host:
    state: present
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
    object_name: "foohostb"
    address: "127.0.0.1"
    imports:
      - "foohosttemplate"

- name: Create a host in icinga
  t_systems_mms.icinga_director.icinga_host:
    state: present
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
    display_name: "foohosta"
    object_name: "foohostb"
    append: False

First task:
grafik

Second task:
grafik

the branch works fine for me too. i think this is a good solution.
Thanks for the quick support.

Hi @zatroa, we implemented the append-function here for all modules: https://github.com/T-Systems-MMS/ansible-collection-icinga-director/pull/153

I'd be glad f you would test it and give feedback.