Project

General

Profile

Statistics
| Branch: | Revision:

ansible-role-zabbix / tasks / agent_detect_config.yml @ 3c1c0d84

History | View | Annotate | Download (2.72 KB)

1
---
2

    
3
- name: Load settings based on distribution
4
  include_vars: "{{ item }}"
5
  with_first_found:
6
    - "sys_{{ ansible_distribution }}.yml"
7
    - "sys_{{ ansible_os_family }}.yml"
8

    
9
- name: Load service detection settings
10
  include_vars: service_detection.yml
11

    
12
- name: Reset list of templates and macros
13
  set_fact:
14
    # TODO: support non-Linux OSes
15
    # Template App Zabbix Agent is a dependency, so no need to list it here
16
    templates: ['Template OS GNU-Linux']
17
    macros: {}
18

    
19
- name: "Autodetect services on Zabbix Agent host"
20
  include_tasks: _detect_service.yml
21
  with_dict: "{{ autodetect_agent_services }}"
22
  loop_control:
23
    loop_var: service
24

    
25
- name: Display detected list of templates
26
  debug:
27
    var: templates
28

    
29
- name: Register Agent
30
  block:
31
    - name: Compute final list of templates
32
      set_fact:
33
        final_templates: "{{ templates | union(agent.register.templates_extra|default([])) | difference(agent.register.templates_exclude|default([])) | unique }}"
34
    - name: Display chosen list of templates
35
      debug:
36
        var: final_templates
37
    - name: Register Agent via API
38
      zabbix_host:
39
        server_url: "{{ agent.register.api_url }}"
40
        login_user: "{{ agent.register.api_user }}"
41
        login_password: "{{ agent.register.api_pw }}"
42
        host_name: "{{ agent.register.host_name | default(inventory_hostname) }}"
43
        status: "{{ agent.register.enabled | default(True) | ternary('enabled', 'disabled') }}"
44
        state: present
45
        host_groups: "{{ agent.register.host_groups | mandatory }}"
46
        link_templates: "{{ final_templates }}"
47
        inventory_mode: automatic
48
        interfaces:
49
          - type: 1
50
            main: 1
51
            useip: 0
52
            ip: ''
53
            dns: "{{ agent.register.dns | default(ansible_fqdn) }}"
54
            port: "{{ agent.register.port | default(10050) }}"
55
        proxy: "{{ agent.register.proxy | default(None) }}"
56
        tls_accept: 4
57
        tls_connect: 4
58
        validate_certs: yes
59
      delegate_to: localhost
60
    - name: Compute final list of macros
61
      set_fact:
62
        final_macros: "{{ macros | combine(agent.register.macros|default({})) }}"
63
    - name: Display chosen list of macros
64
      debug:
65
        var: final_macros
66
    - name: Set Host Macros
67
      zabbix_hostmacro:
68
        server_url: "{{ agent.register.api_url }}"
69
        login_user: "{{ agent.register.api_user }}"
70
        login_password: "{{ agent.register.api_pw }}"
71
        host_name: "{{ agent.register.host_name | default(inventory_hostname) }}"
72
        macro_name: "{{ item.key }}"
73
        macro_value: "{{ item.value }}"
74
        state: "{{ item.value | ternary('present', 'absent') }}"
75
      loop: "{{ q('dict', final_macros) }}"
76
      delegate_to: localhost
77
  when: agent.register is defined
78