Ad Widget

Collapse

Create a host with snmp interface via api/ansible mudule "zabbix_host"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Create a host with snmp interface via api/ansible mudule "zabbix_host"

    Hello,
    I have a problem creating hosts with ansible (see https://docs.ansible.com/ansible/lat...st_module.html ) when I set the interface type to 2 (snmp). It works fine with the other types. I guess zabbix wants some more details like snmp version and community ( https://www.zabbix.com/documentation...terface/object ). Can anyone help me setting these in my playbook?

    My playbook:
    ---
    - hosts: test
    vars_files:
    - "../vars/zabbix_vars.yml"
    tasks:
    - name: "create host on zabbix server"
    local_action:
    module: zabbix_host
    server_url: "{{ zabbix_server_url }}"
    login_user: "{{ zabbix_user }}"
    login_password: "{{ zabbix_pw }}"
    host_name: test123
    interfaces:
    - type: 2
    ip: 10.0.0.1
    main: 1
    useip: 1
    dns: ""
    status: disabled
    state: present
    host_groups:
    - Networking Hardware
    And here the error:
    fatal: [test_centos8_4]: FAILED! => {"changed": false, "msg": "Failed to create host test123: ('Error -32602: Invalid params., Incorrect arguments passed to function. while sending {"jsonrpc": "2.0", "method": "host.create", "params": {"host": "test123", "interfaces": [{"type": 2, "ip": "10.0.0.1", "main": 1, "useip": 1, "dns": "", "port": "161"}], "groups": [{"groupid": "16"}], "status": 1, "tls_connect": 1, "tls_accept": 1}, "auth": "ebasdadadadasdasdadsadad", "id": 4}', -32602)"}
    Zabbix Server 5.0.0
    ansible 2.9.10
    zabbix-api 0.5.4

    #2
    Hi, vonlo!
    Got same problem. All parameters are looks good.
    Have you found the way to solve it or a workaround?

    Comment


      #3
      Can you try this :

      ---
      - hosts: test
      vars_files:
      - "../vars/zabbix_vars.yml"
      tasks:
      - name: "create host on zabbix server"
      local_action:
      module: zabbix_host
      server_url: "{{ zabbix_server_url }}"
      login_user: "{{ zabbix_user }}"
      login_password: "{{ zabbix_pw }}"
      host_name: test123
      interfaces:
      - type: 2
      ip: 10.0.0.1
      main: 1
      useip: 1
      dns: ""
      details:
      version: 2
      bulk: 1
      community: your_snmp_community

      status: disabled
      state: present
      host_groups:
      - Networking Hardware

      Comment


        #4
        Got same error. I suppose something wrong with SNMP interface creation. All other interface types was created successfully.

        Code:
        <localhost> ESTABLISH LOCAL CONNECTION FOR USER: awx
        <localhost> EXEC /bin/sh -c 'echo ~awx && sleep 0'
        <localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/awx/.ansible/tmp `"&& mkdir /home/awx/.ansible/tmp/ansible-tmp-1595602691.25-12384-160650177228842 && echo ansible-tmp-1595602691.25-12384-160650177228842="` echo /home/awx/.ansible/tmp/ansible-tmp-1595602691.25-12384-160650177228842 `" ) && sleep 0'
        Using module file /usr/lib/python2.7/dist-packages/ansible/modules/monitoring/zabbix/zabbix_host.py
        <localhost> PUT /home/awx/.ansible/tmp/ansible-local-12364Qize0G/tmpebL2GN TO /home/awx/.ansible/tmp/ansible-tmp-1595602691.25-12384-160650177228842/AnsiballZ_zabbix_host.py
        <localhost> EXEC /bin/sh -c 'chmod u+x /home/awx/.ansible/tmp/ansible-tmp-1595602691.25-12384-160650177228842/ /home/awx/.ansible/tmp/ansible-tmp-1595602691.25-12384-160650177228842/AnsiballZ_zabbix_host.py && sleep 0'
        <localhost> EXEC /bin/sh -c '/usr/bin/python2 /home/awx/.ansible/tmp/ansible-tmp-1595602691.25-12384-160650177228842/AnsiballZ_zabbix_host.py && sleep 0'
        <localhost> EXEC /bin/sh -c 'rm -f -r /home/awx/.ansible/tmp/ansible-tmp-1595602691.25-12384-160650177228842/ > /dev/null 2>&1 && sleep 0'
        The full traceback is:
        WARNING: The below traceback may *not* be related to the actual failure.
        File "/tmp/ansible_********_host_payload_Pioif3/ansible_********_host_payload.zip/ansible/modules/monitoring/********/********_host.py", line 378, in add_host
        File "/usr/local/lib/python2.7/dist-packages/********_api.py", line 341, in method
        return self.universal("%s.%s" % (self.data["prefix"], name), opts[0])
        File "/usr/local/lib/python2.7/dist-packages/********_api.py", line 79, in wrapper
        return self.do_request(self.json_obj(method, opts))['result']
        File "/usr/local/lib/python2.7/dist-packages/********_api.py", line 348, in do_request
        return self.parent.do_request(req)
        File "/usr/local/lib/python2.7/dist-packages/********_api.py", line 299, in do_request
        raise ZabbixAPIException(msg, jobj['error']['code'])
        fatal: [zabbix5-test.dotserv.ru]: FAILED! => {
        "changed": false,
        "invocation": {
        "module_args": {
        "ca_cert": null,
        "description": null,
        "force": true,
        "host_groups": [
        "Linux"
        ],
        "host_name": "test123",
        "http_login_password": null,
        "http_login_user": null,
        "interfaces": [
        {
        "bulk": 1,
        "community": "public",
        "details": null,
        "dns": "",
        "ip": "10.0.0.1",
        "main": 1,
        "port": "161",
        "state": "present",
        "status": "disabled",
        "type": 2,
        "useip": 1,
        "version": 2
        }
        ],
        "inventory_mode": null,
        "inventory_zabbix": null,
        "ipmi_authtype": null,
        "ipmi_password": null,
        "ipmi_privilege": null,
        "ipmi_username": null,
        "link_templates": null,
        "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
        "login_user": "Admin",
        "proxy": null,
        "server_url": "http://test-zbx5",
        "state": "present",
        "status": "enabled",
        "timeout": 10,
        "tls_accept": 1,
        "tls_connect": 1,
        "tls_psk": null,
        "tls_psk_identity": null,
        "tls_subject": null,
        "validate_certs": false,
        "visible_name": null
        }
        },
        "msg": "Failed to create host test123: (u'Error -32602: Invalid params., Incorrect arguments passed to function. while sending {"params": {"status": 0, "interfaces": [{"status": "disabled", "ip": "10.0.0.1", "useip": 1, "community": "public", "bulk": 1, "state": "present", "version": 2, "details": null, "dns": "", "main": 1, "type": 2, "port": "161"}], "tls_connect": 1, "tls_accept": 1, "host": "test123", "groups": [{"groupid": "17"}]}, "jsonrpc": "2.0", "method": "host.create", "auth": "6327c28a30643b80daeabad2424ceff7", "id": 4}', -32602)"

        Comment


          #5
          Hi,
          I got it working with this:

          interfaces:
          - type: 2
          main: 1
          useip: 1
          ip: "{{ primary_ip4 }}"
          dns: ""
          details:
          version: "{{ snmp_version }}"
          bulk: 1
          community: "{{ snmp_community }}"

          Comment

          Announcement

          Collapse
          No announcement yet.
          Working...
          X