community.zabbix
community.zabbix copied to clipboard
fix issue with userparameters failing when trying to deploy a script
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.
@pyrodie18 added change fragment.
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') }}"