zabbix.zabbix.zabbix_host (1.3.6) — module

Module for creating hosts, deleting and updating existing hosts.

Authors: Zabbix Ltd (@zabbix)

Install collection

Install with ansible-galaxy collection install zabbix.zabbix:==1.3.6


Add to requirements.yml

  collections:
    - name: zabbix.zabbix
      version: 1.3.6

Description

The module is designed to create, update or delete a host in Zabbix.

In case of updating an existing host, only the specified parameters will be updated.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# To create host with minimum parameters
# Host group is required
- name: Create host
  zabbix.zabbix.zabbix_host:
    state: present
    host: Example host
    hostgroups:
      - Linux servers
  vars:
    ansible_network_os: zabbix.zabbix.zabbix
    ansible_connection: httpapi
    ansible_user: Admin
    ansible_httpapi_pass: zabbix
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# To create host with maximum parameters
- name: Create host with maximum parameters
  zabbix.zabbix.zabbix_host:
    state: present
    host: Example host
    hostgroups:
      - Linux servers
    templates:
      - Zabbix agent active
    status: enabled
    description: 'Host example'
    name: 'Example host'
    tags:
      - tag: scope
        value: test
    macros:
      - macro: TEST_MACRO
        value: example
        description: Description of macro example
        type: text
    ipmi_authtype: default
    ipmi_privilege: user
    ipmi_username: admin
    ipmi_password: your_password
    tls_accept:
      - unencrypted
      - psk
      - certificate
    tls_psk_identity: my_example_identity
    tls_psk: SET_YOUR_PSK_KEY
    tls_issuer: Example Issuer
    tls_subject: Example Subject
    tls_connect: psk
    inventory_mode: automatic
    inventory:
      type: ""  # To specify an empty value
      serialno_b: example value
      hardware_full: |
        very very long
        multiple string value
    interfaces:
      - type: agent # To specify an interface with default parameters (the IP will be 127.0.0.1)
      - type: ipmi
      - type: jmx
        ip: 192.168.100.51
        dns: test.com
        useip: true
        port: 12345
      - type: snmp
        ip: 192.168.100.50
        dns: switch.local
        port: 169   # To specify a non-standard value
        details:
          version: 3
          bulk: true
          contextname: my contextname name
          securityname: my securityname name
          securitylevel: authPriv
          authprotocol: md5
          authpassphrase: SET_YOUR_PWD
          privprotocol: des
          privpassphrase: SET_YOUR_PWD
  vars:
    ansible_network_os: zabbix.zabbix.zabbix
    ansible_connection: httpapi
    ansible_user: Admin
    ansible_httpapi_pass: zabbix
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# To update host to empty parameters
- name: Clean all parameters from host
  zabbix.zabbix.zabbix_host:
    state: present
    host: Example host
    hostgroups:    # Host group must be not empty
      - Linux servers
    templates: []
    status: enabled
    description: ''
    name: '' # The technical name will be used
    tags: []
    macros: []
    ipmi_authtype: default
    ipmi_privilege: user
    ipmi_username: ''
    ipmi_password: ''
    tls_accept:
      - unencrypted
    tls_issuer: ''
    tls_subject: ''
    tls_connect: unencrypted
    proxy: ''
    inventory_mode: disabled
    interfaces: []
  vars:
    ansible_network_os: zabbix.zabbix.zabbix
    ansible_connection: httpapi
    ansible_user: Admin
    ansible_httpapi_pass: zabbix
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# To update only one parameter, you can specify just
# the hostname (used for searching) and the desired parameter.
# The rest of the host parameters will not be changed.
# For example, you want to turn off a host
- name: Update host status
  zabbix.zabbix.zabbix_host:
    host: Example host
    status: disabled
  vars:
    ansible_network_os: zabbix.zabbix.zabbix
    ansible_connection: httpapi
    ansible_user: Admin
    ansible_httpapi_pass: zabbix
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# To remove a host, you can use:
- name: Delete host
  zabbix.zabbix.zabbix_host:
    state: absent
    host: Example host
  vars:
    ansible_network_os: zabbix.zabbix.zabbix
    ansible_connection: httpapi
    ansible_user: Admin
    ansible_httpapi_pass: zabbix
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# You can configure Zabbix API connection settings with the following parameters:
- name: Create host groups
  zabbix.zabbix.zabbix_host:
    state: present
    host: Example host
    hostgroups:
      - Linux servers
  vars:
    # Connection parameters
    ansible_host: zabbix-api.com                # Specifying Zabbix API address. You can also use 'delegate_to'.
    ansible_connection: httpapi                 # Specifying to use HTTP API plugin.
    ansible_network_os: zabbix.zabbix.zabbix    # Specifying which HTTP API plugin to use.
    ansible_httpapi_port: 80                    # Specifying the port for connecting to Zabbix API.
    ansible_httpapi_use_ssl: false              # Specifying the type of connection. True for https, False for http (by default).
    ansible_httpapi_validate_certs: false       # Specifying certificate validation.
    # User parameters for connecting to Zabbix API
    ansible_user: Admin                         # Username to connect to Zabbix API.
    ansible_httpapi_pass: zabbix                # Password to connect to Zabbix API.
    # Token for connecting to Zabbix API
    zabbix_api_token: your_secret_token         # Specify your token to connect to Zabbix API.
    # Path to connect to Zabbix API
    zabbix_api_url: '/zabbix'                   # The field is empty by default. You can specify your connection path (e.g., '/zabbix').
    # User parameters for basic HTTP authorization
    # These options only affect the basic HTTP authorization configured on the web server.
    http_login: my_http_login                   # Username for connecting to API in case of additional basic HTTP authorization.
    http_password: my_http_password             # Password for connecting to API in case of additional basic HTTP authorization.

Inputs

    
host:
    aliases:
    - host_name
    description:
    - Host name to create.
    - The name of an existing host in case of an update.
    required: true
    type: str

name:
    aliases:
    - visible_name
    description: Visible host name
    type: str

tags:
    aliases:
    - host_tags
    description:
    - Host tags to replace the current host tags.
    - All tags that are not listed in the task will be removed.
    elements: dict
    suboptions:
      tag:
        description: Host tag name.
        required: true
        type: str
      value:
        default: ''
        description: Host tag value.
        type: str
    type: list

proxy:
    description: Name of the proxy that is used to monitor the host.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description: Create or delete host.
    required: false
    type: str

macros:
    aliases:
    - user_macros
    - user_macro
    description:
    - User macros to replace the current user macros.
    - All macros that are not listed in the task will be removed.
    - If a secret macro is specified, the host will be updated every time the task is
      run.
    elements: dict
    suboptions:
      description:
        default: ''
        description: Description of the macro.
        type: str
      macro:
        description: Macro string.
        required: true
        type: str
      type:
        choices:
        - text
        - secret
        - vault_secret
        default: text
        description: Type of the macro.
        type: str
      value:
        default: ''
        description:
        - Value of the macro.
        - Write-only if I(type=secret).
        type: str
    type: list

status:
    choices:
    - enabled
    - disabled
    description: Host status (enabled or disabled).
    type: str

tls_psk:
    description:
    - The pre-shared key, at least 32 hex digits.
    - Required if I(tls_connect=psk), or I(tls_accept) contains the 'psk'.
    - In case of updating an existing host, if the host already has PSK enabled, the parameter
      is not required.
    - If the parameter is defined, then every launch of the task will update the host,
      because Zabbix API does not have access to an existing PSK key and we cannot compare
      the specified key with the existing one.
    type: str

inventory:
    aliases:
    - inventory_zabbix
    - host_inventory
    description:
    - The host inventory object.
    - 'All possible fields:'
    - type, type_full, name, alias, os, os_full, os_short, serialno_a, serialno_b, tag,
      asset_tag, macaddress_a, macaddress_b, hardware, hardware_full, software, software_full,
      software_app_a, software_app_b, software_app_c, software_app_d, software_app_e,
      contact, location, location_lat, location_lon, notes, chassis, model, hw_arch, vendor,
      contract_number, installer_name, deployment_status, url_a, url_b, url_c, host_networks,
      host_netmask, host_router, oob_ip, oob_netmask, oob_router, date_hw_purchase, date_hw_install,
      date_hw_expiry, date_hw_decomm, site_address_a, site_address_b, site_address_c,
      site_city, site_state, site_country, site_zip, site_rack, site_notes, poc_1_name,
      poc_1_email, poc_1_phone_a, poc_1_phone_b, poc_1_cell, poc_1_screen, poc_1_notes,
      poc_2_name, poc_2_email, poc_2_phone_a, poc_2_phone_b, poc_2_cell, poc_2_screen,
      poc_2_notes.
    - See U(https://www.zabbix.com/documentation/current/en/manual/api/reference/host/object#host-inventory)
      for an overview.
    type: dict

templates:
    aliases:
    - link_templates
    - host_templates
    - template
    description:
    - Templates to replace the currently linked templates.
    - All templates that are not listed in the task will be unlinked.
    elements: str
    type: list

hostgroups:
    aliases:
    - host_group
    - host_groups
    description:
    - Host groups to replace the current host groups the host belongs to.
    - All host groups that are not listed in the task will be unlinked.
    elements: str
    type: list

interfaces:
    description:
    - Host interfaces to replace the current host interfaces.
    - Only one interface of each type is supported.
    - All interfaces that are not listed in the request will be removed.
    elements: dict
    suboptions:
      details:
        description:
        - Additional details object for interface.
        - Required if I(type=snmp).
        suboptions:
          authpassphrase:
            description:
            - SNMPv3 authentication passphrase.
            - Used only if I(version=3).
            type: str
          authprotocol:
            choices:
            - md5
            - sha1
            - sha224
            - sha256
            - sha384
            - sha512
            description:
            - SNMPv3 authentication protocol.
            - Used only if I(version=3).
            type: str
          bulk:
            description: Whether to use bulk SNMP requests.
            type: bool
          community:
            description:
            - SNMP community.
            - Used only if I(version=1) or I(version=2).
            type: str
          contextname:
            description:
            - SNMPv3 context name.
            - Used only if I(version=3).
            type: str
          max_repetitions:
            description:
            - Max repetition count is applicable to discovery and walk only.
            - Used only if I(version=2) or I(version=3).
            - Used only for Zabbix versions above 6.4.
            type: str
          privpassphrase:
            description:
            - SNMPv3 privacy passphrase.
            - Used only if I(version=3).
            type: str
          privprotocol:
            choices:
            - des
            - aes128
            - aes192
            - aes256
            - aes192c
            - aes256c
            description:
            - SNMPv3 privacy protocol.
            - Used only if I(version=3).
            type: str
          securitylevel:
            choices:
            - noAuthNoPriv
            - authNoPriv
            - authPriv
            description:
            - SNMPv3 security level.
            - Used only if I(version=3).
            type: str
          securityname:
            description:
            - SNMPv3 security name.
            - Used only if I(version=3).
            type: str
          version:
            choices:
            - '1'
            - '2'
            - '3'
            description: SNMP interface version.
            type: str
        type: dict
      dns:
        default: ''
        description:
        - DNS name used by the interface.
        - Can be empty if the connection is made through IP.
        - Require if I(useip=False).
        type: str
      ip:
        default: ''
        description:
        - IP address used by the interface.
        - Can be empty if the connection is made through DNS.
        type: str
      port:
        description:
        - Port number used by the interface.
        - Can contain user macros.
        type: str
      type:
        choices:
        - agent
        - snmp
        - ipmi
        - jmx
        description: Interface type.
        required: true
        type: str
      useip:
        default: true
        description: Whether the connection should be made through IP.
        type: bool
    type: list

tls_accept:
    choices:
    - unencrypted
    - psk
    - cert
    description: Connections from host.
    elements: str
    type: list

tls_issuer:
    description: Certificate issuer.
    type: str

description:
    description: Host description.
    type: str

tls_connect:
    choices:
    - ''
    - unencrypted
    - psk
    - cert
    description: Connections to host.
    type: str

tls_subject:
    description: Certificate subject.
    type: str

ipmi_authtype:
    choices:
    - default
    - none
    - md2
    - md5
    - straight
    - oem
    - rmcp+
    description: IPMI authentication algorithm.
    type: str

ipmi_password:
    description: IPMI password.
    type: str

ipmi_username:
    description: IPMI username.
    type: str

inventory_mode:
    choices:
    - automatic
    - manual
    - disabled
    description: Host inventory population mode.
    type: str

ipmi_privilege:
    choices:
    - callback
    - user
    - operator
    - admin
    - oem
    description: IPMI privilege level.
    type: str

tls_psk_identity:
    description:
    - PSK identity.
    - Required if I(tls_connect=psk) , or I(tls_accept) contains the 'psk'.
    - In case of updating an existing host, if the host already has PSK enabled, the parameter
      is not required.
    - If the parameter is defined, then every launch of the task will update the host,
      because Zabbix API does not have access to an existing PSK key and we cannot compare
      the specified key with the existing one.
    type: str