mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
* Fix health check configurations being ignored - #43244 * Ensure health_check_protocol is not None before check * Simplify long indented if statement
This commit is contained in:
parent
079299db4d
commit
7e426b0381
1 changed files with 34 additions and 20 deletions
|
@ -397,9 +397,14 @@ def create_or_update_target_group(connection, module):
|
||||||
stickiness_lb_cookie_duration = module.params.get("stickiness_lb_cookie_duration")
|
stickiness_lb_cookie_duration = module.params.get("stickiness_lb_cookie_duration")
|
||||||
stickiness_type = module.params.get("stickiness_type")
|
stickiness_type = module.params.get("stickiness_type")
|
||||||
|
|
||||||
# If health check path not None, set health check attributes
|
health_option_keys = [
|
||||||
if module.params.get("health_check_path") is not None:
|
"health_check_path", "health_check_protocol", "health_check_interval", "health_check_timeout",
|
||||||
params['HealthCheckPath'] = module.params.get("health_check_path")
|
"healthy_threshold_count", "unhealthy_threshold_count", "successful_response_codes"
|
||||||
|
]
|
||||||
|
health_options = any([module.params[health_option_key] is not None for health_option_key in health_option_keys])
|
||||||
|
|
||||||
|
# Set health check if anything set
|
||||||
|
if health_options:
|
||||||
|
|
||||||
if module.params.get("health_check_protocol") is not None:
|
if module.params.get("health_check_protocol") is not None:
|
||||||
params['HealthCheckProtocol'] = module.params.get("health_check_protocol").upper()
|
params['HealthCheckProtocol'] = module.params.get("health_check_protocol").upper()
|
||||||
|
@ -419,9 +424,15 @@ def create_or_update_target_group(connection, module):
|
||||||
if module.params.get("unhealthy_threshold_count") is not None:
|
if module.params.get("unhealthy_threshold_count") is not None:
|
||||||
params['UnhealthyThresholdCount'] = module.params.get("unhealthy_threshold_count")
|
params['UnhealthyThresholdCount'] = module.params.get("unhealthy_threshold_count")
|
||||||
|
|
||||||
if module.params.get("successful_response_codes") is not None:
|
# Only need to check response code and path for http(s) health checks
|
||||||
params['Matcher'] = {}
|
if module.params.get("health_check_protocol") is not None and module.params.get("health_check_protocol").upper() != 'TCP':
|
||||||
params['Matcher']['HttpCode'] = module.params.get("successful_response_codes")
|
|
||||||
|
if module.params.get("health_check_path") is not None:
|
||||||
|
params['HealthCheckPath'] = module.params.get("health_check_path")
|
||||||
|
|
||||||
|
if module.params.get("successful_response_codes") is not None:
|
||||||
|
params['Matcher'] = {}
|
||||||
|
params['Matcher']['HttpCode'] = module.params.get("successful_response_codes")
|
||||||
|
|
||||||
# Get target type
|
# Get target type
|
||||||
if module.params.get("target_type") is not None:
|
if module.params.get("target_type") is not None:
|
||||||
|
@ -441,8 +452,9 @@ def create_or_update_target_group(connection, module):
|
||||||
# Target group exists so check health check parameters match what has been passed
|
# Target group exists so check health check parameters match what has been passed
|
||||||
health_check_params = dict()
|
health_check_params = dict()
|
||||||
|
|
||||||
# If we have no health check path then we have nothing to modify
|
# Modify health check if anything set
|
||||||
if module.params.get("health_check_path") is not None:
|
if health_options:
|
||||||
|
|
||||||
# Health check protocol
|
# Health check protocol
|
||||||
if 'HealthCheckProtocol' in params and tg['HealthCheckProtocol'] != params['HealthCheckProtocol']:
|
if 'HealthCheckProtocol' in params and tg['HealthCheckProtocol'] != params['HealthCheckProtocol']:
|
||||||
health_check_params['HealthCheckProtocol'] = params['HealthCheckProtocol']
|
health_check_params['HealthCheckProtocol'] = params['HealthCheckProtocol']
|
||||||
|
@ -451,10 +463,6 @@ def create_or_update_target_group(connection, module):
|
||||||
if 'HealthCheckPort' in params and tg['HealthCheckPort'] != params['HealthCheckPort']:
|
if 'HealthCheckPort' in params and tg['HealthCheckPort'] != params['HealthCheckPort']:
|
||||||
health_check_params['HealthCheckPort'] = params['HealthCheckPort']
|
health_check_params['HealthCheckPort'] = params['HealthCheckPort']
|
||||||
|
|
||||||
# Health check path
|
|
||||||
if 'HealthCheckPath'in params and tg['HealthCheckPath'] != params['HealthCheckPath']:
|
|
||||||
health_check_params['HealthCheckPath'] = params['HealthCheckPath']
|
|
||||||
|
|
||||||
# Health check interval
|
# Health check interval
|
||||||
if 'HealthCheckIntervalSeconds' in params and tg['HealthCheckIntervalSeconds'] != params['HealthCheckIntervalSeconds']:
|
if 'HealthCheckIntervalSeconds' in params and tg['HealthCheckIntervalSeconds'] != params['HealthCheckIntervalSeconds']:
|
||||||
health_check_params['HealthCheckIntervalSeconds'] = params['HealthCheckIntervalSeconds']
|
health_check_params['HealthCheckIntervalSeconds'] = params['HealthCheckIntervalSeconds']
|
||||||
|
@ -471,14 +479,20 @@ def create_or_update_target_group(connection, module):
|
||||||
if 'UnhealthyThresholdCount' in params and tg['UnhealthyThresholdCount'] != params['UnhealthyThresholdCount']:
|
if 'UnhealthyThresholdCount' in params and tg['UnhealthyThresholdCount'] != params['UnhealthyThresholdCount']:
|
||||||
health_check_params['UnhealthyThresholdCount'] = params['UnhealthyThresholdCount']
|
health_check_params['UnhealthyThresholdCount'] = params['UnhealthyThresholdCount']
|
||||||
|
|
||||||
# Matcher (successful response codes)
|
# Only need to check response code and path for http(s) health checks
|
||||||
# TODO: required and here?
|
if tg['HealthCheckProtocol'] != 'TCP':
|
||||||
if 'Matcher' in params:
|
# Health check path
|
||||||
current_matcher_list = tg['Matcher']['HttpCode'].split(',')
|
if 'HealthCheckPath'in params and tg['HealthCheckPath'] != params['HealthCheckPath']:
|
||||||
requested_matcher_list = params['Matcher']['HttpCode'].split(',')
|
health_check_params['HealthCheckPath'] = params['HealthCheckPath']
|
||||||
if set(current_matcher_list) != set(requested_matcher_list):
|
|
||||||
health_check_params['Matcher'] = {}
|
# Matcher (successful response codes)
|
||||||
health_check_params['Matcher']['HttpCode'] = ','.join(requested_matcher_list)
|
# TODO: required and here?
|
||||||
|
if 'Matcher' in params:
|
||||||
|
current_matcher_list = tg['Matcher']['HttpCode'].split(',')
|
||||||
|
requested_matcher_list = params['Matcher']['HttpCode'].split(',')
|
||||||
|
if set(current_matcher_list) != set(requested_matcher_list):
|
||||||
|
health_check_params['Matcher'] = {}
|
||||||
|
health_check_params['Matcher']['HttpCode'] = ','.join(requested_matcher_list)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if health_check_params:
|
if health_check_params:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue