Skip to content

Commit

Permalink
Reworked include logic in agent role(#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thulium-Drake authored Jul 19, 2024
1 parent 93eac6b commit c229ac6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/1335-rework-include-logic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- zabbix_agent Role - Reworked Include logic based on Alias logic
2 changes: 1 addition & 1 deletion roles/zabbix_agent/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ zabbix_agent_docker_ports:
zabbix_agent_docker_security_opts:
- apparmor:unconfined
zabbix_agent_docker_volumes:
- /etc/zabbix/zabbix_agentd.d:{{ zabbix_agent_include_dir }}
- /etc/zabbix/zabbix_agentd.d:{{ zabbix_agent_docker_include_dir }}
- /:/hostfs:ro
- /etc:/hostfs/etc:ro
- /proc:/hostfs/proc:ro
Expand Down
1 change: 1 addition & 0 deletions roles/zabbix_agent/tasks/Docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: "Create volume mount string"
ansible.builtin.set_fact:
zabbix_agent_docker_include_dir: "{{ (zabbix_agent_include_dir is iterable) | ternary(zabbix_agent_include_dir[0], zabbix_agent_include_dir) }}"
volume_mount: "{{ zabbix_agent_tlspskfile }}:/var/lib/zabbix/enc/tlspskfile"
tls_key:
ZBX_TLSPSKFILE: tlspskfile
Expand Down
16 changes: 16 additions & 0 deletions roles/zabbix_agent/tasks/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@
become: true
tags:
- config
when: zabbix_agent_include_dir is string

- name: "Create include dirs zabbix-agent"
ansible.builtin.file:
path: "{{ include_dir }}"
owner: root
group: zabbix
mode: "{{ zabbix_agent_include_mode }}"
state: directory
loop: "{{ zabbix_agent_include_dir | list }}" # To prevent errors, filter a string value as a list
loop_control:
loop_var: 'include_dir'
when: zabbix_agent_include_dir is iterable
become: true
tags:
- config

- name: "Install the Docker container"
ansible.builtin.include_tasks: Docker.yml
Expand Down
4 changes: 0 additions & 4 deletions roles/zabbix_agent/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
zabbix_agent_tlsaccept: "{{ zabbix_agent_tlsaccept is defined | ternary(zabbix_agent_tlsaccept, 'unencrypted')}}"
zabbix_agent_tlsconnect: "{{ zabbix_agent_tlsconnect is defined | ternary(zabbix_agent_tlsconnect, 'unencrypted')}}"

- name: Set Include Files
ansible.builtin.set_fact:
zabbix_agent_include: "{{ zabbix_agent_include is defined | ternary(zabbix_agent_include, zabbix_agent_include_dir + '/*.conf') }}"

- name: Setting Zabbix API Server Port
ansible.builtin.set_fact:
zabbix_api_server_port: "{{ '443' if zabbix_api_use_ssl|bool else '80' }}"
Expand Down
12 changes: 11 additions & 1 deletion roles/zabbix_agent/templates/agent.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ DenyKey={{ item }}
{{ (zabbix_agent_hostmetadataitem is defined and zabbix_agent_hostmetadataitem is not none) | ternary('', '# ') }}HostMetadataItem={{ zabbix_agent_hostmetadataitem | default('') }}
{{ (zabbix_agent_hostname is defined and zabbix_agent_hostname is not none) | ternary('', '# ') }}Hostname={{ zabbix_agent_hostname | default('') }}
{{ (zabbix_agent_hostnameitem is defined and zabbix_agent_hostnameitem is not none) | ternary('', '# ') }}HostnameItem={{ zabbix_agent_hostnameitem | default('') }}
{{ (zabbix_agent_include is defined and zabbix_agent_include is not none) | ternary('', '# ') }}Include={{ zabbix_agent_include | default('') }}
{% if zabbix_agent_include_dir is defined and zabbix_agent_include_dir %}
{% if zabbix_agent_include_dir is string %}
Include={{ zabbix_agent_include_dir }}/*.conf
{% else %}
{% for item in zabbix_agent_include_dir %}
Include={{ item }}/*.conf
{% endfor %}
{% endif %}
{% else %}
# Include=
{% endif %}
{% if not zabbix_agent2 %}
{{ (zabbix_agent_listenbacklog is defined and zabbix_agent_listenbacklog is not none) | ternary('', '# ') }}ListenBacklog={{ zabbix_agent_listenbacklog | default('') }}
{% endif %}
Expand Down
4 changes: 3 additions & 1 deletion roles/zabbix_agent/vars/agent2_vars.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
_pidfile: /var/run/zabbix/zabbix_agent2.pid
_logfile: /var/log/zabbix/zabbix_agent2.log
_include: /etc/zabbix/zabbix_agent2.d
_include:
- /etc/zabbix/zabbix_agent2.d
- /etc/zabbix/zabbix_agent2.d/plugins.d
_tls_subject: "{{ zabbix_agent_tlsservercertsubject | default(omit) }}" # FIXME this is not correct and should be removed with 2.0.0, here only to prevent regression
_win_package: zabbix_agent2-{{ zabbix_version_long }}-windows-amd64-openssl-static.zip
_win_download_link: "{{ zabbix_win_download_url }}/{{ zabbix_version_long | regex_search('^\\d+\\.\\d+') }}/{{ zabbix_version_long }}/{{ zabbix_win_package | default(_win_package) }}"
Expand Down

0 comments on commit c229ac6

Please sign in to comment.