diff --git a/handlers/main.yml b/handlers/main.yml index 467a651..9ae5386 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -207,4 +207,11 @@ - config is defined - config.changed | bool +# zabbix agent +- name: restart zabbix agent # noqa no-changed-when + ansible.builtin.command: configctl zabbixagent restart + when: + - config is defined + - config.changed | bool + ... diff --git a/tasks/main.yml b/tasks/main.yml index 331addc..7924a48 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -286,6 +286,14 @@ apply: tags: nut +- name: zabbix agent + tags: + - always + ansible.builtin.include_tasks: + file: zabbixagent.yml + apply: + tags: zabbix-agent + - name: trim EOF delegate_to: localhost ansible.builtin.lineinfile: diff --git a/tasks/zabbixagent.yml b/tasks/zabbixagent.yml new file mode 100644 index 0000000..969155d --- /dev/null +++ b/tasks/zabbixagent.yml @@ -0,0 +1,77 @@ +--- + +# requires plugin os-zabbix*-agent to be installed +# +# opn_zabbixagent: +# local: +# hostname: my-opnsense-instance +# settings: +# main: +# enabled: 1 +# serverList: +# listenPort: 10050 +# listenIP: 0.0.0.0 +# sudoRoot: 1 +# tuning: +# timeout: 10 +# features: +# enableActiveChecks: 1 +# activeCheckServers: +# enableRemoteCommands: 1 +# encryption: 1 +# encryptionidentity: my-opnsense-instance +# encryptionpsk: zabbixpsk +# userparameters: +# 980e7ff4-6f59-4072-82a1-e78655ecd70b: +# key: opn.version +# command: opnsense-version + +- name: zabbix agent - hostname + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: /opnsense/OPNsense/ZabbixAgent/local/{{ item.key }} + value: "{{ item.value }}" + pretty_print: true + notify: restart zabbix agent + with_dict: "{{ opn_zabbixagent.local | default({}) }}" + +- name: zabbix agent - main settings + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: /opnsense/OPNsense/ZabbixAgent/settings/main/{{ item.key }} + value: "{{ item.value }}" + pretty_print: true + notify: restart zabbix agent + with_dict: "{{ opn_zabbixagent.settings.main | default({}) }}" + +- name: zabbix agent - tuning + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: /opnsense/OPNsense/ZabbixAgent/settings/tuning/{{ item.key }} + value: "{{ item.value }}" + pretty_print: true + notify: restart zabbix agent + with_dict: "{{ opn_zabbixagent.settings.tuning | default({}) }}" + +- name: zabbix agent - features + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: /opnsense/OPNsense/ZabbixAgent/settings/features/{{ item.key }} + value: "{{ item.value }}" + pretty_print: true + notify: restart zabbix agent + with_dict: "{{ opn_zabbixagent.settings.features | default({}) }}" + +- name: zabbix agent - userparameters + ansible.builtin.include_tasks: zabbixagentuserparameters.yml + vars: + uuid: "{{ userparameter.key }}" + cfg: "{{ userparameter.value }}" + with_dict: + - "{{ opn_zabbixagent.userparameters | default({}) }}" + loop_control: + loop_var: userparameter diff --git a/tasks/zabbixagentuserparameters.yml b/tasks/zabbixagentuserparameters.yml new file mode 100644 index 0000000..f4e6e75 --- /dev/null +++ b/tasks/zabbixagentuserparameters.yml @@ -0,0 +1,21 @@ +--- + +- name: zabbix agent - userparameter id config + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: /opnsense/OPNsense/ZabbixAgent/userparameters/userparameter[@uuid='{{ uuid }}']/id + value: "{{ uuid }}" + pretty_print: true + notify: restart zabbix agent + +- name: zabbix agent - userparameter configs + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: /opnsense/OPNsense/ZabbixAgent/userparameters/userparameter[@uuid='{{ uuid }}']/{{ item.key }} + value: "{{ item.value }}" + pretty_print: true + notify: restart zabbix agent + with_dict: + - "{{ cfg | default({}) }}"