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

unable to connect to socket error while running task for multiple server

Open solick opened this issue 1 year ago • 16 comments

SUMMARY

Running a task against one server is working, running it against a server group cause "unable to connect to socket" error

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.zabbix.zabbix_hostmacro:

ANSIBLE VERSION
ansible [core 2.15.3]
  config file = /Users/xxx/Development/Ansible/lmc-ansible/ansible.cfg
  configured module search path = ['/Users/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/8.3.0/libexec/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.5 (main, Aug 24 2023, 15:18:16) [Clang 14.0.3 (clang-1403.0.22.14.1)] (/usr/local/Cellar/ansible/8.3.0/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True

CONFIGURATION
CONFIG_FILE() = /Users/xxx/Development/Ansible/lmc-ansible/ansible.cfg
DEFAULT_HOST_LIST(/Users/xxx/Development/Ansible/lmc-ansible/ansible.cfg) = ['/Users/xxx/Development/Ansible/lmc-ansible/hosts']
DEFAULT_REMOTE_USER(/Users/xxx/Development/Ansible/lmc-ansible/ansible.cfg) = root
DEFAULT_VAULT_PASSWORD_FILE(/Users/xxx/Development/Ansible/lmc-ansible/ansible.cfg) = /Users/xxx/Development/Ansible/lmc-ansible-vault-password
EDITOR(env: EDITOR) = nano

OS / ENVIRONMENT / Zabbix Version

Zabbix 6.0 MacOS 17.1

STEPS TO REPRODUCE

Set macros via zabbix_hostmacro module. Use the tasks for a single server is working, use the task for a group of servers is not working.

---

- name: add maccro trigger_threshold_processes to host
  vars:
    gather_facts: false
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true  # Set to true for HTTPS
    ansible_httpapi_validate_certs: true  # For HTTPS et to true to validate server's certificate
  community.zabbix.zabbix_hostmacro:
    host_name: "{{ inventory_hostname }}"
    macro_name: "{$TRIGGER_THRESHOLD_PROCESSES}"
    macro_value: "{{ zabbix_proxmox_threshold_processes }}"
    macro_description: "extended value because proxmox server"
  become: false
  delegate_to: "{{ zabbix_api_server_host }}"

- name: add maccro trigger_threshold_processes_running to host
  vars:
    gather_facts: false
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true  # Set to true for HTTPS
    ansible_httpapi_validate_certs: true  # For HTTPS et to true to validate server's certificate
  community.zabbix.zabbix_hostmacro:
    host_name: "{{ inventory_hostname }}"
    macro_name: "{$TRIGGER_THRESHOLD_PROCESSES_RUNNING}"
    macro_value: "{{ zabbix_proxmox_threshold_processes_running }}"
    macro_description: "extended value because proxmox server"
  become: false
  delegate_to: "{{ zabbix_api_server_host }}"
  
EXPECTED RESULTS

The task should be able to run against a group of servers without error.

ACTUAL RESULTS

The error does not occur for all servers (I tested with a group of 6 servers) but occurs for part of them.

fatal: [server3.xxx -> zabbix.xxx]: FAILED! => {"msg": "Traceback (most recent call last):\n  File \"/usr/local/Cellar/ansible/8.3.0/libexec/lib/python3.11/site-packages/ansible/module_utils/connection.py\", line 207, in send\n    sf.connect(self.socket_path)\nConnectionRefusedError: [Errno 61] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/usr/local/Cellar/ansible/8.3.0/libexec/lib/python3.11/site-packages/ansible/cli/scripts/ansible_connection_cli_stub.py\", line 315, in main\n    conn.set_options(direct=options)\n  File \"/usr/local/Cellar/ansible/8.3.0/libexec/lib/python3.11/site-packages/ansible/module_utils/connection.py\", line 194, in __rpc__\n    response = self._exec_jsonrpc(name, *args, **kwargs)\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/Cellar/ansible/8.3.0/libexec/lib/python3.11/site-packages/ansible/module_utils/connection.py\", line 155, in _exec_jsonrpc\n    out = self.send(data)\n          ^^^^^^^^^^^^^^^\n  File \"/usr/local/Cellar/ansible/8.3.0/libexec/lib/python3.11/site-packages/ansible/module_utils/connection.py\", line 214, in send\n    raise ConnectionError(\nansible.module_utils.connection.ConnectionError: unable to connect to socket /Users/xxx/.ansible/pc/615f7cd59a. See the socket path issue category in Network Debug and Troubleshooting Guide\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/usr/local/bin/ansible-connection\", line 8, in <module>\n    sys.exit(main())\n             ^^^^^^\n  File \"/usr/local/Cellar/ansible/8.3.0/libexec/lib/python3.11/site-packages/ansible/cli/scripts/ansible_connection_cli_stub.py\", line 318, in main\n    raise ConnectionError('Unable to decode JSON from response set_options. See the debug log for more information.')\nansible.module_utils.connection.ConnectionError: Unable to decode JSON from response set_options. See the debug log for more information.\n"}

solick avatar Nov 03 '23 16:11 solick

Not sure I totally follow what you mean by use it for a group of servers.

pyrodie18 avatar Nov 04 '23 21:11 pyrodie18

@pyrodie18 i have in my hosts file a group called proxmox_servers where are 6 server assigned. When I start the playbook with the --limit proxmox_servers the problem occurs.

solick avatar Nov 04 '23 23:11 solick

As I read the output of the error (granted I'm not an expert), I don't see it even trying to execute the module, but instead failing trying to connect to the host. I suspect (again, a bit of a guess) that because you're delegating to zabbix_api_server_host that because you are limiting, that its not adding that host into your inventory in memory and so when it tries to connect to it, it has no idea how to connect to it. Or I could be completely wrong.

pyrodie18 avatar Nov 05 '23 02:11 pyrodie18

@solick did you try to follow these steps as failure message suggests https://docs.ansible.com/ansible/latest/network/user_guide/network_debug_troubleshooting.html#troubleshooting-socket-path-issues ?

BGmot avatar Nov 06 '23 01:11 BGmot

Any feedback @solick ?

pyrodie18 avatar Nov 20 '23 03:11 pyrodie18

@pyrodie18 @BGmot sorry für my late response. I was very busy the last weeks. I will try to troubleshoot within the next days and will than give feedback.

solick avatar Nov 20 '23 06:11 solick

I have the same problem after migration to the new connect method.

out of 10 server, maybe 2 goes ok

nerdalertdk avatar Dec 04 '23 20:12 nerdalertdk

Looks like it runs it multiple time on each host.

This is the web log for 11 hosts

zabbix: 6.2

zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 89 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 592 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 592 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 584 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 584 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 176 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 586 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 179 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 176 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:52 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 179 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 618 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 946 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 616 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 297 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 946 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 296 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 1092 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:53 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:54 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 1594 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 592 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 592 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 631 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 631 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 176 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 176 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 179 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 179 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:55 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 596 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 598 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 960 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 929 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 286 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 287 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 273 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 1139 "-" "Python-urllib/3.12" "-"
zabbix-web                  | 100.117.160.3 - - [04/Dec/2023:21:55:56 +0100] "POST /api_jsonrpc.php HTTP/1.1" 200 1139 "-" "Python-urllib/3.12" "-"
PLAY RECAP **************************************************************************************************
RANDOMSERVERNAME1.net : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME2.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME3.net : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME4.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME5.net : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME6.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME7.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME8.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME9.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME10.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
RANDOMSERVERNAME11.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  
- name: Zabbix | Create a new host or update an existing host's info
  vars:
    gather_facts: false
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 80
    ansible_httpapi_use_ssl: false
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: ''
    ansible_zabbix_auth_key: "{{ secure_zabbix_api_token }}"
  become: false
  delegate_to: "{{ secure_zabbix_host_url }}"
  community.zabbix.zabbix_host:
    host_name: "{{ inventory_hostname }}"
    host_groups:
      - 'Linux servers'
    link_templates: "{{ zabbix_link_templates }}"
    interfaces:
      - type: 'agent'
        main: 1
        useip: 0
        dns: "{{ inventory_hostname }}"

run_once: true, do not help

some fail with ConnectionRefusedError: [Errno 61] Connection refused others Unable to decode JSON from response set_options. See the debug log for more information.

it's not isolated to one host, This is the result from two runs, no changes made

HOST1.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST2.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST3.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST4.net : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
HOST5.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST6.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST7.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST8.net : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
HOST9.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST10.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST11.net : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

HOST1.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST2.net : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
HOST3.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST4.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST5.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST6.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST7.net : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
HOST8.net : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
HOST9.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST10.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
HOST11.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  

nerdalertdk avatar Dec 04 '23 20:12 nerdalertdk

One execution of zabbix_host module (and almost all modules) involves multiple API calls, I believe this is what you are seeing not several execution of zabbix_host on each server. Would you be able to provide full tcpdump between your Ansible controller and Zabbix server for the whole playbook run?

BGmot avatar Dec 04 '23 21:12 BGmot

One execution of zabbix_host module (and almost all modules) involves multiple API calls, I believe this is what you are seeing not several execution of zabbix_host on each server. Would you be able to provide full tcpdump between your Ansible controller and Zabbix server for the whole playbook run?

Hi, Sorry really don't have time too do a deep debug of this now

For everyone else, fixed it by using version 1.9.3 now my old role just work

requirements.yaml


collections:
  - name: community.zabbix
    version: 1.9.3

nerdalertdk avatar Dec 11 '23 15:12 nerdalertdk

Hi, I specified the following variables for the test:

      zabbix_api_server_host: zabbix.example.com
      zabbix_api_server_port: 80
      ansible_zabbix_url_path: '/'

I performed a tcpdump on the Zabbix server and saw that in the “Host:” header the IP address was indicated instead of the host name.

POST ///api_jsonrpc.php HTTP/1.1
Accept-Encoding: identity
Content-Length: 162
Host: xxx.xxx.xxx.xxx:80
User-Agent: Python-urllib/3.10
Content-Type: application/json-rpc
Accept: application/json
Auth: fake
Connection: close

I process all such requests in NGINX with server_name _;, so requests do not go to Zabbix. Requests without a hostname are sent over both HTTP and HTTPS.

I think if you remove the conversion of the host name to IP address, the problem will be solved.

snk26 avatar Jan 16 '24 16:01 snk26

Same issue with version 2.3.1. The task will randomly fail on some hosts when executing against a group. When running the task against the hosts one by one, not against the group, it finishes successfully every time.

Zabbix Server is 6.4.2

Edit: looks like this might be related.

leomuso avatar Jan 24 '24 10:01 leomuso

Finally got time to investigate this interesting problem. Cannot reproduce. My environment: Zabbix version 6.4.12 (I don't think it matters).

ey@ls1:~/ansible$ ansible --version
ansible [core 2.12.4]
  config file = /home/ey/ansible/ansible.cfg
  configured module search path = ['/home/ey/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /home/ey/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

Tested with much newer version of Ansible/Python too:

(env_py312_ans216) ey@ls1:~/ansible$ ansible --version
ansible [core 2.16.0]
  config file = /home/ey/ansible/ansible.cfg
  configured module search path = ['/home/ey/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ey/env_py312_ans216/lib/python3.12/site-packages/ansible
  ansible collection location = /home/ey/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ey/env_py312_ans216/bin/ansible
  python version = 3.12.2 (main, Feb 25 2024, 16:36:57) [GCC 9.4.0] (/home/ey/env_py312_ans216/bin/python)
  jinja version = 3.1.3
  libyaml = True

Collection version is 2.3.1.

My inventory:

ey@ls1:~/ansible$ cat inventories/multiple_hosts_fail.yml 
RANDOMSERVERNAME1.net
RANDOMSERVERNAME2.net
RANDOMSERVERNAME3.net
RANDOMSERVERNAME4.net
RANDOMSERVERNAME5.net
RANDOMSERVERNAME6.net
RANDOMSERVERNAME7.net
RANDOMSERVERNAME8.net
RANDOMSERVERNAME9.net
RANDOMSERVERNAME10.net
RANDOMSERVERNAME11.net

My playbook:

ey@ls1:~/ansible$ cat multiple_hosts_fail.yml 
---
- hosts: all
  gather_facts: false
  vars:
    secure_zabbix_host_url: 'ls1'
    secure_zabbix_api_token: 'df8288ac524a826e4c0aabd7fdde40d0caf0e349adf18ea4d8cbd023b8eebc71'
    zabbix_link_templates:
      - 'Linux by Zabbix agent'
  tasks:
  - name: Zabbix | Create a new host or update an existing host's info
    vars:
      gather_facts: false
      ansible_network_os: community.zabbix.zabbix
      ansible_connection: httpapi
      ansible_httpapi_port: 8080
      ansible_httpapi_use_ssl: false
      ansible_httpapi_validate_certs: false
      ansible_zabbix_url_path: ''
      ansible_zabbix_auth_key: "{{ secure_zabbix_api_token }}"
    become: false
    delegate_to: "{{ secure_zabbix_host_url }}"
    community.zabbix.zabbix_host:
      host_name: "{{ inventory_hostname }}"
      host_groups:
        - 'Linux servers'
      link_templates: "{{ zabbix_link_templates }}"
      interfaces:
        - type: 'agent'
          main: 1
          useip: 0
          dns: "{{ inventory_hostname }}"

Running:

ey@ls1:~/ansible$ ansible-playbook -i inventories/multiple_hosts_fail.yml multiple_hosts_fail.yml

PLAY [all] ***********************************************************************************************************************************************************************************************************************************************************************

TASK [Zabbix | Create a new host or update an existing host's info] **************************************************************************************************************************************************************************************************************
changed: [RANDOMSERVERNAME4.net -> ls1]
changed: [RANDOMSERVERNAME5.net -> ls1]
changed: [RANDOMSERVERNAME3.net -> ls1]
changed: [RANDOMSERVERNAME2.net -> ls1]
changed: [RANDOMSERVERNAME1.net -> ls1]
changed: [RANDOMSERVERNAME6.net -> ls1]
changed: [RANDOMSERVERNAME7.net -> ls1]
changed: [RANDOMSERVERNAME8.net -> ls1]
changed: [RANDOMSERVERNAME9.net -> ls1]
changed: [RANDOMSERVERNAME10.net -> ls1]
changed: [RANDOMSERVERNAME11.net -> ls1]

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************************************************
RANDOMSERVERNAME1.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME10.net     : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME11.net     : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME2.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME3.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME4.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME5.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME6.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME7.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME8.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
RANDOMSERVERNAME9.net      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

And in WebUI I see all the hosts successfully added. Any thoughts how to proceed?

BGmot avatar Mar 04 '24 18:03 BGmot

Hey @BGmot, after some tests we discovered that the issue, at least for us, is mostly happening when running the playbooks on macOS. Running the same on Linux works just fine.

leomuso avatar Apr 10 '24 09:04 leomuso

Hey @BGmot, after some tests we discovered that the issue, at least for us, is mostly happening when running the playbooks on macOS. Running the same on Linux works just fine.

Bingo! On MacOS it fails indeed. On Ubuntu running without any problems. The same versions of Ansible + Python. I don't know how to troubleshoot this, does not look like the collection code related but rather "persistent connection" implementation by Ansible...

BGmot avatar Apr 10 '24 15:04 BGmot

Also on MacOS here

System Software Overview:

  System Version: macOS 14.4.1 (23E224)
  Kernel Version: Darwin 23.4.0

nerdalertdk avatar Apr 11 '24 12:04 nerdalertdk

+1 same problem on MacOS Ventura

texnocobra avatar May 15 '24 15:05 texnocobra

Since it sounds like this is definitely a problem with Ansible and not the collection, I'm going to close this out and encourage someone to open a ticket in the Ansible project.

pyrodie18 avatar May 16 '24 02:05 pyrodie18

Since it sounds like this is definitely a problem with Ansible and not the collection, I'm going to close this out and encourage someone to open a ticket in the Ansible project.

Hello @pyrodie18 ! Can you elaborate on how you came to the conclusion that this issue is with Ansible rather than the zabbix module? Could it not be an interaction with this module specifically and MacOS?

m!

matt604-adjust avatar Jun 06 '24 08:06 matt604-adjust

Since it sounds like this is definitely a problem with Ansible and not the collection, I'm going to close this out and encourage someone to open a ticket in the Ansible project.

Hello @pyrodie18 ! Can you elaborate on how you came to the conclusion that this issue is with Ansible rather than the zabbix module? Could it not be an interaction with this module specifically and MacOS?

m!

HttpAPI connection plugin is provided by Ansible, our modules just use it. The issue is not happening on Linux OS. Do you have any idea how we can troubleshoot this? I am all for it but don't know how to approach it.

BGmot avatar Jun 06 '24 11:06 BGmot

I have the same issue with my MacOS. If you run your task and override ansible_host via vars / or delegate_to it uses a persistent connection for the same host (specified as ansible_host/delegate_to). And as far as I understand, it can't be done on MacOS (security reason or something). I found a workaround - specify "fork=1" in ansible.cfg in that way, it will run one by one.. slowly but steadily.

I didn't find a way to disable the persistent connection for httpapi.

xocoru avatar Jul 02 '24 09:07 xocoru

unable to connect to socket /Users/xxx/.ansible/pc/615f7cd59a

I think, Ansible wants to use the same socket for multiple hosts. I captured this moment when unix socket was created for one host and the second host got "The error was: ansible.module_utils.connection.ConnectionError: unable to connect to socket /Users/aivanov/.ansible/pc/40a3273b53"

% ls -lsa /Users/aivanov/.ansible/pc/
total 0
0 drwxr-xr-x  4 aivanov  staff  128 Jul  2 12:14 .
0 drwxr-xr-x  7 aivanov  staff  224 Jun 28 18:44 ..
0 -rw-------  1 aivanov  staff    0 Jul  2 12:14 .ansible_pc_lock_40a3273b53
0 srwxr-xr-x  1 aivanov  staff    0 Jul  2 12:14 40a3273b53

xocoru avatar Jul 02 '24 09:07 xocoru

My understanding it is "by design" - one socket re-usable for all the hosts in the batch.

BGmot avatar Jul 02 '24 11:07 BGmot

But it means that Zabbix module is unusable at all.

Simple thing - I have many PDUs (no ssh) and want to configure them via REST API, then add each to Zabbix.

So, in these cases, I can't use the destination hosts (coz there is no SSH), and I can't use a Zabbix host from inventory because I need first enumerate all PDUs and get facts to fill host entries to Zabbix.

URI builtin module works fine with delegate_to localhost & multiple hosts in simultaneous run

xocoru avatar Jul 02 '24 13:07 xocoru

My config:

    - name: Checking that PDU exists in Zabbix
      vars:
        ansible_zabbix_auth_key: "{{ zabbix_token }}"
        ansible_network_os: community.zabbix.zabbix
        ansible_connection: httpapi
        ansible_httpapi_port: 443
        ansible_httpapi_use_ssl: true
        ansible_httpapi_validate_certs: true
        ansible_httpapi_use_proxy: false
        ansible_zabbix_url_path: ''
        ansible_host: monitoring.local
      community.zabbix.zabbix_host:
        host_name: "{{ inventory_hostname }}"
        visible_name: "{{ inventory_hostname_short | regex_replace('p1', 'PDU1') | regex_replace('p2', 'PDU2') }}"
        description: This object is created by Ansible. Be aware that some fields might be overwritten if you change it manually.
        host_groups:
          - All
          - "{{ zabbix_host_group | default('') }}"
        link_templates:
          - "{{ zabbix_host_template | default('') }}"
        proxy: "{{ zabbix_proxy | default('') }}"
        status: enabled
        state: present
        inventory_mode: automatic
        interfaces:
          - type: 2
            main: 1
            useip: 1
            ip: "{{ hostvars[inventory_hostname].ansible_host }}"
            dns: "{{ inventory_hostname }}"
            port: 161
            details:
              version: 2
              bulk: 1
              community: "{$SNMP_COMMUNITY}"
        macros:
          - macro: "{$SNMP_COMMUNITY}"
            value: "{{ snmp_community | default('public') }}"
        tags:
          - tag: Rack
            value: "{{ inventory_hostname_short | regex_replace('-p\\d+$', '') }}"
          - tag: NetboxRegions
            value: "{{ regions | default('') | join(',') | lower }}"
          - tag: NetboxSites
            value: "{{ sites | default('') | join(',') | lower }}"
          - tag: NetboxDeviceTypes
            value: "{{ device_types | default('') | join(',') | lower }}"
          - tag: NetboxManufacturers
            value: "{{ manufacturers | default('') | join(',') | lower }}"
          - tag: NetboxPlatforms
            value: "{{ platforms | default('') | join(',') | lower }}"
          - tag: NetboxRacks
            value: "{{ racks | default('') | join(',') | lower }}"
      become: false
      register: zabbix_host
      tags: zabbix

xocoru avatar Jul 02 '24 13:07 xocoru

But it means that Zabbix module is unusable at all.

Simple thing - I have many PDUs (no ssh) and want to configure them via REST API, then add each to Zabbix.

So, in these cases, I can't use the destination hosts (coz there is no SSH), and I can't use a Zabbix host from inventory because I need first enumerate all PDUs and get facts to fill host entries to Zabbix.

URI builtin module works fine with delegate_to localhost & multiple hosts in simultaneous run

If you carefully read this ticket you notice that this problem exists only on MacOS. Why? I don't know yet, did not have to investigate deeper. If you Ansible controller runs on Linux then you can manage as many hosts as you want.

BGmot avatar Jul 03 '24 00:07 BGmot