In Ansible 2.7.11 and wanted to use the module waif_for together with loops for connection test to my System Center Operations Manager (SCOM) servers.
Currently I'm using a task
- name: "Test connection to SCOM_MGMT_SRV_PROD: {{ SCOM_MGMT_SRV_PROD }}"
wait_for:
host: "{{ item }}"
port: "{{ SCOM_PORT }}"
state: drained # Port should be open
delay: 0 # No wait before first check (sec)
timeout: 3 # Stop checking after timeout (sec)
active_connection_states: SYN_RECV
with_items:
- server1
- server2
- server3
- server4
ignore_errors: yes
tags: connectionTest,testSCOM
where the variable SCOM_PORT
is set to 1270
and SCOM_MGMT_SRV_PROD
to a list of servers "server1,server2,server3,server4"
.
This approach is working but I wanted to have a variable list of servers maintained at a central place, like a global variable SCOM_MGMT_SRV_PROD
in inventory file.
It is possible to iterate over such a list via
- debug:
msg="{{ item }}"
loop: "{{ [SCOM_MGMT_SRV_PROD] }}"
but when using this approach in the task
- name: "Test connection to SCOM_MGMT_SRV_PROD: {{ SCOM_MGMT_SRV_PROD }}"
wait_for:
host: "{{ item }}"
port: "{{ SCOM_PORT }}"
state: drained # Port should be open
delay: 0 # No wait before first check (sec)
timeout: 3 # Stop checking after timeout (sec)
active_connection_states: SYN_RECV
loop: "{{ [SCOM_MGMT_SRV_PROD] }}"
ignore_errors: yes
tags: connectionTest,testSCOM
I'm getting an error
failed: [host] (item=server1,server2,server3,server4) => ... /tmp/ansible_wait_for_payload_zNj2ac/__main__.py\", line 380, in _convert_host_to_hex\r\n File \"/tmp/ansible_wait_for_payload_zNj2ac/__main__.py\", line 354, in _convert_host_to_ip\r\nsocket.gaierror: [Errno -2] Name or service not known\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
which for me indicates that the module wait_for
got the full list as item instead of one server from the list. The reason for the described behavior seems to be answered @https://stackoverflow.com/questions/48351187/.
Any idea how to get the module wait_for
working with a variable list of servers?
Other Components