| 1 |
--- |
| 2 |
# tasks file for zabbix_agent |
| 3 |
- name: "Include OS-specific variables" |
| 4 |
ansible.builtin.include_vars: "{{ ansible_facts.os_family }}.yml" |
| 5 |
tags: |
| 6 |
- always |
| 7 |
|
| 8 |
- name: Determine Latest Supported Zabbix Version |
| 9 |
ansible.builtin.set_fact: |
| 10 |
zabbix_agent_version: "{{ zabbix_valid_agent_versions[ansible_facts.distribution_major_version][0] | default(7.2) }}" |
| 11 |
when: zabbix_agent_version is not defined or zabbix_agent_version is none |
| 12 |
tags: |
| 13 |
- always |
| 14 |
|
| 15 |
- name: Check that version is supported |
| 16 |
when: zabbix_agent_version_check | bool |
| 17 |
ansible.builtin.assert: |
| 18 |
that: |
| 19 |
- zabbix_agent_version | float in zabbix_valid_agent_versions[ansible_facts.distribution_major_version] |
| 20 |
fail_msg: Zabbix version {{ zabbix_agent_version }} is not supported on {{ ansible_facts.distribution }} {{ ansible_facts.distribution_major_version }} |
| 21 |
tags: |
| 22 |
- always |
| 23 |
|
| 24 |
- name: Load Appropriate Defaults |
| 25 |
ansible.builtin.include_vars: "{{ zabbix_agent2 | ternary('agent2', 'agent') }}_vars.yml" |
| 26 |
|
| 27 |
- when: zabbix_agent_tlspsk_auto | bool |
| 28 |
tags: |
| 29 |
- config |
| 30 |
block: |
| 31 |
- name: AutoPSK | Default tlsconnect to enforce PSK |
| 32 |
ansible.builtin.set_fact: |
| 33 |
zabbix_agent_tlsconnect: psk |
| 34 |
|
| 35 |
- name: AutoPSK | Default tlsaccept to enforce PSK when zabbix_agent_tlsaccept is not defined |
| 36 |
ansible.builtin.set_fact: |
| 37 |
zabbix_agent_tlsaccept: psk |
| 38 |
when: not zabbix_agent_tlsaccept is defined |
| 39 |
|
| 40 |
- name: AutoPSK | Default tlsaccept to enforce PSK when zabbix_agent_tlsaccept is defined |
| 41 |
ansible.builtin.set_fact: |
| 42 |
zabbix_agent_tlsaccept: "{{ 'psk,' + zabbix_agent_tlsaccept }}" |
| 43 |
when: |
| 44 |
- zabbix_agent_tlsaccept is defined |
| 45 |
- not 'psk' in zabbix_agent_tlsaccept |
| 46 |
|
| 47 |
- name: Install Repository |
| 48 |
ansible.builtin.include_role: |
| 49 |
name: community.zabbix.zabbix_repo |
| 50 |
vars: |
| 51 |
zabbix_repo_version: "{{ zabbix_agent_version }}" |
| 52 |
zabbix_repo_package: "{{ zabbix_agent_package }}" |
| 53 |
when: |
| 54 |
- zabbix_manage_repo | default(true) |
| 55 |
- not (zabbix_agent_docker | bool) |
| 56 |
- ansible_facts['os_family'] not in ['Alpine', 'Darwin', 'FreeBSD', 'Windows'] |
| 57 |
|
| 58 |
- name: "Install the agent" |
| 59 |
when: not (zabbix_agent_docker | bool) |
| 60 |
ansible.builtin.include_tasks: "{{ _install_tasks_file }}" |
| 61 |
with_first_found: |
| 62 |
- "install-{{ ansible_facts['os_family'] }}.yml" |
| 63 |
- "install.yml" |
| 64 |
loop_control: |
| 65 |
loop_var: _install_tasks_file |
| 66 |
|
| 67 |
- name: "Configure Agent" |
| 68 |
when: ansible_facts['os_family'] not in ['Darwin'] |
| 69 |
ansible.builtin.include_tasks: "{{ _configure_tasks_file }}" |
| 70 |
with_first_found: |
| 71 |
- "configure-{{ ansible_facts['os_family'] }}.yml" |
| 72 |
- "configure{% if zabbix_agent_docker %}-Docker{% endif %}.yml" |
| 73 |
loop_control: |
| 74 |
loop_var: _configure_tasks_file |
| 75 |
|
| 76 |
- name: "Run the API calls to Zabbix Server" |
| 77 |
vars: |
| 78 |
ansible_network_os: community.zabbix.zabbix |
| 79 |
ansible_connection: httpapi |
| 80 |
ansible_httpapi_use_ssl: "{{ zabbix_api_use_ssl }}" |
| 81 |
# --- Basic Auth (Begin) --- |
| 82 |
http_login_user: "{{ zabbix_api_http_user | default(-42) }}" |
| 83 |
http_login_password: "{{ zabbix_api_http_password | default(-42) }}" |
| 84 |
# --- Basic Auth (End) --- |
| 85 |
ansible_user: "{{ zabbix_api_login_user }}" |
| 86 |
ansible_httpapi_pass: "{{ zabbix_api_login_pass }}" |
| 87 |
ansible_httpapi_port: "{{ zabbix_api_server_port }}" |
| 88 |
ansible_httpapi_validate_certs: "{{ zabbix_api_validate_certs }}" |
| 89 |
ansible.builtin.include_tasks: api.yml |
| 90 |
when: |
| 91 |
- (zabbix_api_create_hostgroup | bool) or (zabbix_api_create_hosts | bool) |
| 92 |
tags: |
| 93 |
- api |
| 94 |
|
| 95 |
- name: "Including userparameters" |
| 96 |
ansible.builtin.include_tasks: "userparameter.yml" |
| 97 |
when: zabbix_agent_userparameters | default ([]) | length > 0 |
| 98 |
tags: |
| 99 |
- config |