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

fix issue with userparameters failing when trying to deploy a script #1205

Merged
merged 3 commits into from
May 1, 2024

Conversation

zshahan
Copy link
Contributor

@zshahan zshahan commented Apr 12, 2024

SUMMARY

When deploying scripts, ansible was attempting to create userparameters, rather than deploying the script file. This change adds an additional conditional where the userparameters task does not try use defined scripts.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

community.zabbix.roles.zabbix_agent, all userparameter tasks in tasks/userparameters.yml

ADDITIONAL INFORMATION

Currently, while the module states it supports deploying zabbix scripts, it does not work and fails the ansible run.

Copy link
Collaborator

@pyrodie18 pyrodie18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a change fragment.

@zshahan
Copy link
Contributor Author

zshahan commented Apr 13, 2024

@pyrodie18 added change fragment.

@flowerysong
Copy link
Contributor

flowerysong commented Apr 13, 2024

This whole file could be cleaned up quite a bit. It's more efficient to loop over the items that meet your criteria instead of looping over everything, and it's more readable to not have so much duplication.

---
- tags:
    - config
  block:
    - when:
        - ansible_os_family == "Windows"
      notify:
        - restart win zabbix agent
      block:
        - name: Windows | Install user-defined userparameters
          ansible.windows.win_template:
            src: "{{ zabbix_agent_userparameters_templates_src }}/{{ item.name }}.j2"
            dest: '{{ zabbix_agent_win_include }}\{{ item.name }}.conf'
          loop: "{{ zabbix_agent_userparameters | rejectattr('scripts_dir', 'defined') }}"

        - name: Windows | Install user-defined scripts
          ansible.windows.win_copy:
            src: "{{ zabbix_agent_userparameters_scripts_src }}/{{ item.scripts_dir }}"
            dest: '{{ zabbix_win_install_dir }}\scripts\'
          loop: "{{ zabbix_agent_userparameters | selectattr('scripts_dir', 'defined') }}"

    - when:
        - ansible_os_family != 'Windows'
      notify:
        - restart zabbix-agent
        - restart mac zabbix agent
      become: true
      block:
        - name: Install user-defined userparameters
          ansible.builtin.template:
            src: "{{ zabbix_agent_userparameters_templates_src }}/{{ item.name }}.j2"
            dest: "{{ zabbix_agent2_include if zabbix_agent2 else zabbix_agent_include }}/userparameter_{{ item.name }}.conf"
            owner: zabbix
            group: zabbix
            mode: "0644"
          loop: "{{ zabbix_agent_userparameters | rejectattr('scripts_dir', 'defined') }}"

        - name: Install user-defined scripts
          ansible.builtin.copy:
            src: "{{ zabbix_agent_userparameters_scripts_src }}/{{ item.scripts_dir }}"
            dest: /etc/zabbix/scripts/
            owner: zabbix
            group: zabbix
            mode: "0755"
          loop: "{{ zabbix_agent_userparameters | selectattr('scripts_dir', 'defined') }}"

@pyrodie18 pyrodie18 self-requested a review April 16, 2024 01:36
@pyrodie18 pyrodie18 merged commit e215196 into ansible-collections:main May 1, 2024
99 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants