Ansible can be used to check ports for multiple locations with multiple endpoints by utilizing the built-in wait_for
module. This module allows you to specify the endpoint IP address and port to check, as well as the timeout and number of retries.
Here's an example playbook that checks ports for multiple locations with multiple endpoints:
- name: Check ports for multiple locations with multiple endpoints
hosts: all
vars:
locations:
- name: Location 1
endpoints:
- 192.168.1.10
- 192.168.1.20
- 192.168.1.30
- name: Location 2
endpoints:
- 192.168.2.10
- 192.168.2.20
- 192.168.2.30
tasks:
- name: Check ports for endpoints in each location
wait_for:
host: "{{ endpoint }}"
port: "{{ port }}"
state: "started"
delay: 10
timeout: 60
retries: 6
loop: "{{ locations | json_query('[].endpoints[]') }}"
loop_control:
loop_var: endpoint
vars:
port: 22 # the port to check on each endpoint
register: port_checks
- name: Display results of port checks
debug:
msg: "Endpoint {{ item.item }} in {{ item.location }}: {{ item.status }}"
loop: "{{ port_checks.results }}"
loop_control:
label: "{{ item.item }}"
vars:
location: "{{ locations | json_query('[?endpoints.contains(@, `%s`)].name' % item.item) | first }}"
status: "{{ 'Success' if item.rc == 0 else 'Failure' }}"
In this playbook, we define a list of locations
that each have their own list of endpoints
. We then loop over each endpoint and use the wait_for
module to check if the specified port
is open. We register the results of each check and then display them in a debug message.
To run this playbook, you would need to specify the hosts to run it on and make any necessary modifications to the locations
and port
variables.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-01-25 11:00:00 +0000
Seen: 1 times
Last updated: Jun 07 '22
How can I deal with Expression.Error related to a column in Power Query?
How can you implement pagination in Oracle for the LISTAGG() function?
What is the process for implementing a FutureBuilder on an OnTap function in Flutter?
How can we require users to be logged in before they can access the root folders in WordPress?
In SCSS, what is the method for grouping and reusing a set of classes and styles?
How can popen() be used to direct streaming data to TAR?
How does iOS retrieve information from a BLE device?
How can Django Admin accommodate a variety of formats and locales for its input fields?