-
Notifications
You must be signed in to change notification settings - Fork 35
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
Improve performance of icinga2_object action plugin #339
base: main
Are you sure you want to change the base?
Improve performance of icinga2_object action plugin #339
Conversation
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Luca Gubler.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Luca Gubler.
|
Thank you very much @lucagubler! Could you also share an example playbook? - name: Install Icinga
become: true
hosts: ansible-debian12
vars:
icinga2_confd: "local.d"
icinga2_config_directories:
- "local.d"
icinga2_purge_features: true
icinga2_features:
- name: api
ca_host: none
endpoints:
- name: NodeName
zones:
- name: ZoneName
endpoints:
- NodeName
- name: notification
state: absent
icinga2_objects:
- name: Host1
type: Host
file: "local.d/hosts.conf"
check_command: dummy
roles:
- icinga.icinga.repos
- icinga.icinga.icinga2 |
That's strange. The only difference I can see is that you're using the Here are the vars I use to setup Icinga2 icinga2_constants:
TicketSalt: "{{ vault_ticket_salt }}"
NodeName: "{{ ansible_fqdn }}"
ZoneName: "main"
ScriptDir: /etc/icinga2/scripts
icinga2_confd: false
icinga2_purge_features: true
icinga2_config_directories:
- zones.d/main/commands
- zones.d/main/hosts
- zones.d/main/services
icinga2_features:
- name: icingadb
host: 127.0.0.1
- name: notification
- name: checker
- name: api
ca_host: none
endpoints:
- name: NodeName
zones:
- name: ZoneName
endpoints:
- NodeName
- name: mainlog
severity: information
icinga2_objects:
- name: Host1
type: Host
file: "zones.d/main/hosts.conf"
check_command: dummy
|
I thought I might be going mad. So I decided to use podman to make sure I don't pull any plugins / roles / collections from the wrong place. If anyone sees where I'm messing up, please let me know! My complete setup to test looks as follows and does not end with my host being deployed: podman run --rm -it --name ansible-test debian:12 bash
apt update
apt install -y vim git ansible
ansible-galaxy collection install git+https://github.com/lucagubler/ansible-collection-icinga.git,fix/improve-icinga2-object-action-plugin-performance-338 hosts.ini: [all]
testhost ansible_host=locahost ansible_connection=local ansible_user=root play.yml: - name: Install Icinga
become: true
hosts: testhost
vars:
icinga2_constants:
TicketSalt: "123"
NodeName: "{{ ansible_fqdn }}"
ZoneName: "main"
ScriptDir: /etc/icinga2/scripts
icinga2_confd: false
icinga2_purge_features: true
icinga2_config_directories:
- zones.d/main/commands
- zones.d/main/hosts
- zones.d/main/services
icinga2_features:
- name: icingadb
host: 127.0.0.1
- name: notification
- name: checker
- name: api
ca_host: none
endpoints:
- name: NodeName
zones:
- name: ZoneName
endpoints:
- NodeName
- name: mainlog
severity: information
icinga2_objects:
- name: Host1
type: Host
file: "zones.d/main/hosts.conf"
check_command: dummy
roles:
- icinga.icinga.repos
- icinga.icinga.icinga2
I think the interesting part is this:
|
@Donien I think I found the issue. The Ansible task If you remove the Do we need to keep the We could do the following:
This way we only have to copy a single file which may increase performance. However, I haven't tested that yet. |
Well, in my case the ansible controller and the target host were both the same container. So it should have worked there.
The problem I see with delegation to the ansible controller is that we could have multiple hosts. And yes, idempotency is a big concern. With my approach I had to resort to sorting every (Icinga) object I think bulk writing objects that go to the same file would already greatly increase performance without having to work around quirky ansible module idempotency issues. |
Thanks, I'll have a look at it. Right now the icinga2_object is an action plugin. As far as I know action plugins are executed on localhost. Couldn't we just convert that to a custom library module? By default they will be executed on the remote host. This way we don't have to copy the files anymore. |
But: If you run another module using Example: file_args = dict()
file_args['state'] = 'directory'
file_args['path'] = path
file_module = self._execute_module(
module_name='file',
module_args=file_args,
task_vars=task_vars,
tmp=tmp
) Basically, the calculations and creation of the config is delegated to the Ansible Controller (action plugin) but the deployment of a file is done on the target host ( When we talk about copying we actually copy twice:
So we don't copy files from the Controller. We copy content (lives in RAM) to the target host and then copy files locally on the target host from The reason deployment is done in
I think keeping the logic that builds the configuration in an action module is beneficial since connections to the target host are only made once a write operation happens. So before doing a write operation the code can decide if writing is even necessary. |
No description provided.