ansible-collections / community.zabbix

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

`zabbix_api_use_ssl: true` uses port 80 by default. #1048

Closed Bubbgump209 closed 1 year ago

Bubbgump209 commented 1 year ago
SUMMARY

Registering an agent to the Zabbix server fails.

ISSUE TYPE
COMPONENT NAME

community.zabbix.zabbix_agent

ANSIBLE VERSION
ansible [core 2.14.3]
  config file = /Users/someuser/.ansible.cfg
  configured module search path = ['/Users/someuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/someuser/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.4 (main, Jun 20 2023, 16:51:49) [Clang 14.0.0 (clang-1400.0.29.202)] (/usr/local/opt/python@3.11/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
CONFIGURATION
CONFIG_FILE() = /Users/someuser/.ansible.cfg
DEFAULT_HOST_LIST(/Users/someuser/.ansible.cfg) = ['/Users/someuser/ansible/inventory']
DEFAULT_INVENTORY_PLUGIN_PATH(/Users/someuser/.ansible.cfg) = ['/Users/someuser/{{ ANSIBLE_HOME ~ "/plugins/inventory', '/usr/share/ansible/plugins/inventory" }}']
HOST_KEY_CHECKING(/Users/someuser/.ansible.cfg) = False
INVENTORY_ENABLED(/Users/someuser/.ansible.cfg) = ['ini', 'host_list', 'script', 'auto', 'yaml', 'toml']
OS / ENVIRONMENT / Zabbix Version

Tried to run against target hosts on Debian 11 and 12 VM (cloud image) and LXC.

Zabbix server 6.0.17 LTS.

community.zabbix 2.0.1 and 2.1.0 with both netcommon 4.1.0 and 5.1.2.

STEPS TO REPRODUCE

Command

ansible-playbook  InstallZabbixLXC.yml --extra-vars "host=192.168.73.112"

InstallZabbixLXC.yml

- name: Install the Zabbix agent and register with the Zabbix server
  hosts: "{{ hostvars['localhost']['fqdn'] | default(host) }}"
  tasks:
    - name: Generate UUID 
      ansible.builtin.shell: uuidgen
      register: UUID
      delegate_to: localhost
    - name: Generate key
      ansible.builtin.shell: openssl rand -hex 256
      register: PSK
      delegate_to: localhost

- hosts: "{{ hostvars['localhost']['fqdn'] | default(host) }}"
  roles:
    - role: community.zabbix.zabbix_agent
      zabbix_agent_become_on_localhost: false
      zabbix_agent_hostname: "{{ansible_hostname}}"
      zabbix_agent_server: 192.168.30.20
      zabbix_agent_serveractive: 192.168.30.20
      zabbix_api_server_url: https://zabbix.camdenacres.stream
      ansible_zabbix_url_path: "" 
      zabbix_api_use: true
      zabbix_api_use_ssl: yes
      zabbix_useuip: 0 # Use FQDN instead of IP.
      zabbix_api_login_user: Admin
      zabbix_api_login_pass: zabbix
      zabbix_agent_host_state: present
      zabbix_agent_version: 6.0
      zabbix_api_create_hosts: true
      zabbix_agent_tlsconnect: psk
      zabbix_agent_tlsaccept: psk
      zabbix_agent_tlspskidentity: "{{ UUID.stdout }}"
      zabbix_agent_tlspskfile: /etc/zabbix/zabbix_agent.psk
      zabbix_agent_tlspsk_secret: "{{ PSK.stdout }}"
      zabbix_host_groups:
        - Linux servers
      zabbix_agent_link_templates:
        - Template OS Linux LXC Container by Zabbix agent
      zabbix_agent_userparameters:
        - name: LXCZabbixAgent
EXPECTED RESULTS

I expect the Host to be registered in the Zabbix server using the PSK and ID provided by the playbook.

ACTUAL RESULTS

Everything in the role works until it reaches the point it needs to register with the Zabbix server at which case it fails. What is very curious is it appears to be calling https://localhost:80/api_jsonrpc.php instead of https://zabbix.camdenacres.stream/api_jsonrpc.php. I can't see where that would be coming from in the playbook.

Also, I have confirmed that I can indeed reach the Zabbix API from the target host as well as my localhost which is running Ansible.

curl --request POST \
         --url 'https://zabbix.camdenacres.stream/api_jsonrpc.php' \
         --header 'Content-Type: application/json-rpc' \
         --data '{"jsonrpc":"2.0","method":"apiinfo.version","params":{},"id":1}'
{"jsonrpc":"2.0","result":"6.0.17","id":1}

Failed step output

TASK [community.zabbix.zabbix_agent : API | Create a new host or update an existing host's info] ***
task path: /Users/someuser/.ansible/collections/ansible_collections/community/zabbix/roles/zabbix_agent/tasks/api.yml:15
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: someuser
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v `"&& mkdir "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136 `" && echo ansible-tmp-1689880569.361784-18645-221969449623136="` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136 `" ) && sleep 0'
Using module file /Users/someuser/.ansible/collections/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py
<localhost> PUT /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/tmpa68nlfz9 TO /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/AnsiballZ_zabbix_host.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/ /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/local/opt/python@3.11/bin/python3.11 /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/ > /dev/null 2>&1 && sleep 0'
FAILED - RETRYING: [192.168.73.112 -> localhost]: API | Create a new host or update an existing host's info (3 retries left).Result was: {
    "attempts": 1,
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/AnsiballZ_zabbix_host.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/AnsiballZ_zabbix_host.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880569.361784-18645-221969449623136/AnsiballZ_zabbix_host.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', init_globals=dict(_module_fqn='ansible_collections.community.zabbix.plugins.modules.zabbix_host', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_fh4cq0oa/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1237, in <module>\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_fh4cq0oa/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1042, in main\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_fh4cq0oa/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/base.py\", line 20, in __init__\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_fh4cq0oa/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py\", line 53, in api_version\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_fh4cq0oa/ansible_community.zabbix.zabbix_host_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\nansible.module_utils.connection.ConnectionError: Could not connect to https://localhost:80/api_jsonrpc.php: [Errno 61] Connection refused\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "retries": 4
}
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v `"&& mkdir "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674 `" && echo ansible-tmp-1689880574.9608378-18645-250204479794674="` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674 `" ) && sleep 0'
Using module file /Users/someuser/.ansible/collections/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py
<localhost> PUT /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/tmpqgslt96y TO /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/AnsiballZ_zabbix_host.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/ /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/local/opt/python@3.11/bin/python3.11 /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/ > /dev/null 2>&1 && sleep 0'
FAILED - RETRYING: [192.168.73.112 -> localhost]: API | Create a new host or update an existing host's info (2 retries left).Result was: {
    "attempts": 2,
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/AnsiballZ_zabbix_host.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/AnsiballZ_zabbix_host.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880574.9608378-18645-250204479794674/AnsiballZ_zabbix_host.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', init_globals=dict(_module_fqn='ansible_collections.community.zabbix.plugins.modules.zabbix_host', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_ybwpnw00/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1237, in <module>\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_ybwpnw00/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1042, in main\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_ybwpnw00/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/base.py\", line 20, in __init__\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_ybwpnw00/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py\", line 53, in api_version\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_ybwpnw00/ansible_community.zabbix.zabbix_host_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\nansible.module_utils.connection.ConnectionError: Could not connect to https://localhost:80/api_jsonrpc.php: [Errno 61] Connection refused\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "retries": 4
}
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v `"&& mkdir "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991 `" && echo ansible-tmp-1689880580.35712-18645-31509061879991="` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991 `" ) && sleep 0'
Using module file /Users/someuser/.ansible/collections/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py
<localhost> PUT /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/tmp7uvlk16_ TO /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/AnsiballZ_zabbix_host.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/ /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/local/opt/python@3.11/bin/python3.11 /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/ > /dev/null 2>&1 && sleep 0'
FAILED - RETRYING: [192.168.73.112 -> localhost]: API | Create a new host or update an existing host's info (1 retries left).Result was: {
    "attempts": 3,
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/AnsiballZ_zabbix_host.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/AnsiballZ_zabbix_host.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880580.35712-18645-31509061879991/AnsiballZ_zabbix_host.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', init_globals=dict(_module_fqn='ansible_collections.community.zabbix.plugins.modules.zabbix_host', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_0cmfrnr9/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1237, in <module>\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_0cmfrnr9/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1042, in main\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_0cmfrnr9/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/base.py\", line 20, in __init__\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_0cmfrnr9/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py\", line 53, in api_version\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_0cmfrnr9/ansible_community.zabbix.zabbix_host_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\nansible.module_utils.connection.ConnectionError: Could not connect to https://localhost:80/api_jsonrpc.php: [Errno 61] Connection refused\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "retries": 4
}
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v `"&& mkdir "` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521 `" && echo ansible-tmp-1689880585.750378-18645-49333304779521="` echo /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521 `" ) && sleep 0'
Using module file /Users/someuser/.ansible/collections/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py
<localhost> PUT /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/tmp2m2e_w_4 TO /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/ /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/local/opt/python@3.11/bin/python3.11 /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', init_globals=dict(_module_fqn='ansible_collections.community.zabbix.plugins.modules.zabbix_host', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py", line 1237, in <module>
  File "/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py", line 1042, in main
  File "/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/base.py", line 20, in __init__
  File "/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py", line 53, in api_version
  File "/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
ansible.module_utils.connection.ConnectionError: Could not connect to https://localhost:80/api_jsonrpc.php: [Errno 61] Connection refused
fatal: [192.168.73.112 -> localhost]: FAILED! => {
    "attempts": 3,
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/someuser/.ansible/tmp/ansible-local-18416xwc4ko3v/ansible-tmp-1689880585.750378-18645-49333304779521/AnsiballZ_zabbix_host.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', init_globals=dict(_module_fqn='ansible_collections.community.zabbix.plugins.modules.zabbix_host', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1237, in <module>\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1042, in main\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/base.py\", line 20, in __init__\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py\", line 53, in api_version\n  File \"/var/folders/yq/gp4yr4853pzb0pjc0q2srxym0000gn/T/ansible_community.zabbix.zabbix_host_payload_4fujnweu/ansible_community.zabbix.zabbix_host_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\nansible.module_utils.connection.ConnectionError: Could not connect to https://localhost:80/api_jsonrpc.php: [Errno 61] Connection refused\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
Bubbgump209 commented 1 year ago

I did a bit more digging and it seems my issue is a mix of bad documentation and unexpected behavior.

  1. zabbix_api_server_url does not work despite the UPGRADE docs suggesting that it should. Instead, this documentation and zabbix_api_server_host does work.
  2. Despite zabbix_api_use_ssl: true, 80 is still the port that is used. One must explicitly set zabbix_api_server_port: 443. This specifically seems to be a bug or at least very suboptimal. I would expect zabbix_api_use_ssl: true to automatically use 443 and only require zabbix_api_server_port: for non-standard ports.

What finally worked:

- hosts: "{{ hostvars['localhost']['fqdn'] | default(host) }}"
  roles:
    - role: community.zabbix.zabbix_agent
      zabbix_agent_become_on_localhost: true
      zabbix_agent_hostname: "{{ansible_hostname}}"
      zabbix_agent_server: 192.168.30.20
      zabbix_agent_serveractive: 192.168.30.20
      zabbix_api_server_host: zabbix.camdenacres.stream
      zabbix_api_server_port: 443
      ansible_zabbix_url_path: "" 
      zabbix_api_use: true
      zabbix_api_use_ssl: true
      zabbix_useuip: 0 # Use FQDN instead of IP.
      zabbix_api_login_user: Admin
      zabbix_api_login_pass: zabbix
      zabbix_agent_host_state: present
      zabbix_agent_version: 6.0
      zabbix_api_create_hosts: true
      zabbix_agent_tlsconnect: psk
      zabbix_agent_tlsaccept: psk
      zabbix_agent_tlspskidentity: "{{ UUID.stdout }}"
      zabbix_agent_tlspskfile: /etc/zabbix/zabbix_agent.psk
      zabbix_agent_tlspsk_secret: "{{ PSK.stdout }}"
      zabbix_host_groups:
        - Linux servers
      zabbix_agent_link_templates:
        - Template OS Linux LXC Container by Zabbix agent
      zabbix_agent_userparameters:
        - name: LXCZabbixAgent