feat: try with new ansible role structure
This commit is contained in:
parent
da1e3d8e5c
commit
c14dd49576
10 changed files with 0 additions and 0 deletions
16
roles/zabbix_agent/defaults/main.yaml
Normal file
16
roles/zabbix_agent/defaults/main.yaml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
|
||||
# zabbix_version
|
||||
zabbix_major_version: "7.4"
|
||||
zabbix_agent_enable: true
|
||||
|
||||
# zabbix agent defaults
|
||||
zabbix_agent_psk_enable: true
|
||||
zabbix_agent_listen_port: "10050"
|
||||
|
||||
# zabbix server / proxy connectivity
|
||||
zabbix_proxy_address: "zabbix.siempie.internal"
|
||||
zabbix_proxy_port: "10051"
|
||||
|
||||
# zabbix user permissions
|
||||
zabbix_user_sudo: true
|
||||
2
roles/zabbix_agent/files/zabbix/plugins.d/nvidia.conf
Normal file
2
roles/zabbix_agent/files/zabbix/plugins.d/nvidia.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# disable the NVIDIA plugin
|
||||
# Plugins.NVIDIA.System.Path=/usr/libexec/zabbix/zabbix-agent2-plugin-nvidia-gpu
|
||||
8
roles/zabbix_agent/handlers/main.yaml
Normal file
8
roles/zabbix_agent/handlers/main.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
|
||||
# zabbix agent
|
||||
- name: "restart zabbix-agent"
|
||||
ansible.builtin.service:
|
||||
name: "zabbix-agent2"
|
||||
enabled: true
|
||||
state: "restarted"
|
||||
10
roles/zabbix_agent/meta/main.yaml
Normal file
10
roles/zabbix_agent/meta/main.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
|
||||
galaxy_info:
|
||||
author: "siempie"
|
||||
description: "install and configure a Zabbix Agent"
|
||||
license: "MIT"
|
||||
role_name: "zabbix_agent"
|
||||
|
||||
dependencies:
|
||||
- role: "zabbix_prereq"
|
||||
33
roles/zabbix_agent/tasks/config.yaml
Normal file
33
roles/zabbix_agent/tasks/config.yaml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
|
||||
# setup psk
|
||||
- name: "setup psk"
|
||||
ansible.builtin.template:
|
||||
src: "templates/zabbix/zabbix_agent.psk.j2"
|
||||
dest: "/etc/zabbix/zabbix_agent.psk"
|
||||
owner: "zabbix"
|
||||
group: "zabbix"
|
||||
mode: "0640"
|
||||
notify: "restart zabbix-agent"
|
||||
|
||||
# config agent
|
||||
- name: "config agent"
|
||||
ansible.builtin.template:
|
||||
src: "templates/zabbix/zabbix_agent.conf.j2"
|
||||
dest: "/etc/zabbix/zabbix_agent2.conf"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0664"
|
||||
notify: "restart zabbix-agent"
|
||||
|
||||
# configure plugins
|
||||
- name: "configure plugins"
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: "/etc/zabbix/zabbix_agent2.d/plugins.d/"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0644"
|
||||
with_fileglob:
|
||||
- "files/zabbix/plugins.d/*"
|
||||
notify: "restart zabbix-agent"
|
||||
68
roles/zabbix_agent/tasks/install.yaml
Normal file
68
roles/zabbix_agent/tasks/install.yaml
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
---
|
||||
|
||||
# install zabbix-agent2
|
||||
- name: "install zabbix-agent2"
|
||||
when: "zabbix_major_version not in zabbix_current_version.stdout"
|
||||
block:
|
||||
|
||||
# install repository - debian
|
||||
- name: "install repository"
|
||||
when: 'ansible_os_family == "Debian"'
|
||||
block:
|
||||
|
||||
# remove old agent
|
||||
- name: "remove old agent"
|
||||
ansible.builtin.apt:
|
||||
name: "{{ item }}"
|
||||
state: "absent"
|
||||
loop:
|
||||
- "zabbix-agent2"
|
||||
- "zabbix-agent2-plugin-*"
|
||||
|
||||
# install agent
|
||||
- name: "install agent"
|
||||
ansible.builtin.apt:
|
||||
name: "{{ item }}"
|
||||
state: "present"
|
||||
update_cache: true
|
||||
when: 'ansible_os_family == "Debian"'
|
||||
loop:
|
||||
- "zabbix-agent2"
|
||||
- "zabbix-agent2-plugin-*"
|
||||
|
||||
|
||||
# install repository - suse
|
||||
- name: "install repository"
|
||||
when: 'ansible_os_family == "Suse"'
|
||||
block:
|
||||
|
||||
# remove old agent
|
||||
- name: "remove old agent"
|
||||
ansible.builtin.zypper:
|
||||
name: "{{ item }}"
|
||||
state: "absent"
|
||||
loop:
|
||||
- "zabbix-agent2"
|
||||
- "zabbix-agent2-plugin-*"
|
||||
|
||||
# install agent
|
||||
- name: "install agent"
|
||||
ansible.builtin.zypper:
|
||||
name: "{{ item }}"
|
||||
disable_recommends: false
|
||||
state: "present"
|
||||
when: 'ansible_os_family == "Suse"'
|
||||
loop:
|
||||
- "zabbix-agent2"
|
||||
- "zabbix-agent2-plugin-*"
|
||||
|
||||
|
||||
# install sudoers file
|
||||
- name: "install sudoers file"
|
||||
ansible.builtin.template:
|
||||
src: "templates/sudoers.d/zabbix.j2"
|
||||
dest: "/etc/sudoers.d/zabbix"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0440"
|
||||
when: "zabbix_user_sudo"
|
||||
23
roles/zabbix_agent/tasks/main.yaml
Normal file
23
roles/zabbix_agent/tasks/main.yaml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
|
||||
# load variables and collect version information
|
||||
- name: "include vars and collect versions"
|
||||
block:
|
||||
|
||||
# collect zabbix-agent2 version information
|
||||
- name: "collect version information"
|
||||
ansible.builtin.shell:
|
||||
cmd: "zabbix_agent2 --version | head -n 1"
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
ignore_errors: true
|
||||
register: "zabbix_current_version"
|
||||
|
||||
|
||||
# zabbix-agent install
|
||||
- name: "zabbix-agent install"
|
||||
ansible.builtin.include_tasks: "install.yaml"
|
||||
|
||||
# zabbix-agent config
|
||||
- name: "zabbix-agent config"
|
||||
ansible.builtin.include_tasks: "config.yaml"
|
||||
1
roles/zabbix_agent/templates/sudoers.d/zabbix.j2
Normal file
1
roles/zabbix_agent/templates/sudoers.d/zabbix.j2
Normal file
|
|
@ -0,0 +1 @@
|
|||
zabbix ALL=(ALL) NOPASSWD: ALL
|
||||
25
roles/zabbix_agent/templates/zabbix/zabbix_agent.conf.j2
Normal file
25
roles/zabbix_agent/templates/zabbix/zabbix_agent.conf.j2
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# general
|
||||
Hostname={{ zabbix_agent_hostname | default(inventory_hostname) }}
|
||||
Server={{ zabbix_proxy_address }}
|
||||
ServerActive={{ zabbix_proxy_address }}:{{ zabbix_proxy_port }}
|
||||
ListenPort={{ zabbix_agent_listen_port }}
|
||||
HostMetadataItem=system.uname
|
||||
HostInterface={{ zabbix_agent_hostinterface | default(inventory_hostname) }}
|
||||
AllowKey=system.run[*]
|
||||
Timeout=30
|
||||
LogType=system
|
||||
DebugLevel=1
|
||||
|
||||
{% if zabbix_agent_psk_enable %}
|
||||
# psk
|
||||
TLSConnect=psk
|
||||
TLSAccept=psk
|
||||
TLSPSKIdentity={{ zabbix_agent_psk_id }}
|
||||
TLSPSKFile=/etc/zabbix/zabbix_agent.psk
|
||||
{% endif %}
|
||||
|
||||
# advanced parameters
|
||||
Include=/etc/zabbix/zabbix_agent2.d/*.conf
|
||||
Include=/etc/zabbix/zabbix_agent2.d/plugins.d/*.conf
|
||||
PluginSocket=/run/zabbix/agent.plugin.sock
|
||||
ControlSocket=/run/zabbix/agent.sock
|
||||
1
roles/zabbix_agent/templates/zabbix/zabbix_agent.psk.j2
Normal file
1
roles/zabbix_agent/templates/zabbix/zabbix_agent.psk.j2
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{ zabbix_agent_psk }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue