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

module_defaults group for zabbix modules #326

Closed
D3DeFi opened this issue Feb 11, 2021 · 11 comments · Fixed by #833
Closed

module_defaults group for zabbix modules #326

D3DeFi opened this issue Feb 11, 2021 · 11 comments · Fixed by #833
Assignees
Labels
enhancement New feature or request module The issue or pull request is related to Zabbix module

Comments

@D3DeFi
Copy link
Contributor

D3DeFi commented Feb 11, 2021

SUMMARY

It should be now possible for collections to somehow define module_defaults for groups. E.g.:

module_defaults:
  group/zabbix:
    server_url: http://zabbix
    login_user: Admin
    timeout: 15
ISSUE TYPE
  • Feature Idea
COMPONENT NAME

plugins/

ADDITIONAL INFORMATION

Additional reference:
ansible/ansible#69919
ansible/ansible#67291

@D3DeFi D3DeFi self-assigned this Feb 11, 2021
@D3DeFi D3DeFi added enhancement New feature or request module The issue or pull request is related to Zabbix module labels Feb 11, 2021
@D3DeFi D3DeFi changed the title module_defaults for zabbix plugin group module_defaults group for zabbix modules Feb 11, 2021
@D3DeFi
Copy link
Contributor Author

D3DeFi commented Mar 27, 2021

This unfortunately never made it into the ansible as a feature. So it is not possible yet

@D3DeFi D3DeFi closed this as completed Mar 27, 2021
@ghost
Copy link

ghost commented Oct 21, 2022

@D3DeFi Maybe it's a good idea to reopen this once since it's available from version 2.12?

In ansible-core 2.12, collections can define their own groups in the meta/runtime.yml file. module_defaults does not take the collections keyword into account, so the fully qualified group name must be used for new groups in module_defaults.

Ref: https://docs.ansible.com/ansible/latest/user_guide/playbooks_module_defaults.html

@D3DeFi
Copy link
Contributor Author

D3DeFi commented Oct 21, 2022

Yees, but! :) We are migrating away from zabbix-api into httpapi. With 1.9 this would be released as opt-in, with 2.0 zabbix-api will be dropped altogether.

I am not sure that defining module_defaults group for community.zabbix would be necessary anymore as shared connection parameters for httpapi are set only once I think.

@BGmot can you share your opinion here when you have a little bit of time to spare please?

@BGmot
Copy link
Collaborator

BGmot commented Oct 21, 2022

I am not sure I understand the request. module_defaults is used on tasks level, so everybody is free to use it with our collection. And we do use this 'feature' in our modules tests.

@D3DeFi
Copy link
Contributor Author

D3DeFi commented Oct 21, 2022

I am not sure I understand the request. module_defaults is used on tasks level, so everybody is free to use it with our collection. And we do use this 'feature' in our modules tests.

Normally, you have to specify module_defaults per module:

  module_defaults:
    community.zabbix.zabbix_host:
      server_url: ...
      login_user: ...
      login_pass: ...

    community.zabbix.zabbix_groupt:
      server_url: ...
      login_user: ...
      login_pass: ...

But implementing this in collections runtime.yml would allow users to provide:

module_defaults:
  group/zabbix:
    server_url: http://zabbix
    login_user: Admin
    timeout: 15

and it would be inherited by all modules in the collection.

However, I am not sure if we still have need for this as login credentials will be set only once for httpapi if I understand it correctly, so they don't have to be repeated for each module as it was with zabbix-api.

Except validate_certs and timeout we may not have much more options to share.

Anyway, as I am looking at it. This only requires keeping list of modules in runtime.yml from our side, I think we should implement it:

# collections/ansible_collections/ns/coll/meta/runtime.yml
action_groups:
  groupname:
    - module
    - another.collection.module

Re-opening the issue.

@D3DeFi D3DeFi reopened this Oct 21, 2022
@BGmot
Copy link
Collaborator

BGmot commented Oct 21, 2022

How is it different from modules parameters defaults?

@ghost
Copy link

ghost commented Oct 21, 2022

Yees, but! :) We are migrating away from zabbix-api into httpapi. With 1.9 this would be released as opt-in, with 2.0 zabbix-api will be dropped altogether.

I am not sure that defining module_defaults group for community.zabbix would be necessary anymore as shared connection parameters for httpapi are set only once I think.

This is amazing! I come to the same conclusion when I read the documentation for the httpapi connection plugin.

Anyway, as I am looking at it. This only requires keeping list of modules in runtime.yml from our side, I think we should implement it:

Thanks a lot, appreciate it!

@D3DeFi
Copy link
Contributor Author

D3DeFi commented Oct 22, 2022

How is it different from modules parameters defaults?

We have 20+ modules, lets ignore httpapi for a moment and pretend that we will be using 15 modules in our playbook, each multiple times. We know that there will be lot of code duplicity due to server_url, login_password, login_user and more. Without group module_defaults, this would be:

- hosts: all
  module_defaults:
    community.zabbix.zabbix_host:
      server_url: ...
      login_user: ...
      login_pass: ...

    community.zabbix.zabbix_group:
      server_url: ...
      login_user: ...
      login_pass: ...

    community.zabbix.zabbix_action:
      server_url: ...
      login_user: ...
      login_pass: ...

    community.zabbix.zabbix_service:
      server_url: ...
      login_user: ...
      login_pass: ...

   ... and so on for each module ...

  tasks:
    ...

Now, with group module_defaults, the same playbook will look like this:

- hosts: all
  module_defaults:
    group/community.zabbix.zabbix:
      server_url: ...
      login_user: ...
      login_pass: ...
  tasks:
    ...

That's it. Now back to the httpapi - I know it will deprecate some of the stuff, instead of specifying server_url, login_password, login_user, etc without need to provide them under each module call. However, I think users may still benefit from having group module_defaults for a smaller use cases than I presented. Maybe I am not able to bring up more elaborate use case, but never underestimate users of your code! 😄

This small example also comes to my mind:

# roles/myrole/tasks/setup-zabbix-resources.yml
module_defaults:
  group/community.zabbix.zabbix:
    state: present

- set_fact:
    ...httpapi parameters...

- zabbix_host:
    ...

- zabbix_group:
    ...

@BGmot
Copy link
Collaborator

BGmot commented Oct 22, 2022

Thank you very much for explanation, now I get it and sure we need this "feature".

@D3DeFi
Copy link
Contributor Author

D3DeFi commented Nov 1, 2022

@ansiballZ would you have any chance to test my proposed changes in #833?

@ghost
Copy link

ghost commented Nov 1, 2022

Sure thing, happy to help!
So, I cloned your repo and ran on the module-defaults-group branch and it works flawless. That is after banging my head to the wall a couple of time before remembering I had to use Ansible 2.12+.

EDIT: I saw the discussion in the PR and my testing is only done with server_url, login_user, and login_password.

I really appreciate this implementation. Thank you very much!

@BGmot BGmot closed this as completed in #833 Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module The issue or pull request is related to Zabbix module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants