| Server IP : 85.214.239.14  /  Your IP : 216.73.216.181 Web Server : Apache/2.4.65 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/ansible_collections/community/zabbix/roles/zabbix_agent/tasks/ | 
| Upload File : | 
---
- name: "Set default ip address for zabbix_agent_ip"
  set_fact:
    zabbix_agent_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4'].address }}"
  when:
    - zabbix_agent_ip is not defined
    - "'ansible_default_ipv4' in hostvars[inventory_hostname]"
- name: "Get Total Private IP Addresses"
  set_fact:
    total_private_ip_addresses: "{{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr('private') | length }}"
  when:
    - ansible_all_ipv4_addresses is defined
- name: "Set first public ip address for zabbix_agent_ip"
  set_fact:
    zabbix_agent_ip: "{{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr('public') | first }}"
    zabbix_agent_server: "{{ zabbix_agent_server_public_ip | default(zabbix_agent_server) }}"
    zabbix_agent_serveractive: "{{ zabbix_agent_serveractive_public_ip | default(zabbix_agent_serveractive) }}"
    zabbix_agent2_server: "{{ zabbix_agent_server_public_ip | default(zabbix_agent2_server) }}"
    zabbix_agent2_serveractive: "{{ zabbix_agent_serveractive_public_ip | default(zabbix_agent2_serveractive) }}"
  when:
    - zabbix_agent_ip is not defined
    - total_private_ip_addresses is defined
    - total_private_ip_addresses == '0'
- name: "Set first private ip address for zabbix_agent_ip"
  set_fact:
    zabbix_agent_ip: "{{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr('private') | first }}"
  when:
    - zabbix_agent_ip is not defined
    - total_private_ip_addresses is defined
    - total_private_ip_addresses != '0'
- name: "Fail invalid specified agent_listeninterface"
  fail:
    msg: "The specified network interface does not exist"
  when:
    - zabbix_agent_listeninterface
    - (zabbix_agent_listeninterface not in ansible_all_ipv4_addresses)
  tags:
    - zabbix-agent
    - config
- name: "Set network interface"
  set_fact:
    network_interface: ansible_{{ zabbix_agent_listeninterface }}
  when:
    - zabbix_agent_listeninterface
    - not zabbix_agent_listenip
- name: "Get IP of agent_listeninterface when no agent_listenip specified"
  set_fact:
    zabbix_agent_listenip: "{{ hostvars[inventory_hostname][network_interface]['ipv4'].address | default('0.0.0.0') }}"
    zabbix_agent_ip: "{{ hostvars[inventory_hostname][network_interface]['ipv4'].address | default('0.0.0.0') }}"
  when:
    - zabbix_agent_listeninterface
    - not zabbix_agent_listenip
  tags:
    - zabbix-agent
    - config
    - api
- name: "Default agent_listenip to all when not specified"
  set_fact:
    zabbix_agent_listenip: '0.0.0.0'
  when:
    - not zabbix_agent_listenip
  tags:
    - zabbix-agent
    - config
- name: "Fail invalid specified agent_listenip"
  fail:
    msg: "The agent_listenip does not exist"
  when:
    - zabbix_agent_listenip != '0.0.0.0'
    - zabbix_agent_listenip != '127.0.0.1'
    - (zabbix_agent_listenip not in ansible_all_ipv4_addresses)
  tags:
    - zabbix-agent
    - config
- name: "Installing Agent"
  include_tasks: macOS.yml
  tags:
    - always
- name: "Configure zabbix-agent"
  template:
    src: zabbix_agentd.conf.j2
    dest: "/usr/local/etc/zabbix/{{ zabbix_agent_conf }}"
    owner: zabbix
    group: wheel
    mode: 0644
  notify:
    - restart mac zabbix agent
  become: true
  when:
    - not (zabbix_agent_docker | bool)
  tags:
    - zabbix-agent
    - config
    - init
- name: "Create directory for PSK file if not exist."
  file:
    path: "{{ zabbix_agent_tlspskfile | dirname }}"
    mode: 0755
    state: directory
  become: true
  when:
    - zabbix_agent_tlspskfile is defined
- name: "Place TLS PSK File"
  copy:
    dest: "{{ zabbix_agent_tlspskfile }}"
    content: "{{ zabbix_agent_tlspsk_secret }}"
    owner: zabbix
    group: zabbix
    mode: 0400
  become: true
  when:
    - zabbix_agent_tlspskfile is defined
    - zabbix_agent_tlspsk_secret is defined
  notify:
    - restart mac zabbix agent
- name: "Create include dir zabbix-agent"
  file:
    path: "{{ zabbix_agent_include }}"
    owner: zabbix
    group: zabbix
    mode: 0750
    state: directory
  become: true
  tags:
    - config
    - include
- name: "Create pid file directory for zabbix-agent"
  file:
    path: /var/run/zabbix
    state: directory
    owner: zabbix
    group: zabbix
    mode: 0755
  become: true
- name: "Install the Docker container"
  include_tasks: Docker.yml
  when:
    - zabbix_agent_docker | bool
- name: "Check if zabbix-agent service is running"
  shell: |
    set -o pipefail
    launchctl list | grep com.zabbix.zabbix_agentd | awk '{print $1}'
  register: launchctl_pid
  check_mode: false
  changed_when: false
  failed_when: launchctl_pid.rc == 2
  become: true
  tags:
    - init
    - service
- name: "Make sure the zabbix-agent service is running"
  command: launchctl start com.zabbix.zabbix_agentd
  become: true
  when:
    - not (zabbix_agent_docker | bool)
    - launchctl_pid.stdout == "-"
  tags:
    - init
    - service