Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add implicit deletion function #231

Open
flkhndlr opened this issue Nov 30, 2023 · 3 comments
Open

[Enhancement] Add implicit deletion function #231

flkhndlr opened this issue Nov 30, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@flkhndlr
Copy link
Contributor

Description

You currently need to explicitly state the Icinga Director Objects you want to delete. We encountered several situations, where a object was deleted as code, but not removed. The reason is, that you need to state them as a deletion office.
A solution could be to implicitly delete the Objects when removed in Ansible

We came up with following solution as a playbook:

---
- hosts: localhost
  gather_facts: false
  collections:
    - t_systems_mms.icinga_director
  tasks:
    - name: include Vars
      ansible.builtin.include_vars:
        file: vars/icinga_service.yml

    - name: get all object configs
      telekom_mms.icinga_director.icinga_service_info:
        url: "{{ icinga_host }}"
        url_username: "{{ icinga_user }}"
        url_password: "{{ icinga_pass }}"
        query: "*"
        force_basic_auth: true
      register: result

    - name: create objects scheduled for deletion
      set_fact:
        icinga_services: "{{ icinga_services + [{'service_object': [item.object_name], 'state': 'absent' }] }}"
      when: not icinga_services|selectattr('service_object', 'contains', item.object_name)
      loop: "{{ result.objects }}"

  roles:
    - ansible_icinga
  vars:
    icinga_force_basic_auth: true

Is there a way to include this either into the collection as an example or create a solution in the role or modules itself?
Thanks in advance!

Additional information

No response

@flkhndlr flkhndlr added the enhancement New feature or request label Nov 30, 2023
@schurzi
Copy link
Contributor

schurzi commented Nov 30, 2023

Your code shows how to select all objects for deletion, but it does not actually delete them, if I understand right. Can you extend this to also delete them with our collection?

I am thinkging how we can document this, since this shows an important part of the usage, that is hard to get right. My first thought was to add it in playbooks/ to offer a ready to use implementation where one is only expected to add their variables and everything else is ready to use.

Another approach might be to add further documentation in docs/ to illustrate all kinds of usage patterns and also describe tradeoffs and offer help to decide on specific implementations. (covering tutorials or how-tos as described in https://diataxis.fr/)

@schurzi schurzi changed the title Add implicite deletion function [Enhancement] Add implicit deletion function [Enhancement] Nov 30, 2023
@rndmh3ro
Copy link
Collaborator

rndmh3ro commented Dec 1, 2023

Is there a way to include this either into the collection as an example or create a solution in the role or modules itself?

I don't think this should be part of a module, but I like the idea of creating a new role that does exactly this for all resources. Or alternatively document it like @schurzi described.

Your code shows how to select all objects for deletion, but it does not actually delete them, if I understand right. Can you extend this to also delete them with our collection?

It already does in the set_fact step. There's the state: absent part.

My first thought was to add it in playbooks/ to offer a ready to use implementation where one is only expected to add their variables and everything else is ready to use.

I'm not sure this will work. vars_files doesn't work for import_playbook (see), so you'd have to do some workaround like described here.

@schurzi
Copy link
Contributor

schurzi commented Dec 1, 2023

I don't think this should be part of a module, but I like the idea of creating a new role that does exactly this for all resources.

I like the idea of a separate "cleanup" role. (Or maybe an additional flag for the existing role?)

It already does in the set_fact step. There's the state: absent part.

Yeah, I missed that part. All good.

@rndmh3ro rndmh3ro changed the title Add implicit deletion function [Enhancement] [Enhancement] Add implicit deletion function Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants