| 1 |
--- |
| 2 |
- name: Configure PSK |
| 3 |
when: "( 'psk' in zabbix_agent_tlsaccept ) or (zabbix_agent_tlsconnect == 'psk')" |
| 4 |
tags: |
| 5 |
- config |
| 6 |
block: |
| 7 |
- name: AutoPSK | Check for existing TLS PSK file |
| 8 |
ansible.builtin.stat: |
| 9 |
path: "{{ zabbix_agent_tlspskfile }}" |
| 10 |
register: zabbix_agent_tlspskcheck |
| 11 |
become: true |
| 12 |
|
| 13 |
- name: Gather PSK Secret Info |
| 14 |
ansible.builtin.include_tasks: psk_secret.yml |
| 15 |
|
| 16 |
- name: AutoPSK | Template PSK Secret |
| 17 |
when: |
| 18 |
- zabbix_agent_tlspskfile is defined |
| 19 |
- zabbix_agent_tlspsk_secret is defined |
| 20 |
block: |
| 21 |
- name: Create Directory for PSK File |
| 22 |
ansible.builtin.file: |
| 23 |
path: "{{ zabbix_agent_tlspskfile | dirname }}" |
| 24 |
mode: 0755 |
| 25 |
state: directory |
| 26 |
become: true |
| 27 |
|
| 28 |
- name: AutoPSK | Template PSK Secret |
| 29 |
ansible.builtin.copy: |
| 30 |
dest: "{{ zabbix_agent_tlspskfile }}" |
| 31 |
content: "{{ zabbix_agent_tlspsk_secret }}" |
| 32 |
owner: zabbix |
| 33 |
group: zabbix |
| 34 |
mode: 0400 |
| 35 |
become: true |
| 36 |
notify: |
| 37 |
- restart zabbix-agent |
| 38 |
- restart mac zabbix agent |
| 39 |
|
| 40 |
- name: AutoPSK | Check for existing TLS PSK identity |
| 41 |
ansible.builtin.stat: |
| 42 |
path: "{{ zabbix_agent_tlspskidentity_file }}" |
| 43 |
register: zabbix_agent_tlspskidentity_check |
| 44 |
become: true |
| 45 |
|
| 46 |
- name: Gather PSK Identity Info |
| 47 |
ansible.builtin.include_tasks: psk_identity.yml |
| 48 |
|
| 49 |
- name: AutoPSK | Template PSK Identity |
| 50 |
ansible.builtin.copy: |
| 51 |
dest: "{{ zabbix_agent_tlspskidentity_file }}" |
| 52 |
content: "{{ zabbix_agent_tlspskidentity }}" |
| 53 |
owner: zabbix |
| 54 |
group: zabbix |
| 55 |
mode: 0400 |
| 56 |
become: true |
| 57 |
when: |
| 58 |
- zabbix_agent_tlspskidentity_file is defined |
| 59 |
- zabbix_agent_tlspskidentity is defined |
| 60 |
notify: |
| 61 |
- restart zabbix-agent |
| 62 |
- restart mac zabbix agent |
| 63 |
|
| 64 |
- name: "Validate zabbix_agent_listenip" |
| 65 |
ansible.builtin.assert: |
| 66 |
that: |
| 67 |
- _listenip in ansible_facts['all_ipv4_addresses'] |
| 68 |
fail_msg: "listenip: {{ _listenip }} is not an address available on {{ inventory_hostname }}" |
| 69 |
when: |
| 70 |
- _listenip not in ['127.0.0.1', '0.0.0.0'] |
| 71 |
loop: "{{ zabbix_agent_listenip | split(',') }}" |
| 72 |
loop_control: |
| 73 |
loop_var: _listenip |
| 74 |
tags: |
| 75 |
- config |
| 76 |
|
| 77 |
- name: "Configure SELinux when enabled" |
| 78 |
ansible.builtin.include_tasks: selinux.yml |
| 79 |
when: ansible_facts.selinux.status | default('disabled') == 'enabled' |
| 80 |
|
| 81 |
- name: "Configure zabbix-agent" |
| 82 |
ansible.builtin.template: |
| 83 |
src: agent.conf.j2 |
| 84 |
dest: "/etc/zabbix/zabbix_agent{{ (zabbix_agent2 | bool) | ternary('2', 'd') }}.conf" |
| 85 |
owner: root |
| 86 |
group: root |
| 87 |
mode: "{{ zabbix_agent_conf_mode }}" |
| 88 |
notify: |
| 89 |
- restart zabbix-agent |
| 90 |
become: true |
| 91 |
tags: |
| 92 |
- config |
| 93 |
|
| 94 |
- name: "Create include dirs zabbix-agent" |
| 95 |
ansible.builtin.file: |
| 96 |
path: "{{ include_dir }}" |
| 97 |
owner: root |
| 98 |
group: root |
| 99 |
mode: "{{ zabbix_agent_include_mode }}" |
| 100 |
state: directory |
| 101 |
loop: "{{ zabbix_agent_include_dirs }}" |
| 102 |
loop_control: |
| 103 |
loop_var: 'include_dir' |
| 104 |
become: true |
| 105 |
tags: |
| 106 |
- config |
| 107 |
|
| 108 |
- name: "Remove zabbix-agent installation when zabbix-agent2 is used." |
| 109 |
ansible.builtin.include_tasks: remove.yml |
| 110 |
when: |
| 111 |
- zabbix_agent2 | bool |
| 112 |
- zabbix_agent_package_remove |
| 113 |
|
| 114 |
- name: "Give zabbix-agent access to system.hw.chassis info" |
| 115 |
ansible.builtin.file: |
| 116 |
path: /sys/firmware/dmi/tables/DMI |
| 117 |
owner: root |
| 118 |
group: zabbix |
| 119 |
become: true |
| 120 |
when: |
| 121 |
- zabbix_agent_chassis is defined |
| 122 |
- zabbix_agent_chassis | bool |
| 123 |
- ansible_facts['os_family'] != "FreeBSD" |
| 124 |
tags: |
| 125 |
- config |
| 126 |
|
| 127 |
- name: "Update sysctl settings" |
| 128 |
ansible.posix.sysctl: |
| 129 |
name: "{{ item }}" |
| 130 |
value: '1' |
| 131 |
sysctl_set: true |
| 132 |
with_items: |
| 133 |
- security.bsd.see_other_gids |
| 134 |
- security.bsd.see_other_uids |
| 135 |
when: |
| 136 |
- ansible_facts['os_family'] == "FreeBSD" |
| 137 |
tags: |
| 138 |
- config |
| 139 |
notify: restart sysctl |
| 140 |
|
| 141 |
- meta: flush_handlers |
| 142 |
|
| 143 |
- name: "Ensure zabbix-agent is enabled and running" |
| 144 |
ansible.builtin.service: |
| 145 |
name: "{{ zabbix_agent_service }}" |
| 146 |
state: started |
| 147 |
enabled: true |
| 148 |
become: true |
| 149 |
tags: |
| 150 |
- service |