mirror of
				https://gitlab.sectorq.eu/jaydee/ansible.git
				synced 2025-10-31 02:11:10 +01:00 
			
		
		
		
	klal
This commit is contained in:
		| @@ -1,175 +1,172 @@ | ||||
| - block: | ||||
|   - name: Get config for not nas | ||||
|     ansible.builtin.set_fact: | ||||
|       zabbix_agent_cfg: "/etc/zabbix/zabbix_agent2.conf" | ||||
|     when: inventory_hostname != 'nas.home.lan' | ||||
|      | ||||
|   - name: Get config for nas | ||||
|     ansible.builtin.set_fact: | ||||
|       zabbix_agent_cfg: "/opt/ZabbixAgent/etc/zabbix_agentd.conf" | ||||
|     when: inventory_hostname  == 'nas.home.lan' | ||||
| - name: Install zabbix agent | ||||
|   become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}" | ||||
|   block: | ||||
|     - name: Get config for not nas | ||||
|       ansible.builtin.set_fact: | ||||
|         zabbix_agent_cfg: "/etc/zabbix/zabbix_agent2.conf" | ||||
|       when: inventory_hostname != 'nas.home.lan' | ||||
|  | ||||
|   - name: Print all available facts | ||||
|     ansible.builtin.debug: | ||||
|       msg: "{{ false if inventory_hostname == 'nas.home.lan' else true }}" | ||||
|     - name: Get config for nas | ||||
|       ansible.builtin.set_fact: | ||||
|         zabbix_agent_cfg: "/opt/ZabbixAgent/etc/zabbix_agentd.conf" | ||||
|       when: inventory_hostname  == 'nas.home.lan' | ||||
|  | ||||
|   - name: Print all available facts | ||||
|     ansible.builtin.debug: | ||||
|       var: ansible_facts.architecture | ||||
|   - name: Print all available facts | ||||
|     ansible.builtin.debug: | ||||
|       var: ansible_distribution | ||||
|   - name: Print all available facts | ||||
|     ansible.builtin.debug: | ||||
|       var: ansible_distribution_major_version | ||||
|   # - name: Upload zabbix package | ||||
|   #   ansible.builtin.copy: | ||||
|   #     src: packages/zabbix-release_6.4-1+ubuntu22.04_all.deb | ||||
|   #     dest: /tmp/ | ||||
|   - name: Install a .deb package from the internet111 | ||||
|     ansible.builtin.apt: | ||||
|       deb: https://repo.zabbix.com/zabbix/7.2/release/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.2+ubuntu24.04_all.deb | ||||
|     when: | ||||
|       - ansible_facts.architecture != "armv7l" and  ( ansible_distribution == "Ubuntu1" or ansible_distribution == "Linux Mint" ) | ||||
|     - name: Print all available facts | ||||
|       ansible.builtin.debug: | ||||
|         msg: "{{ false if inventory_hostname == 'nas.home.lan' else true }}" | ||||
|  | ||||
|   - name: Install a .deb package from the internet2 | ||||
|     ansible.builtin.apt: | ||||
|       #deb: https://repo.zabbix.com/zabbix/6.4/raspbian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb | ||||
|       deb: https://repo.zabbix.com/zabbix/7.0/raspbian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian11_all.deb | ||||
|     retries: 5 | ||||
|     delay: 5 | ||||
|     when: | ||||
|       - ansible_facts.architecture == "armv7l" or ansible_facts.architecture == "aarch64" | ||||
|     - name: Print all available facts | ||||
|       ansible.builtin.debug: | ||||
|         var: ansible_facts.architecture | ||||
|     - name: Print all available facts | ||||
|       ansible.builtin.debug: | ||||
|         var: ansible_distribution | ||||
|     - name: Print all available facts | ||||
|       ansible.builtin.debug: | ||||
|         var: ansible_distribution_major_version | ||||
|     # - name: Upload zabbix package | ||||
|     #   ansible.builtin.copy: | ||||
|     #     src: packages/zabbix-release_6.4-1+ubuntu22.04_all.deb | ||||
|     #     dest: /tmp/ | ||||
|     - name: Install a .deb package from the internet111 | ||||
|       ansible.builtin.apt: | ||||
|         deb: https://repo.zabbix.com/zabbix/7.2/release/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.2+ubuntu24.04_all.deb | ||||
|       when: | ||||
|         - ansible_facts.architecture != "armv7l" and  ( ansible_distribution == "Ubuntu1" or ansible_distribution == "Linux Mint" ) | ||||
|  | ||||
|     ignore_errors: true | ||||
|     - name: Install a .deb package from the internet2 | ||||
|       ansible.builtin.apt: | ||||
|         # deb: https://repo.zabbix.com/zabbix/6.4/raspbian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb | ||||
|         deb: https://repo.zabbix.com/zabbix/7.0/raspbian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian11_all.deb | ||||
|       retries: 5 | ||||
|       delay: 5 | ||||
|       when: | ||||
|         - ansible_facts.architecture == "armv7l" or ansible_facts.architecture == "aarch64" | ||||
|       register: command_result | ||||
|       failed_when: "'FAILED' in command_result.stderr" | ||||
|  | ||||
|   - name: Install a .deb package from the internet3 | ||||
|     ansible.builtin.apt: | ||||
|       deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb | ||||
|        | ||||
|     when: | ||||
|       - ansible_facts.architecture != "armv7l"  and ansible_distribution == "Debian"  and ansible_distribution_major_version  == "11" | ||||
|      | ||||
|   - name: Install a .deb package from the internet4 | ||||
|     ansible.builtin.apt: | ||||
|       #deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian12_all.deb | ||||
|       deb: https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian12_all.deb | ||||
|     when: | ||||
|       - ansible_facts.architecture != "armv7l" and  ansible_facts.architecture != "aarch64" and ansible_distribution == "Debian"  and ansible_distribution_major_version  == "12" | ||||
|     ignore_errors: true | ||||
|     - name: Install a .deb package from the internet3 | ||||
|       ansible.builtin.apt: | ||||
|         deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb | ||||
|       when: | ||||
|         - ansible_facts.architecture != "armv7l"  and ansible_distribution == "Debian"  and ansible_distribution_major_version  == "11" | ||||
|  | ||||
|   # - name: Install a .deb package localy | ||||
|   #   ansible.builtin.apt: | ||||
|   #     deb: /tmp/zabbix-release_6.4-1+ubuntu22.04_all.deb | ||||
|   - name: Install zabbix packages | ||||
|     ansible.builtin.apt: | ||||
|       name:  | ||||
|         - zabbix-agent2 | ||||
|         - zabbix-agent2-plugin-mongodb | ||||
|         - zabbix-agent2-plugin-postgresql | ||||
|         # - zabbix-agent2-plugin-mysql | ||||
|       update_cache: yes | ||||
|     ignore_errors: true | ||||
|     when: inventory_hostname != 'nas.home.lan' | ||||
|     - name: Install a .deb package from the internet4 | ||||
|       ansible.builtin.apt: | ||||
|         # deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian12_all.deb | ||||
|         deb: https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian12_all.deb | ||||
|       when: | ||||
|         - ansible_facts.architecture != "armv7l" | ||||
|         - ansible_facts.architecture != "aarch64" | ||||
|         - ansible_distribution == "Debian" | ||||
|         - ansible_distribution_major_version  == "12" | ||||
|       register: command_result | ||||
|       failed_when: "'FAILED' in command_result.stderr" | ||||
|     # - name: Install a .deb package localy | ||||
|     #   ansible.builtin.apt: | ||||
|     #     deb: /tmp/zabbix-release_6.4-1+ubuntu22.04_all.deb | ||||
|     - name: Install zabbix packages | ||||
|       ansible.builtin.apt: | ||||
|         name: | ||||
|           - zabbix-agent2 | ||||
|           - zabbix-agent2-plugin-mongodb | ||||
|           - zabbix-agent2-plugin-postgresql | ||||
|           # - zabbix-agent2-plugin-mysql | ||||
|         update_cache: true | ||||
|       when: inventory_hostname != 'nas.home.lan' | ||||
|  | ||||
|   - name: Reconfigure zabbix agent Server | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       regexp: "^Server=.*" | ||||
|       insertafter: '^# Server=' | ||||
|       line: "Server=192.168.77.0/24,192.168.89.0/28" | ||||
|     - name: Reconfigure zabbix agent Server | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         regexp: "^Server=.*" | ||||
|         insertafter: '^# Server=' | ||||
|         line: "Server=192.168.77.0/24,192.168.89.0/28" | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix agent ServerActive | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       regexp: "^ServerActive=.*" | ||||
|       line: "ServerActive={{ ZABBIX_SERVER }}" | ||||
|     - name: Reconfigure zabbix agent ServerActive | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         regexp: "^ServerActive=.*" | ||||
|         line: "ServerActive={{ ZABBIX_SERVER }}" | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix agent ListenPort | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       regexp: "^ListenPort=.*" | ||||
|       line: "ListenPort=10050" | ||||
|   # - name: Reconfigure zabbix agent ListenIP | ||||
|   #   ansible.builtin.lineinfile: | ||||
|   #     path: /"{{ zabbix_agent_cfg }}" | ||||
|   #     regexp: "^ListenIP=.*" | ||||
|   #     line: "ListenIP=0.0.0.0" | ||||
|     - name: Reconfigure zabbix agent ListenPort | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         regexp: "^ListenPort=.*" | ||||
|         line: "ListenPort=10050" | ||||
|     # - name: Reconfigure zabbix agent ListenIP | ||||
|     #   ansible.builtin.lineinfile: | ||||
|     #     path: /"{{ zabbix_agent_cfg }}" | ||||
|     #     regexp: "^ListenIP=.*" | ||||
|     #     line: "ListenIP=0.0.0.0" | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix-agent2 hostname | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       regexp: "^Hostname=.*" | ||||
|       line: "Hostname={{ inventory_hostname }}" | ||||
|     - name: Reconfigure zabbix-agent2 hostname | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         regexp: "^Hostname=.*" | ||||
|         line: "Hostname={{ inventory_hostname }}" | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix-agent2 config | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       insertafter: '^# UserParameter=' | ||||
|       regexp: "^UserParameter=system.certs.*" | ||||
|       line: "UserParameter=system.certs,python3 /share/ZFS530_DATA/.qpkg/ZabbixAgent/cert_check2.py" | ||||
|     when: inventory_hostname == 'nas.home.lan' | ||||
|     - name: Reconfigure zabbix-agent2 config | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         insertafter: '^# UserParameter=' | ||||
|         regexp: "^UserParameter=system.certs.*" | ||||
|         line: "UserParameter=system.certs,python3 /share/ZFS530_DATA/.qpkg/ZabbixAgent/cert_check2.py" | ||||
|       when: inventory_hostname == 'nas.home.lan' | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix-agent2 config | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       insertafter: '^# UserParameter=' | ||||
|       regexp: "^UserParameter=system.certs.*" | ||||
|       line: "UserParameter=system.certs,python3 /usr/bin/cert_check2.py" | ||||
|     when: inventory_hostname == 'm-server.home.lan'  | ||||
|     - name: Reconfigure zabbix-agent2 config | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         insertafter: '^# UserParameter=' | ||||
|         regexp: "^UserParameter=system.certs.*" | ||||
|         line: "UserParameter=system.certs,python3 /usr/bin/cert_check2.py" | ||||
|       when: inventory_hostname == 'm-server.home.lan' | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix-agent2 config | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       insertafter: '^# UserParameter=' | ||||
|       line: "UserParameter=rpi.hw.temp,/usr/bin/vcgencmd measure_temp" | ||||
|     when: inventory_hostname == 'rpi5.home.lan' | ||||
|     - name: Reconfigure zabbix-agent2 config | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         insertafter: '^# UserParameter=' | ||||
|         line: "UserParameter=rpi.hw.temp,/usr/bin/vcgencmd measure_temp" | ||||
|       when: inventory_hostname == 'rpi5.home.lan' | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix-agent2 hostname | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       regexp: "^HostMetadata=.*" | ||||
|       insertafter: '^# HostMetadata=' | ||||
|       line: "HostMetadata=linux;jaydee" | ||||
|     - name: Reconfigure zabbix-agent2 hostname | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         regexp: "^HostMetadata=.*" | ||||
|         insertafter: '^# HostMetadata=' | ||||
|         line: "HostMetadata=linux;jaydee" | ||||
|  | ||||
|     - name: Reconfigure zabbix-agent2 hostname | ||||
|       ansible.builtin.lineinfile: | ||||
|         path: "{{ zabbix_agent_cfg }}" | ||||
|         regexp: "^HostMetadata=.*" | ||||
|         insertafter: '^# HostMetadata=' | ||||
|         line: "HostMetadata=server;jaydee" | ||||
|       when: inventory_hostname == 'nas.home.lan' or inventory_hostname == 'm-server.home.lan' | ||||
|  | ||||
|     - name: Add the user 'to group video | ||||
|       ansible.builtin.user: | ||||
|         name: zabbix | ||||
|         groups: video | ||||
|         append: true | ||||
|       when: inventory_hostname != 'nas.home.lan' | ||||
|  | ||||
|  | ||||
|  | ||||
|   - name: Reconfigure zabbix-agent2 hostname | ||||
|     ansible.builtin.lineinfile: | ||||
|       path: "{{ zabbix_agent_cfg }}" | ||||
|       regexp: "^HostMetadata=.*" | ||||
|       insertafter: '^# HostMetadata=' | ||||
|       line: "HostMetadata=server;jaydee" | ||||
|     when: inventory_hostname == 'nas.home.lan' or inventory_hostname == 'm-server.home.lan'  | ||||
|     - name: Restart zabbix-agent2 service | ||||
|       ansible.builtin.service: | ||||
|         name: zabbix-agent2.service | ||||
|         state: restarted | ||||
|         enabled: true | ||||
|       when: inventory_hostname != 'nas.home.lan' | ||||
|  | ||||
|  | ||||
|  | ||||
|   - name: Add the user 'to group video | ||||
|     ansible.builtin.user: | ||||
|       name: zabbix | ||||
|       groups: video | ||||
|       append: yes | ||||
|     when: inventory_hostname != 'nas.home.lan' | ||||
|  | ||||
|  | ||||
|   - name: Restart zabbix-agent2 service | ||||
|     ansible.builtin.service: | ||||
|       name: zabbix-agent2.service | ||||
|       state: restarted | ||||
|       enabled: true | ||||
|     when: inventory_hostname != 'nas.home.lan' | ||||
|  | ||||
|  | ||||
|   - name: Restart agent | ||||
|     ansible.builtin.shell: /etc/init.d/ZabbixAgent.sh restart | ||||
|     when: inventory_hostname == 'nas.home.lan' | ||||
|  | ||||
|  | ||||
|   become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}" | ||||
|     - name: Restart agent | ||||
|       ansible.builtin.command: /etc/init.d/ZabbixAgent.sh restart | ||||
|       when: inventory_hostname == 'nas.home.lan' | ||||
|       changed_when: false | ||||
|   | ||||
		Reference in New Issue
	
	Block a user