Skip to content

Commit

Permalink
Lots of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrodie18 committed May 14, 2024
1 parent 899abac commit 645c0ac
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 391 deletions.
179 changes: 71 additions & 108 deletions docs/ZABBIX_AGENT_ROLE.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions molecule/zabbix_agent_tests/common/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ provisioner:
inventory:
group_vars:
all:
zabbix_agent_src_reinstall: false
zabbix_install_pip_packages: false
zabbix_agent_server: 192.168.3.33
zabbix_agent_serveractive: 192.168.3.33
zabbix_agent_listenip: 0.0.0.0
Expand Down
3 changes: 2 additions & 1 deletion molecule/zabbix_agent_tests/molecule/agent2/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ provisioner:
zabbix_agent2: true
zabbix_agent2_tlsconnect: psk
zabbix_agent2_tlsaccept: psk
zabbix_agent2_tlspsk_auto: True
zabbix_agent2_tlspskidentity: my_Identity
zabbix_agent2_tlspskfile: /data/certs/zabbix.psk
zabbix_agent2_tlspsk_secret: 97defd6bd126d5ba7fa5f296595f82eac905d5eda270207a580ab7c0cb9e8eab
zabbix_agent2_plugins:
- name: SystemRun
options:
- parameter: LogRemoteCommands
value: 0
value: 0
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def zabbix_agent_conf(host):
if host.system_info.distribution in ["opensuse"]:
passwd = host.file("/etc/zabbix/zabbix-agentd.conf")
else:
passwd = host.file("/etc/zabbix/zabbix_agent2d.conf")
passwd = host.file("/etc/zabbix/zabbix_agent2.conf")

return passwd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def zabbix_agent_conf(host):
if host.system_info.distribution in ["opensuse"]:
passwd = host.file("/etc/zabbix/zabbix-agentd.conf")
else:
passwd = host.file("/etc/zabbix/zabbix_agent2d.conf")
passwd = host.file("/etc/zabbix/zabbix_agent2.conf")

return passwd

Expand Down
87 changes: 28 additions & 59 deletions roles/zabbix_agent/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,76 @@
# defaults file for zabbix_agent

zabbix_agent2: false
# zabbix_agent_version: 6.4
zabbix_agent_version_minor: "*"
zabbix_version_patch: 0
zabbix_agent_package_remove: false
# zabbix_agent_package: zabbix-agent
zabbix_sender_package: zabbix-sender
zabbix_get_package: zabbix-get
zabbix_sender_package: zabbix-sender # Depricate in 3.0
zabbix_agent_sender_package: "{{ zabbix_sender_package }}"
zabbix_get_package: zabbix-get # Depricate in 3.0
zabbox_agent_get_package: "{{ zabbix_get_package }}"
zabbix_agent_package_state: present
zabbix_selinux: false
zabbix_agent_apt_priority:
zabbix_agent_conf_mode: "0644"
zabbix_agent_dont_detect_ip: false

zabbix_agent_tlspskfile: "/etc/zabbix/tls_psk_auto.secret"
zabbix_agent_tlspskidentity_file: "/etc/zabbix/tls_psk_auto.identity"
# Selinux related vars
zabbix_agent_tlspskidentity_file:
"/etc/zabbix/tls_psk_auto.identity"
# Selinux related vars
selinux_allow_zabbix_run_sudo: false

zabbix_repo_deb_gpg_key_url: http://repo.zabbix.com/zabbix-official-repo.key
zabbix_repo_deb_include_deb_src: true

zabbix_agent_install_agent_only: false
zabbix_agent_packages:
- "{{ zabbix_agent_package }}"
- "{{ zabbix_sender_package }}"
- "{{ zabbix_get_package }}"

# Zabbix role related vars
zabbix_apt_force_apt_get: true
zabbix_apt_install_recommends: false

# Override Ansible specific facts
zabbix_agent_distribution_major_version: "{{ ansible_distribution_major_version }}"
zabbix_agent_distribution_release: "{{ ansible_distribution_release }}"
zabbix_repo_yum_gpgcheck: 0
zabbix_repo_yum_schema: https
zabbix_agent_disable_repo:
- epel
zabbix_repo_yum:
- name: zabbix
description: Zabbix Official Repository - $basearch
baseurl: "{{ zabbix_repo_yum_schema }}://repo.zabbix.com/zabbix/{{ zabbix_agent_version }}/rhel/{{ zabbix_agent_distribution_major_version }}/$basearch/"
baseurl: "{{ zabbix_repo_yum_schema }}://repo.zabbix.com/zabbix/{{ zabbix_agent_version }}/rhel/{{ ansible_distribution_major_version }}/$basearch/"
mode: "0644"
gpgcheck: "{{ zabbix_repo_yum_gpgcheck }}"
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
state: present
- name: zabbix-non-supported
description: Zabbix Official Repository non-supported - $basearch
baseurl: "{{ zabbix_repo_yum_schema }}://repo.zabbix.com/non-supported/rhel/{{ zabbix_agent_distribution_major_version }}/$basearch/"
baseurl: "{{ zabbix_repo_yum_schema }}://repo.zabbix.com/non-supported/rhel/{{ ansible_distribution_major_version }}/$basearch/"
mode: "0644"
gpgcheck: "{{ zabbix_repo_yum_gpgcheck }}"
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
state: present
- name: zabbix-agent2-plugins
description: Zabbix Official Repository (Agent2 Plugins) - $basearch
baseurl: "{{ zabbix_repo_yum_schema }}://repo.zabbix.com/zabbix-agent2-plugins/1/rhel/{{ zabbix_agent_distribution_major_version }}/$basearch/"
baseurl: "{{ zabbix_repo_yum_schema }}://repo.zabbix.com/zabbix-agent2-plugins/1/rhel/{{ ansible_distribution_major_version }}/$basearch/"
mode: "0644"
gpgcheck: "{{ zabbix_repo_yum_gpgcheck }}"
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
state: present

zabbix_repo_deb_url: "http://repo.zabbix.com/zabbix/{{ zabbix_agent_version }}/{{ ansible_facts.lsb.id | default(ansible_facts['distribution']) | lower }}{% if ansible_facts['architecture'] == 'aarch64' and ansible_facts.lsb.id | default(ansible_facts['distribution']) in ['Debian', 'Ubuntu'] %}-arm64{% endif %}"
zabbix_repo_deb_component: main
# zabbix_agent_tlsservercertsubject:

# Zabbix API stuff
zabbix_api_server_host: localhost
# zabbix_api_server_port: 80
zabbix_api_login_user: Admin
zabbix_api_use_ssl: false
zabbix_api_login_pass: !unsafe zabbix
zabbix_api_validate_certs: false
ansible_httpapi_pass: "{{ zabbix_api_login_pass }}"
ansible_httpapi_port: "{{ zabbix_api_server_port }}"
ansible_httpapi_validate_certs: "{{ zabbix_api_validate_certs }}"
zabbix_api_timeout: 30

# API Related Variables
zabbix_api_create_hostgroup: false
zabbix_api_create_hosts: false
zabbix_agent_hostgroups_state: present # or absent
zabbix_agent_host_state: present # or absent
zabbix_agent_host_update: true
zabbix_host_status: enabled # or disabled
Expand All @@ -100,54 +92,32 @@ zabbix_agent_interfaces:
port: "{{ (zabbix_agent2 == True) | ternary(zabbix_agent2_listenport, zabbix_agent_listenport) }}"

# Zabbix configuration variables
# zabbix_agent_enableremotecommands: 0
# zabbix_agent_allowkeys:
# zabbix_agent_denykeys:
# zabbix_agent_logremotecommands: 0
# zabbix_agent_jmx_listenport:
zabbix_agent_listeninterface:
# zabbix_agent_startagents: 3
# zabbix_agent_maxlinespersecond: 100
# zabbix_agent_allowroot: 0
zabbix_agent_zabbix_alias: # Deprecate after 3.0
zabbix_agent_alias: "{{ zabbix_agent_zabbix_alias }}"
# zabbix_agent_timeout: 3
# zabbix_agent_userparameters: []
# zabbix_agent_userparameters_templates_src: "userparameters"
# zabbix_agent_userparameters_scripts_src: "scripts"
# zabbix_agent_custom_scripts: false
# zabbix_agent_loadmodulepath: ${libdir}/modules
# zabbix_agent_loadmodule:
# zabbix_agent_become_on_localhost: true
# zabbix_agent_description:
# zabbix_agent_inventory_zabbix: {}
# zabbix_agent_heartbeatfrequency: 60
# zabbix_agent_macros: []
# zabbix_agent_tags: []
# zabbix_agent_chassis: false

# statusportzabbix_agent_zabbix_alias: # Deprecate after 3.0
zabbix_agent_alias: "{{ statusportzabbix_agent_zabbix_alias is defined | ternary(statusportzabbix_agent_zabbix_alias, zabbix_agent_alias) | default(omit) }}"
zabbix_agent_userparameters_templates_src: "userparameters"
zabbix_agent_userparameters_scripts_src: "scripts"
zabbix_agent_chassis: false

zabbix_agent_tls_config:
unencrypted: "1"
psk: "2"
cert: "4"
cert:
"4"

# IPMI settings
# IPMI settings
zabbix_agent_ipmi_authtype: -1
zabbix_agent_ipmi_password:
zabbix_agent_ipmi_privilege: 2
zabbix_agent_ipmi_username:

# Zabbix Agent2
# zabbix_agent2_statusport: 9999
# zabbix_agent2_hostinterface:
# zabbix_agent2_hostinterfaceitem:
# zabbix_agent2_enablepersistentbuffer: 0
# zabbix_agent2_persistentbufferperiod: 1h
# zabbix_agent2_persistentbufferfile:
# zabbix_agent2_zabbix_alias:
# zabbix_agent2_timeout: 3
# zabbix_agent2_controlsocket: /tmp/agent.sock
# zabbix_agent2_plugins: []
####### Agent 1 Stuff Only

zabbix_agent_loadmodulepath: ${libdir}/modules
zabbix_agent_logremotecommands: 0
zabbix_agent_maxlinespersecond: 100
zabbix_agent_startagents: 3

# Windows/macOS Related
zabbix_version_long: 5.2.4
Expand All @@ -158,7 +128,6 @@ zabbix_win_install_dir: 'C:\Zabbix'
zabbix_win_install_dir_conf: '{{ zabbix_win_install_dir }}\\conf'
zabbix_win_install_dir_bin: '{{ zabbix_win_install_dir }}\\bin'
zabbix_agent_win_include: "{{ zabbix_win_install_dir }}\\zabbix_agent.d\\"
zabbix_agent_win_svc_recovery: true
zabbix_win_firewall_management: true

# macOS Related
Expand Down
45 changes: 22 additions & 23 deletions roles/zabbix_agent/tasks/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
(ansible_distribution == "Debian" and ansible_distribution_major_version < "12")

- name: "Debian | Download gpg key"
when: not ansible_check_mode # Because get_url always has changed status in check_mode.
when: not ansible_check_mode # Because get_url always has changed status in check_mode.
ansible.builtin.get_url:
url: "{{ zabbix_repo_deb_gpg_key_url }}"
dest: "{{ zabbix_gpg_key }}"
Expand Down Expand Up @@ -69,29 +69,28 @@
tags:
- install

- name: "Debian | Create /etc/apt/preferences.d/"
ansible.builtin.file:
path: /etc/apt/preferences.d/
state: directory
mode: "0755"
- name: Configure APT Prefrence
when:
- zabbix_agent_apt_priority is defined
- zabbix_agent_apt_priority | int
become: true
tags:
- install
ansible.builtin.block:
- name: "Debian | Create /etc/apt/preferences.d/"
ansible.builtin.file:
path: /etc/apt/preferences.d/
state: directory
mode: "0755"
become: true

- name: "Debian | Configuring the weight for APT"
ansible.builtin.copy:
dest: "/etc/apt/preferences.d/zabbix-agent-{{ zabbix_underscore_version }}"
content: |
Package: {{ zabbix_agent_package }}
Pin: origin repo.zabbix.com
Pin-Priority: {{ zabbix_agent_apt_priority | int }}
owner: root
mode: "0644"
when:
- zabbix_agent_apt_priority | int
become: true
- name: "Debian | Configuring the weight for APT"
ansible.builtin.copy:
dest: "/etc/apt/preferences.d/zabbix-agent-{{ zabbix_underscore_version }}"
content: |
Package: {{ zabbix_agent_package }}
Pin: origin repo.zabbix.com
Pin-Priority: {{ zabbix_agent_apt_priority | int }}
owner: root
mode: "0644"
become: true
tags:
- install

Expand All @@ -115,8 +114,8 @@
- name: "Debian | Installing zabbix-{sender,get}"
ansible.builtin.apt:
pkg:
- "{{ zabbix_sender_package }}"
- "{{ zabbix_get_package }}"
- "{{ zabbix_agent_sender_package }}"
- "{{ zabbox_agent_get_package }}"
state: "{{ zabbix_agent_package_state }}"
update_cache: true
cache_valid_time: 0
Expand Down
42 changes: 3 additions & 39 deletions roles/zabbix_agent/tasks/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
ansible.builtin.set_fact:
zabbix_agent_ip: "{{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr('public') | first }}"
# zabbix_agent_server: "{{ zabbix_agent_server_public_ip | default(zabbix_agent_server) }}"
# zabbix_agent_serveractive: "{{ zabbix_agent_serveractive_public_ip | default(zabbix_agent_serveractive) }}"
# zabbix_agent2_server: "{{ zabbix_agent_server_public_ip | default(zabbix_agent2_server) }}"
# zabbix_agent2_serveractive: "{{ zabbix_agent_serveractive_public_ip | default(zabbix_agent2_serveractive) }}"
when:
Expand Down Expand Up @@ -121,7 +120,7 @@
- name: "Configure zabbix-agent"
ansible.builtin.template:
src: agent.conf.j2
dest: "/etc/zabbix/zabbix_agentd{{ '2' if zabbix_agent2 | bool }}.conf"
dest: "/etc/zabbix/zabbix_agent{{ (zabbix_agent2 | bool) | ternary('2', 'd') }}.conf"
owner: root
group: root
mode: "{{ zabbix_agent_conf_mode }}"
Expand All @@ -141,23 +140,7 @@
become: true
when:
- zabbix_agent_tlspskfile is defined
- zabbix_agent_tlspskfile # https://github.com/ansible-collections/community.zabbix/issues/680
- not (zabbix_agent2 | bool)
tags:
- config

- name: "Create directory for PSK file if not exist (zabbix-agent2)"
ansible.builtin.file:
path: "{{ zabbix_agent2_tlspskfile | dirname }}"
mode: 0755
state: directory
become: true
when:
- zabbix_agent2_tlspskfile is defined
- zabbix_agent2_tlspskfile # https://github.com/ansible-collections/community.zabbix/issues/680
- zabbix_agent2 | bool
tags:
- config
- zabbix_agent_tlspskfile

- name: "Place TLS PSK File"
ansible.builtin.copy:
Expand All @@ -169,27 +152,8 @@
become: true
when:
- zabbix_agent_tlspskfile is defined
- zabbix_agent_tlspskfile # https://github.com/ansible-collections/community.zabbix/issues/680
- zabbix_agent_tlspskfile
- zabbix_agent_tlspsk_secret is defined
- not (zabbix_agent2 | bool)
notify:
- restart zabbix-agent
tags:
- config

- name: "Place TLS PSK File (zabbix-agent2)"
ansible.builtin.copy:
dest: "{{ zabbix_agent2_tlspskfile }}"
content: "{{ zabbix_agent2_tlspsk_secret }}"
owner: zabbix
group: zabbix
mode: 0400
become: true
when:
- zabbix_agent2_tlspskfile is defined
- zabbix_agent2_tlspskfile # https://github.com/ansible-collections/community.zabbix/issues/680
- zabbix_agent2_tlspsk_secret is defined
- zabbix_agent2 | bool
notify:
- restart zabbix-agent
tags:
Expand Down
2 changes: 1 addition & 1 deletion roles/zabbix_agent/tasks/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
zabbix_win_config_name: "zabbix_agentd.conf"
zabbix2_win_svc_name: Zabbix Agent 2
zabbix2_win_exe_path: '{{ zabbix_win_install_dir }}\bin\zabbix_agent2.exe'
zabbix2_win_config_name: "zabbix_agent2d.conf"
zabbix2_win_config_name: "zabbix_agentd2.conf"
tags:
- always

Expand Down
7 changes: 3 additions & 4 deletions roles/zabbix_agent/tasks/api.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name: "API | Create host groups"
community.zabbix.zabbix_group:
host_group: "{{ zabbix_host_groups }}"
state: "{{ zabbix_agent_hostgroups_state }}"
host_groups: "{{ zabbix_host_groups }}"
state: present
when:
- zabbix_api_create_hostgroup | bool
register: zabbix_api_hostgroup_created
Expand Down Expand Up @@ -35,7 +35,7 @@
ipmi_password: "{{ zabbix_agent_ipmi_password| default(omit) }}"
ipmi_privilege: "{{ zabbix_agent_ipmi_privilege | default(omit) }}"
ipmi_username: "{{ zabbix_agent_ipmi_username | default(omit) }}"
tags: "{{ zabbix_agent_tags }}"
tags: "{{ zabbix_agent_tags | default(omit) }}"
register: zabbix_api_host_created
until: zabbix_api_host_created is succeeded
delegate_to: "{{ zabbix_api_server_host }}"
Expand All @@ -51,7 +51,6 @@
macro_type: "{{ item.macro_type|default('text') }}"
with_items: "{{ zabbix_agent_macros | default([]) }}"
when:
- zabbix_agent_macros is defined
- item.macro_key is defined
register: zabbix_api_hostmarcro_created
until: zabbix_api_hostmarcro_created is succeeded
Expand Down
Loading

0 comments on commit 645c0ac

Please sign in to comment.