summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2021-03-23 16:12:49 +0100
committerGitHub <noreply@github.com>2021-03-23 16:12:49 +0100
commitc1eed681aafbfa1bc1c34ad1b0bf5c4be3201514 (patch)
tree6c2276af65e926263ac9f84ad527bf043024a844
parentFix trailing whitespace in Conditional debug() (#73956) (diff)
downloadansible-c1eed681aafbfa1bc1c34ad1b0bf5c4be3201514.tar.xz
ansible-c1eed681aafbfa1bc1c34ad1b0bf5c4be3201514.zip
fix wait_for looping when missing net module (#73963)
fixes #43486
-rw-r--r--changelogs/fragments/wait_for_fix.yml2
-rw-r--r--lib/ansible/modules/wait_for.py57
2 files changed, 32 insertions, 27 deletions
diff --git a/changelogs/fragments/wait_for_fix.yml b/changelogs/fragments/wait_for_fix.yml
new file mode 100644
index 0000000000..6678795258
--- /dev/null
+++ b/changelogs/fragments/wait_for_fix.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - wait_for module, move missing socket into function to get proper comparrison in time.
diff --git a/lib/ansible/modules/wait_for.py b/lib/ansible/modules/wait_for.py
index f87e46f0c5..428ff9bd27 100644
--- a/lib/ansible/modules/wait_for.py
+++ b/lib/ansible/modules/wait_for.py
@@ -369,28 +369,33 @@ class LinuxTCPConnectionInfo(TCPConnectionInfo):
for family in self.source_file.keys():
if not os.path.isfile(self.source_file[family]):
continue
- f = open(self.source_file[family])
- for tcp_connection in f.readlines():
- tcp_connection = tcp_connection.strip().split()
- if tcp_connection[self.local_address_field] == 'local_address':
- continue
- if (tcp_connection[self.connection_state_field] not in
- [get_connection_state_id(_connection_state) for _connection_state in self.module.params['active_connection_states']]):
- continue
- (local_ip, local_port) = tcp_connection[self.local_address_field].split(':')
- if self.port != local_port:
- continue
- (remote_ip, remote_port) = tcp_connection[self.remote_address_field].split(':')
- if (family, remote_ip) in self.exclude_ips:
- continue
- if any((
- (family, local_ip) in self.ips,
- (family, self.match_all_ips[family]) in self.ips,
- local_ip.startswith(self.ipv4_mapped_ipv6_address['prefix']) and
- (family, self.ipv4_mapped_ipv6_address['match_all']) in self.ips,
- )):
- active_connections += 1
- f.close()
+ try:
+ f = open(self.source_file[family])
+ for tcp_connection in f.readlines():
+ tcp_connection = tcp_connection.strip().split()
+ if tcp_connection[self.local_address_field] == 'local_address':
+ continue
+ if (tcp_connection[self.connection_state_field] not in
+ [get_connection_state_id(_connection_state) for _connection_state in self.module.params['active_connection_states']]):
+ continue
+ (local_ip, local_port) = tcp_connection[self.local_address_field].split(':')
+ if self.port != local_port:
+ continue
+ (remote_ip, remote_port) = tcp_connection[self.remote_address_field].split(':')
+ if (family, remote_ip) in self.exclude_ips:
+ continue
+ if any((
+ (family, local_ip) in self.ips,
+ (family, self.match_all_ips[family]) in self.ips,
+ local_ip.startswith(self.ipv4_mapped_ipv6_address['prefix']) and
+ (family, self.ipv4_mapped_ipv6_address['match_all']) in self.ips,
+ )):
+ active_connections += 1
+ except IOError as e:
+ pass
+ finally:
+ f.close()
+
return active_connections
@@ -651,11 +656,9 @@ def main():
end = start + datetime.timedelta(seconds=timeout)
tcpconns = TCPConnectionInfo(module)
while datetime.datetime.utcnow() < end:
- try:
- if tcpconns.get_active_connections_count() == 0:
- break
- except IOError:
- pass
+ if tcpconns.get_active_connections_count() == 0:
+ break
+
# Conditions not yet met, wait and try again
time.sleep(module.params['sleep'])
else: