Changed file structure. Added zabbix proxy playbook
This commit is contained in:
		| @@ -1,14 +1,14 @@ | |||||||
| - name: Upgrade packages | - name: Upgrade packages | ||||||
|   hosts: ubuntu |   hosts: ubuntu | ||||||
|   become: true |   become: true | ||||||
| 
 | 
 | ||||||
|   tasks: |   tasks: | ||||||
|    - name: Update cache  |    - name: Update cache  | ||||||
|      ansible.builtin.apt: |      ansible.builtin.apt: | ||||||
|       update_cache: true |       update_cache: true | ||||||
|      register: cache_updated |      register: cache_updated | ||||||
| 
 | 
 | ||||||
|    - name: Upgrade packages if something is changed |    - name: Upgrade packages if something is changed | ||||||
|      ansible.builtin.apt: |      ansible.builtin.apt: | ||||||
|       upgrade: "yes" |       upgrade: "yes" | ||||||
|      when: cache_updated.changed |      when: cache_updated.changed | ||||||
| @@ -1,16 +1,16 @@ | |||||||
| - name: Upgrade zabbix agent | - name: Upgrade zabbix agent | ||||||
|   hosts: zagents |   hosts: zagents | ||||||
|   become: true |   become: true | ||||||
| 
 | 
 | ||||||
|   tasks: |   tasks: | ||||||
|    - name: Ensure that Zabbix agent is at the latest version  |    - name: Ensure that Zabbix agent is at the latest version  | ||||||
|      ansible.builtin.apt: |      ansible.builtin.apt: | ||||||
|       name: zabbix-agent2 |       name: zabbix-agent2 | ||||||
|       state: latest |       state: latest | ||||||
|      register: zabbix_agent2_status |      register: zabbix_agent2_status | ||||||
| 
 | 
 | ||||||
|    - name: Upgrade Zabbix agent if not latest |    - name: Upgrade Zabbix agent if not latest | ||||||
|      ansible.builtin.apt: |      ansible.builtin.apt: | ||||||
|       name: zabbix-agent2 |       name: zabbix-agent2 | ||||||
|       upgrade: yes |       upgrade: yes | ||||||
|      when: zabbix_agent2_status.changed |      when: zabbix_agent2_status.changed | ||||||
							
								
								
									
										68
									
								
								playbooks/zabbix_proxy_install.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								playbooks/zabbix_proxy_install.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | |||||||
|  | --- | ||||||
|  | - name: Install and Configure Zabbix Proxy | ||||||
|  |   hosts: zabbix-proxy # Assuming you have a group for zabbix proxy in your inventory | ||||||
|  |   become: yes | ||||||
|  |   vars_files: | ||||||
|  |     - ../secrets.yml | ||||||
|  |   tasks: | ||||||
|  |     - name: Add Zabbix repository | ||||||
|  |       ansible.builtin.apt_repository: | ||||||
|  |         repo: "deb https://repo.zabbix.com/zabbix/7.4/ubuntu {{ ansible_distribution_release }} main" | ||||||
|  |         state: present | ||||||
|  |         filename: zabbix | ||||||
|  |  | ||||||
|  |     - name: Install Zabbix proxy | ||||||
|  |       ansible.builtin.apt: | ||||||
|  |         name: zabbix-proxy-sqlite3 | ||||||
|  |         state: present | ||||||
|  |         update_cache: yes | ||||||
|  |  | ||||||
|  |     - name: Create Zabbix proxy configuration file | ||||||
|  |       ansible.builtin.copy: | ||||||
|  |         dest: /etc/zabbix/zabbix_proxy.conf.d/mbuz.conf | ||||||
|  |         content: | | ||||||
|  |           Server={{ zabbix_server_address }}:10051 | ||||||
|  |           Hostname={{ zabbix_proxy_hostname }} | ||||||
|  |           DBName=/tmp/zabbix_proxy | ||||||
|  |           StartPollers=2 | ||||||
|  |           StartPreprocessors=1 | ||||||
|  |           StartTrappers=1 | ||||||
|  |           StartDiscoverers=1 | ||||||
|  |           StartDBSyncers=1 | ||||||
|  |           StartAgentPollers=2 | ||||||
|  |           EnableRemoteCommands=1 | ||||||
|  |           TLSConnect=psk | ||||||
|  |           TLSAccept=psk | ||||||
|  |           TLSPSKFile=/etc/zabbix/lxc-proxy.psk | ||||||
|  |           TLSPSKIdentity={{ zabbix_psk_identity }} | ||||||
|  |       notify: restart zabbix-proxy | ||||||
|  |  | ||||||
|  |     - name: Create Zabbix proxy PSK file | ||||||
|  |       ansible.builtin.copy: | ||||||
|  |         dest: /etc/zabbix/proxy.psk | ||||||
|  |         content: "{{ zabbix_proxy_psk }}" | ||||||
|  |         owner: zabbix | ||||||
|  |         group: zabbix | ||||||
|  |         mode: '0600' | ||||||
|  |       notify: restart zabbix-proxy | ||||||
|  |  | ||||||
|  |   handlers: | ||||||
|  |     - name: restart zabbix-proxy | ||||||
|  |       ansible.builtin.service: | ||||||
|  |         name: zabbix-proxy | ||||||
|  |         state: restarted | ||||||
|  |         enabled: yes | ||||||
|  |  | ||||||
|  | - name: Verify Zabbix Proxy Service | ||||||
|  |   hosts: zabbix_proxy | ||||||
|  |   become: yes | ||||||
|  |   tasks: | ||||||
|  |     - name: Check if Zabbix proxy service is running | ||||||
|  |       ansible.builtin.service_facts: | ||||||
|  |  | ||||||
|  |     - name: Assert that Zabbix proxy is running | ||||||
|  |       ansible.builtin.assert: | ||||||
|  |         that: | ||||||
|  |           - "ansible_facts.services['zabbix-proxy.service'].state == 'running'" | ||||||
|  |         fail_msg: "Zabbix proxy is not running" | ||||||
|  |         success_msg: "Zabbix proxy is running" | ||||||
		Reference in New Issue
	
	Block a user