Added agent2 installation
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| --- | --- | ||||||
| - name: Install and Configure Zabbix Proxy | - name: Install and Configure Zabbix Proxy and Agent | ||||||
|   hosts: zabbix-proxy # Assuming you have a group for zabbix proxy in your inventory |   hosts: zabbix_proxy # Assuming you have a group for zabbix proxy in your inventory | ||||||
|   become: yes |   become: yes | ||||||
|   vars_files: |   vars_files: | ||||||
|     - ../secrets.yml |     - ../secrets.yml | ||||||
| @@ -14,9 +14,11 @@ | |||||||
|       ansible.builtin.apt: |       ansible.builtin.apt: | ||||||
|         deb: /tmp/zabbix-release.deb |         deb: /tmp/zabbix-release.deb | ||||||
|  |  | ||||||
|     - name: Install Zabbix proxy |     - name: Install Zabbix proxy and agent | ||||||
|       ansible.builtin.apt: |       ansible.builtin.apt: | ||||||
|         name: zabbix-proxy-sqlite3 |         name: | ||||||
|  |           - zabbix-proxy-sqlite3 | ||||||
|  |           - zabbix-agent2 | ||||||
|         state: present |         state: present | ||||||
|         update_cache: yes |         update_cache: yes | ||||||
|  |  | ||||||
| @@ -40,6 +42,8 @@ | |||||||
|       ansible.builtin.copy: |       ansible.builtin.copy: | ||||||
|         dest: /etc/zabbix/zabbix_proxy.d/connection.conf |         dest: /etc/zabbix/zabbix_proxy.d/connection.conf | ||||||
|         content: | |         content: | | ||||||
|  |           ## Managed by Ansible - do not edit manually ## | ||||||
|  |           ## Changes will be overwritten ## | ||||||
|           Server={{ zabbix_server_address }}:10051 |           Server={{ zabbix_server_address }}:10051 | ||||||
|           Hostname={{ ansible_facts.hostname }} |           Hostname={{ ansible_facts.hostname }} | ||||||
|           TLSPSKFile=/etc/zabbix/{{ ansible_facts.hostname }}.psk |           TLSPSKFile=/etc/zabbix/{{ ansible_facts.hostname }}.psk | ||||||
| @@ -55,18 +59,39 @@ | |||||||
|         mode: '0600' |         mode: '0600' | ||||||
|       notify: restart zabbix-proxy |       notify: restart zabbix-proxy | ||||||
|  |  | ||||||
|  |     - name: Create Zabbix agent custom configuration file | ||||||
|  |       ansible.builtin.copy: | ||||||
|  |         dest: /etc/zabbix/zabbix_agent2.d/custom.conf | ||||||
|  |         content: | | ||||||
|  |           Hostname={{ ansible_facts.hostname }} | ||||||
|  |           Server={{ hostvars['zabbix-proxy']['ansible_host'] }},{{ hostvars['raspberry-pi']['ansible_host'] }} | ||||||
|  |           ServerActive={{ hostvars['zabbix-proxy']['ansible_host'] }};{{ hostvars['raspberry-pi']['ansible_host'] }} | ||||||
|  |       notify: restart zabbix-agent2 | ||||||
|  |  | ||||||
|  |     - name: Create Zabbix agent user parameters file | ||||||
|  |       ansible.builtin.copy: | ||||||
|  |         dest: /etc/zabbix/zabbix_agent2.d/userparams.conf | ||||||
|  |         content: | | ||||||
|  |           AllowKey=system.run[*] | ||||||
|  |       notify: restart zabbix-agent2 | ||||||
|  |  | ||||||
|   handlers: |   handlers: | ||||||
|     - name: restart zabbix-proxy |     - name: restart zabbix-proxy | ||||||
|       ansible.builtin.service: |       ansible.builtin.service: | ||||||
|         name: zabbix-proxy |         name: zabbix-proxy | ||||||
|         state: restarted |         state: restarted | ||||||
|         enabled: yes |         enabled: yes | ||||||
|  |     - name: restart zabbix-agent2 | ||||||
|  |       ansible.builtin.service: | ||||||
|  |         name: zabbix-agent2 | ||||||
|  |         state: restarted | ||||||
|  |         enabled: yes | ||||||
|  |  | ||||||
| - name: Verify Zabbix Proxy Service | - name: Verify Zabbix Services | ||||||
|   hosts: zabbix-proxy |   hosts: zabbix_proxy | ||||||
|   become: yes |   become: yes | ||||||
|   tasks: |   tasks: | ||||||
|     - name: Check if Zabbix proxy service is running |     - name: Check if Zabbix services are running | ||||||
|       ansible.builtin.service_facts: |       ansible.builtin.service_facts: | ||||||
|  |  | ||||||
|     - name: Assert that Zabbix proxy is running |     - name: Assert that Zabbix proxy is running | ||||||
| @@ -75,3 +100,10 @@ | |||||||
|           - "ansible_facts.services['zabbix-proxy.service'].state == 'running'" |           - "ansible_facts.services['zabbix-proxy.service'].state == 'running'" | ||||||
|         fail_msg: "Zabbix proxy is not running" |         fail_msg: "Zabbix proxy is not running" | ||||||
|         success_msg: "Zabbix proxy is running" |         success_msg: "Zabbix proxy is running" | ||||||
|  |  | ||||||
|  |     - name: Assert that Zabbix agent is running | ||||||
|  |       ansible.builtin.assert: | ||||||
|  |         that: | ||||||
|  |           - "ansible_facts.services['zabbix-agent2.service'].state == 'running'" | ||||||
|  |         fail_msg: "Zabbix agent 2 is not running" | ||||||
|  |         success_msg: "Zabbix agent 2 is running" | ||||||
		Reference in New Issue
	
	Block a user