ansible-collections / community.zabbix

Zabbix Ansible modules
http://galaxy.ansible.com/community/zabbix
Other
322 stars 284 forks source link

community.zabbix.zabbix_host module not working properly on zabbix 6.4 #972

Closed Skultey closed 1 year ago

Skultey commented 1 year ago
SUMMARY

After updating to zabbix 6.4 our playbook started failing on adding zabbix hosts using community.zabbix.zabbix_host module

ISSUE TYPE
COMPONENT NAME

community.zabbix.zabbix_host

ANSIBLE VERSION

ansible 2.9.6

OS / ENVIRONMENT / Zabbix Version

Ubuntu latest, Zabbix 6.4

STEPS TO REPRODUCE
    local_action:
      module: community.zabbix.zabbix_host
      server_url: "{{server_url}}"
      login_user: Tteam
      login_password: "{{ login_password }}"
      host_name: "{{ zabbix_hostname }}"
      host_groups:
        - P_hosts
      link_templates:
        - Basic_Template
      status: enabled
      state: present
      inventory_mode: manual
      interfaces:
        - type: 1
          main: 1
          useip: 1
          ip: "{{ ansible_host }}"
          port: "10050"
      tls_accept: 2
      tls_connect: 2
      tls_psk: "{{ tls_psk }}" 
      tls_psk_identity: "{{ tls_psk_id }}"
EXPECTED RESULTS

We are expected things done so this task is creating a host in zabbix using our parameters.

ACTUAL RESULTS

FAILED! => {"changed": false, "msg": "Failed to connect to Zabbix server: ('Error -32602: Invalid params., Invalid parameter \"/\": unexpected parameter \"user\". while sending {\"jsonrpc\": \"2.0\", \"method\": \"user.login\", \"params\": {\"user\": \"Tteam\", \"password\": \"****\"}, \"id\": 0}', -32602)"}

eliottcassidy2000 commented 1 year ago

+1, ansible 6.4 completely breaks functionality of all roles in this collection since they all rely on this login function

hackatoo commented 1 year ago

We are patiently waiting for fixes, but our automatization based on this module. When it will be released, guys? Any info?

pyrodie18 commented 1 year ago

What version of the collection are you using?

hackatoo commented 1 year ago

@pyrodie18 community-zabbix-1.9.3 (currently)

salfers commented 1 year ago

It appears that the deprecated way of specifying server_url, login_user and does not and will never work with 6.4. See here https://github.com/ansible-collections/community.zabbix/issues/950#issuecomment-1507302099

pyrodie18 commented 1 year ago

@hackatoo and @salfers , try updating to the 2.0 release that we put out yesterday and let us know if you're still having problems.

tovoro commented 1 year ago

I updated to 2.0 release and still have problems with the host module:

But im not really sure if I use it correctly.

error message from awx:

{
  "msg": "connection error occurred: REST API returned {'code': -32602, 'message': 'Invalid params.', 'data': 'Session terminated, re-login, please.'} when sending {\"jsonrpc\": \"2.0\", \"method\": \"template.get\", \"id\": \"e98e06cf-7819-481d-a779-265c9f9d93fc\", \"params\": {\"output\": \"extend\", \"filter\": {\"host\": \"Linux by Zabbix agent\"}}, \"auth\": \"xxx\"}",
  "exception": "  File \"/tmp/ansible_community.zabbix.zabbix_host_payload_mdsw_9j5/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py\", line 29, in _httpapi_error_handle\n    code, response = self.connection.send_request(data=payload)\n  File \"/tmp/ansible_community.zabbix.zabbix_host_payload_mdsw_9j5/ansible_community.zabbix.zabbix_host_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\n",
  "invocation": {
    "module_args": {
      "force": false,
      "host_name": "xxx",
      "visible_name": "xxx",
      "host_groups": [
        "Linux servers"
      ],
      "link_templates": [
        "Linux by Zabbix agent"
      ],
      "status": "enabled",
      "tags": [
        {
          "tag": "xxx",
          "value": ""
        }
      ],
      "state": "present",
      "interfaces": [
        {
          "type": "1",
          "main": 1,
          "useip": 1,
          "ip": "1xxx,
          "dns": "xxx",
          "port": "10050",
          "details": {
            "version": 2,
            "bulk": 1,
            "community": "",
            "securityname": "",
            "contextname": "",
            "securitylevel": 0,
            "authprotocol": 0,
            "authpassphrase": "",
            "privprotocol": 0,
            "privpassphrase": ""
          }
        }
      ],
      "http_login_user": null,
      "http_login_password": null,
      "inventory_mode": null,
      "ipmi_authtype": null,
      "ipmi_privilege": null,
      "ipmi_username": null,
      "ipmi_password": null,
      "tls_connect": null,
      "tls_accept": null,
      "tls_psk_identity": null,
      "tls_psk": null,
      "ca_cert": null,
      "tls_subject": null,
      "inventory_zabbix": null,
      "proxy": null,
      "description": null,
      "macros": null
    }
  },
  "_ansible_no_log": null,
  "changed": false,
  "item": "syslog",
  "ansible_loop_var": "item",
  "_ansible_item_label": "syslog",
  "_ansible_delegated_vars": {
    "ansible_host": "xxx",
    "ansible_user": "apiuser",
    "ansible_connection": "httpapi"
  }
}

abstract from playbook:

- name: Register Host on Zabbix
      community.zabbix.zabbix_host:
        force: false
        host_name: "{{ hostname }}"
        visible_name: "{{ hostname }}"
        host_groups:
          - Linux servers
        link_templates:
          - Linux by Zabbix agent
        status: enabled
        tags:
          - tag: "{{ item }}"
        state: present
        interfaces:
          - type: 1
            main: 1
            useip: 1
            ip: "{{ ip }}"
            dns: "{{ hostname }}"
            port: "10050"
      delegate_to: zabbix_host
      with_items: "{{ zabbix_tags }}"
      become: false
Skultey commented 1 year ago

I've downloaded the newest version of zabbix module but it has some issues I've tried replacins login_password and login_user to the http version but I can't enter the server_url. There are no supported parameters out here. Can you help me, how can I authentithicate using zabbix_host module so I could add a new host using the parameters described by the zabbix_host module?

jirikotlin commented 1 year ago

Same problem with fresh install of 2.0.0. At my older laptop everything works with 1.9.2 but downgrading this module did not help.

jirikotlin commented 1 year ago

Further investigation in my case is that password auth works in 2.0.0:

ansible_user: Admin ansible_httpapi_pass: zabbix

But my playbooks with API token (ansible_zabbix_auth_key) does not work, it is omited, token not even sended to zabbix, and result:

ansible.module_utils.connection.ConnectionError: REST API returned {'code': -32602, 'message': 'Invalid params.', 'data': 'Invalid parameter "/username": a character string is expected.'} when sending {"jsonrpc": "2.0", "method": "user.login", "id": "6322c6f9-887e-4201-a301-a6ebfee3b337", "params": {"username": null, "password": null}}

Created another topic for my case: https://github.com/ansible-collections/community.zabbix/issues/988

hackatoo commented 1 year ago

Seems like in the new version there is no more variables as @Skultey metioned, so you need to update the params used for requesting data from Zabbix API and authorizing, because in the new version the problem still exist. For those, who just want to make it working now: update zabbix-api python library to 0.5.6, and rollback to 1.7.0 community.zabbix module version

BGmot commented 1 year ago

@tovoro we need to see how you set up all API related variables too. Please provide.

tovoro commented 1 year ago

thanks for the reply, it was an credential issue on my side in conjunction with awx. It works now, sorry for that

@tovoro we need to see how you set up all API related variables too. Please provide.

BGmot commented 1 year ago

Hi @Skultey @eliottcassidy2000 @hackatoo @jirikotlin @salfers! Do any of you still have problems/questions about zabbix_host with Zabbix 6.4 using collection version 2.0? If nobody replies within a week I'll close this issue.

Kulgar commented 1 year ago

Hello @BGmot I still have the "Session terminated, re-login, please." error message on my part with collection v2.0 and Zabbix 6.4

My credentials seem right as I managed to perform an auth using curl

[Edit] Ok... I found part of the issue, for an unknown reason, some of my host group variables are "undefined" when the agent role gets executed... I'll try to find why.

By setting passwords here:

    - name: "Run zabbix webapp role"
      include_role:
        name: community.zabbix.zabbix_agent
      vars:
        zabbix_api_login_pass: "pwd"
        ansible_httpapi_pass: "pwd"

It worked...

But if I do sth like this:

    - debug:
        msg: "{{ zabbix_admin_password }}"

    - name: "Run zabbix webapp role"
      include_role:
        name: community.zabbix.zabbix_agent
      vars:
        zabbix_api_login_pass: "{{ zabbix_admin_password }}"
        ansible_httpapi_pass: "{{ zabbix_admin_password }}"

It says "zabbix_admin_password" is undefined when reaching host group creation. Even though the previous debug msg is totally working and displaying my password.

But it works if I put the password variable in the "all" vars.yml file. So... the role is ignoring my group variables?

If you have any clue about why, let me know.

[Edit 2]

Actually it is even weirder, I have the following inventory:

[app]
server1

[db]
server2

[log]
server3

[preproduction]
server1
server2
server3

The variables set in the app/db/log groups are properly used. But the ones set in the preproduction group aren't... and only for this role. The other roles from the collection work fine with that inventory and my group vars.

eliottcassidy2000 commented 1 year ago

Hi @Skultey @eliottcassidy2000 @hackatoo @jirikotlin @salfers! Do any of you still have problems/questions about zabbix_host with Zabbix 6.4 using collection version 2.0? If nobody replies within a week I'll close this issue.

honestly, I tried my best to get version 2.0.1 working but it just doesnt seem worth it. Kept it at 1.9.3 and just set zabbix-api to 0.5.6 and that worked perfectly. I don't think we will be upgrading to 2.x for the foreseeable future. In my opinion, using httpapi for the ansible connection and having to delegate the task to a zabbix server seems really silly. Our zabbix url is loadbalanced and so we don't really want to send traffic to a hardcoded zabbix server in our ansible playbooks. We send all traffic to the virtual IP for our zabbix instance and the loadbalancer sends it to whatever server, we would like all connections to our zabbix to follow that basic pattern. Also the new solution is much more cumbersome to write in code, and judging from the across the board confusion I've seen various github issues I would say it is also unclear. The documentation on docs.ansible.com is also pretty hard to decipher, if I hadn't spent hours reading through issues I would feel so lost looking at it. Out current use of this module is essentially just a clean wrapper for zabbix API calls for our playbooks (we only use the plugins, haven't touched the roles at all). The playbooks we run don't have our zabbix servers in the inventories, we mainly just use it to make a quick API call for a maintenance window. Not trying to hate, and I do really appreciate the fact that this module exists, but 2.x feels like a step backward. As far as i can tell, the roles of this collection and the plugins seemed to be two separate things. Maybe it made sense to change the plugins in this way to better mesh with existing code, but it seemed like the collections (whose primary purpose is to make API calls to a zabbix server) really meshed well with that zabbix-api python package, and I would have kept them straightforward like that. Thank you for your work on this module regardless

tovoro commented 1 year ago

Hi @Skultey @eliottcassidy2000 @hackatoo @jirikotlin @salfers! Do any of you still have problems/questions about zabbix_host with Zabbix 6.4 using collection version 2.0? If nobody replies within a week I'll close this issue.

honestly, I tried my best to get version 2.0.1 working but it just doesnt seem worth it. Kept it at 1.9.3 and just set zabbix-api to 0.5.6 and that worked perfectly. I don't think we will be upgrading to 2.x for the foreseeable future. In my opinion, using httpapi for the ansible connection and having to delegate the task to a zabbix server seems really silly. Our zabbix url is loadbalanced and so we don't really want to send traffic to a hardcoded zabbix server in our ansible playbooks. We send all traffic to the virtual IP for our zabbix instance and the loadbalancer sends it to whatever server, we would like all connections to our zabbix to follow that basic pattern. Also the new solution is much more cumbersome to write in code, and judging from the across the board confusion I've seen various github issues I would say it is also unclear. The documentation on docs.ansible.com is also pretty hard to decipher, if I hadn't spent hours reading through issues I would feel so lost looking at it. Out current use of this module is essentially just a clean wrapper for zabbix API calls for our playbooks (we only use the plugins, haven't touched the roles at all). The playbooks we run don't have our zabbix servers in the inventories, we mainly just use it to make a quick API call for a maintenance window. Not trying to hate, and I do really appreciate the fact that this module exists, but 2.x feels like a step backward. As far as i can tell, the roles of this collection and the plugins seemed to be two separate things. Maybe it made sense to change the plugins in this way to better mesh with existing code, but it seemed like the collections (whose primary purpose is to make API calls to a zabbix server) really meshed well with that zabbix-api python package, and I would have kept them straightforward like that. Thank you for your work on this module regardless

I completely agree.

pyrodie18 commented 1 year ago

We appreciate your feedback @tovoro and @eliottcassidy2000

Bigsmooth68 commented 1 year ago

Hello @eliottcassidy2000 Despite few research, I did not find a proper way to rollback a collection. Would you please let me know how to do it? Thanks, Olivier

J4RF commented 1 year ago

Got my old task from a few years back to work with the new version, here's a snippet in case it helps anyone. Note that you have to have your Zabbix server as the host the playbook is running against, as it's no longer an option to provide it dynamically.

Old version:

- name: Add host to Zabbix server
  zabbix_host:
    server_url: '{{zabbix_server_url}}'
    login_user: '{{zabbix_user}}'
    login_password: '{{zabbix_pass}}'
    host_name: '{{hostname}}'
    visible_name: '{{hostname}}'
    host_groups: '{{zabbix_groups}}'
    link_templates: '{{zabbix_templates}}'
    interfaces:
      - type: '{{interface_type}}'
        main: '{{interface_is_main}}'
        ip: '{{ip_address}}'
        useip: '{{use_interface_ip}}'
        dns: '{{hostname}}'
        port: '{{agent_port}}'
    status: enabled
    state: present


New version:

- name: Add host to Zabbix server
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_zabbix_url_path: ''
    ansible_user: '{{zabbix_user}}'
    ansible_httpapi_pass: '{{zabbix_pass}}'
  zabbix_host:
    host_name: '{{hostname}}'
    visible_name: '{{hostname}}'
    host_groups: '{{zabbix_groups}}'
    link_templates: '{{zabbix_templates}}'
    interfaces:
      - type: '{{interface_type}}'
        main: '{{interface_is_main}}'
        useip: '{{use_interface_ip}}'
        ip: '{{ip_address}}'
        dns: '{{hostname}}'
        port: '{{agent_port}}'
    status: enabled
    state: present
BGmot commented 1 year ago

@pyrodie18 why is this issue still open? do you know? Everything works as documented.

pyrodie18 commented 1 year ago

Not a clue...because no one say to close it....Closing

Kulgar commented 1 year ago

@BGmot : should I open a new issue for my message? https://github.com/ansible-collections/community.zabbix/issues/972#issuecomment-1564107696 - as I don't have any clue with the zabbix web role isn't properly loading some of my host groups vars :-)

If you can think about an easy solution, maybe it's not necessary to create a new ticket...

BGmot commented 1 year ago

@Kulgar yes please