community.zabbix icon indicating copy to clipboard operation
community.zabbix copied to clipboard

Calls to 6.4 server fail due to "user" parameter being deprecated/removed and httpapi variables won't work with set_fact per example

Open chrisallennc opened this issue 1 year ago • 20 comments

SUMMARY

Using server_url/login_user/login_password with modules to authenticate to 6.4.1 fails due to "user" parameter on user.login being deprecated/removed and "username" being required.

Furthermore, attempting to set variable "ansible_httpapi_pass" for httpapi with set_fact per examples fails. Since the parameter isn't being passed as "username" and that method is deprecated, we're attempted to switch to use httpapi.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Noticed with proxy_info but appears to be present in other modules

ANSIBLE VERSION
ansible [core 2.14.3]
CONFIGURATION
OS / ENVIRONMENT / Zabbix Version

Target host is RHEL 7, host running ansible is Rocky Linux 8.5

STEPS TO REPRODUCE
# This errors after upgrading Zabbix server to 6.4 because "user" is no longer a parameter for user.login.
- name: Get proxy
  community.zabbix.zabbix_proxy_info:
    server_url: "https://<server_fqdn>/zabbix/api_jsonrpc.php"
    login_user: zabbixapi
    login_password: "<password>"
    proxy_name: "<proxy_name>"
  register: zabbix_proxy
  delegate_to: localhost
# This works but we need to be able to make ansible_httpapi_pass set dynamically with set_fact so it's not stored in the play code itself and is sourced from our secret management system.
- name: Get proxy
  community.zabbix.zabbix_proxy_info:
    proxy_name: "<proxy_name>"
  register: zabbix_proxy
  delegate_to: localhost
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: true
    ansible_host: <server_fqdn>
    ansible_user: zabbixapi
    ansible_httpapi_pass: "<password>"

# If we use set_fact for "ansible_httpapi_pass" (per the examples) above the task it fails.
- set_fact:
    ansible_httpapi_pass: "<password>"

- name: Get proxy
  community.zabbix.zabbix_proxy_info:
    proxy_name: "<proxy_name>"
  register: zabbix_proxy
  delegate_to: localhost
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: true
    ansible_host: <server_fqdn>
    ansible_user: zabbixapi
EXPECTED RESULTS

Proxy object returned

ACTUAL RESULTS

Error with server_url/login_user/login_password:

TASK [zabbix-agent : Get proxy] *********************************************************************************************************************************************************************
[WARNING]: Option "server_url" is deprecated with the move to httpapi connection and will be removed in the next release
[WARNING]: Option "login_user" is deprecated with the move to httpapi connection and will be removed in the next release
[WARNING]: Option "login_password" is deprecated with the move to httpapi connection and will be removed in the next release
fatal: [<host_fqdn> -> localhost]: 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\": \"zabbixapi\", \"password\": \"********\"}, \"id\": 0}', -32602)"}

Error with httapi using set_fact:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: REST API returned {'code': -32602, 'message': 'Invalid params.', 'data': 'Invalid parameter "/password": a character string is expected.'} when sending {"jsonrpc": "2.0", "method": "user.login", "id": "42ac1f5d-3503-465f-9f7e-7232ac0931a4", "params": {"username": "zabbixapi", "password": null}}

chrisallennc avatar Apr 11 '23 16:04 chrisallennc