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] Clone objects #193

Open
mdicss opened this issue Dec 12, 2022 · 3 comments
Open

[Enhancement] Clone objects #193

mdicss opened this issue Dec 12, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@mdicss
Copy link

mdicss commented Dec 12, 2022

Description

It should be possible to clone objects by using the icinga director collection for ansible.

To clone objects is possible in the director gui and with 'icingacli director clone --from [options]' . To have clone, maybe you have to combine getting the object, generating a new one and deleting the old.
We often define new objects by cloning them in the gui, defining a new name and changing only some attributes like ip-address and display name for host objects. Sure, you can read the objects definition by an info-command and then create a new one defining all possible parameters, but it would be very handy to have a clone option. Clone also would make it easier to rename e.g. a host by clone it and remove the original object.

Additional information

...

@mdicss mdicss added the enhancement New feature or request label Dec 12, 2022
@rndmh3ro
Copy link
Collaborator

I'm not sure about this.

Why not just copy the code, make changes to it and then run it? After all you already have the code for the first object (the source of the clone).

To have clone, maybe you have to combine getting the object, generating a new one and deleting the old.

What would happen if you run the same playbook again? If the original is deleted, then you cannot copy it. Should the playbook fail because of the missing source (it wouldn't be idempotent), or should it run successfully to make it idempotent?

@mdicss
Copy link
Author

mdicss commented Dec 12, 2022

Sorry, I was thinking about changing the name of an object e.g. a host and so my post is misleading.
Clone would be nice. As far as I see, you need two steps in the director api. First get the information about the original object and then define the copy with a new name maybe with some changes of parameters also. There should be no problem, running the playbook several times. The sentence in my post you cited is wrong. 'deleting the old' should be deleted there.
Rename an object, surely, can not be repeated. So you have to select and clone the objects first. When this is successfully done, you can delete the old objects in a separate step. You are right, when I do this in one playbook, I have the risk to loose some information in the case of failures.

@rndmh3ro
Copy link
Collaborator

I'm still not sure about this. I think "you're holding it wrong" - your workflow seems to be at odds with Ansible.

Here's an example playbook to clone things:

---
- name: gather hosts
  t_systems_mms.icinga_director.icinga_host_info:
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
  register: icinga_host

- name: update 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: "newname"
    append: true
    accept_config: "false"
    check_command: "{{ item.check_command }}"
  loop: "{{ icinga_host.objects }}"
  when: item.object_name == "foohost2"

This copies foohost2 and creates a new host called newname. To use the same attributes, you need to add them all like accept_config: "{{ item.accept_config }}". To overwrite parameters, just define them new (like in accept_config).

So this seems easy enough to do. If you need a module for this, I'd be open to accept a PR, but I won't implement it.

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

2 participants