mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Bug fixes for gcp_compute_http_health_check (#42812)
This commit is contained in:
parent
1db54dd6a1
commit
60e78f33ce
2 changed files with 74 additions and 75 deletions
|
@ -32,8 +32,8 @@ DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: gcp_compute_http_health_check
|
module: gcp_compute_http_health_check
|
||||||
description:
|
description:
|
||||||
- An HttpHealthCheck resource. This resource defines a template for how
|
- An HttpHealthCheck resource. This resource defines a template for how individual
|
||||||
individual VMs should be checked for health, via HTTP.
|
VMs should be checked for health, via HTTP.
|
||||||
short_description: Creates a GCP HttpHealthCheck
|
short_description: Creates a GCP HttpHealthCheck
|
||||||
version_added: 2.6
|
version_added: 2.6
|
||||||
author: Google Inc. (@googlecloudplatform)
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
@ -45,40 +45,38 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Whether the given object should exist in GCP
|
- Whether the given object should exist in GCP
|
||||||
required: true
|
|
||||||
choices: ['present', 'absent']
|
choices: ['present', 'absent']
|
||||||
default: 'present'
|
default: 'present'
|
||||||
check_interval_sec:
|
check_interval_sec:
|
||||||
description:
|
description:
|
||||||
- How often (in seconds) to send a health check. The default value
|
- How often (in seconds) to send a health check. The default value is 5 seconds.
|
||||||
is 5 seconds.
|
|
||||||
required: false
|
required: false
|
||||||
|
default: 5
|
||||||
aliases: [check_interval_seconds]
|
aliases: [check_interval_seconds]
|
||||||
description:
|
description:
|
||||||
description:
|
description:
|
||||||
- An optional description of this resource. Provide this property
|
- An optional description of this resource. Provide this property when you create
|
||||||
when you create the resource.
|
the resource.
|
||||||
required: false
|
required: false
|
||||||
healthy_threshold:
|
healthy_threshold:
|
||||||
description:
|
description:
|
||||||
- A so-far unhealthy instance will be marked healthy after this many
|
- A so-far unhealthy instance will be marked healthy after this many consecutive successes.
|
||||||
consecutive successes. The default value is 2.
|
The default value is 2.
|
||||||
required: false
|
required: false
|
||||||
host:
|
host:
|
||||||
description:
|
description:
|
||||||
- The value of the host header in the HTTP health check request. If
|
- The value of the host header in the HTTP health check request. If left empty (default
|
||||||
left empty (default value), the public IP on behalf of which this
|
value), the public IP on behalf of which this health check is performed will be
|
||||||
health check is performed will be used.
|
used.
|
||||||
required: false
|
required: false
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of the resource. Provided by the client when the resource is
|
- Name of the resource. Provided by the client when the resource is created. The name
|
||||||
created. The name must be 1-63 characters long, and comply with
|
must be 1-63 characters long, and comply with RFC1035. Specifically, the name must
|
||||||
RFC1035. Specifically, the name must be 1-63 characters long and
|
be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which
|
which means the first character must be a lowercase letter, and all following characters
|
||||||
means the first character must be a lowercase letter, and all
|
must be a dash, lowercase letter, or digit, except the last character, which cannot
|
||||||
following characters must be a dash, lowercase letter, or digit,
|
be a dash.
|
||||||
except the last character, which cannot be a dash.
|
|
||||||
required: true
|
required: true
|
||||||
port:
|
port:
|
||||||
description:
|
description:
|
||||||
|
@ -93,39 +91,39 @@ options:
|
||||||
timeout_sec:
|
timeout_sec:
|
||||||
description:
|
description:
|
||||||
- How long (in seconds) to wait before claiming failure.
|
- How long (in seconds) to wait before claiming failure.
|
||||||
- The default value is 5 seconds. It is invalid for timeoutSec to
|
- The default value is 5 seconds. It is invalid for timeoutSec to have greater value
|
||||||
have greater value than checkIntervalSec.
|
than checkIntervalSec.
|
||||||
required: false
|
required: false
|
||||||
aliases: [timeout_seconds]
|
aliases: [timeout_seconds]
|
||||||
unhealthy_threshold:
|
unhealthy_threshold:
|
||||||
description:
|
description:
|
||||||
- A so-far healthy instance will be marked unhealthy after this many
|
- A so-far healthy instance will be marked unhealthy after this many consecutive failures.
|
||||||
consecutive failures. The default value is 2.
|
The default value is 2.
|
||||||
required: false
|
required: false
|
||||||
extends_documentation_fragment: gcp
|
extends_documentation_fragment: gcp
|
||||||
|
notes:
|
||||||
|
- "API Reference: U(https://cloud.google.com/compute/docs/reference/latest/httpHealthChecks)"
|
||||||
|
- "Adding Health Checks: U(https://cloud.google.com/compute/docs/load-balancing/health-checks#legacy_health_checks)"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: create a http health check
|
- name: create a http health check
|
||||||
gcp_compute_http_health_check:
|
gcp_compute_http_health_check:
|
||||||
name: testObject
|
name: "test_object"
|
||||||
healthy_threshold: 10
|
healthy_threshold: 10
|
||||||
port: 8080
|
port: 8080
|
||||||
timeout_sec: 2
|
timeout_sec: 2
|
||||||
unhealthy_threshold: 5
|
unhealthy_threshold: 5
|
||||||
project: testProject
|
project: "test_project"
|
||||||
auth_kind: service_account
|
auth_kind: "service_account"
|
||||||
service_account_file: /tmp/auth.pem
|
service_account_file: "/tmp/auth.pem"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
check_interval_sec:
|
check_interval_sec:
|
||||||
description:
|
description:
|
||||||
- How often (in seconds) to send a health check. The default value
|
- How often (in seconds) to send a health check. The default value is 5 seconds.
|
||||||
is 5 seconds.
|
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
creation_timestamp:
|
creation_timestamp:
|
||||||
|
@ -135,38 +133,36 @@ RETURN = '''
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
description:
|
description:
|
||||||
- An optional description of this resource. Provide this property
|
- An optional description of this resource. Provide this property when you create
|
||||||
when you create the resource.
|
the resource.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
healthy_threshold:
|
healthy_threshold:
|
||||||
description:
|
description:
|
||||||
- A so-far unhealthy instance will be marked healthy after this many
|
- A so-far unhealthy instance will be marked healthy after this many consecutive successes.
|
||||||
consecutive successes. The default value is 2.
|
The default value is 2.
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
host:
|
host:
|
||||||
description:
|
description:
|
||||||
- The value of the host header in the HTTP health check request. If
|
- The value of the host header in the HTTP health check request. If left empty (default
|
||||||
left empty (default value), the public IP on behalf of which this
|
value), the public IP on behalf of which this health check is performed will be
|
||||||
health check is performed will be used.
|
used.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
id:
|
id:
|
||||||
description:
|
description:
|
||||||
- The unique identifier for the resource. This identifier is defined
|
- The unique identifier for the resource. This identifier is defined by the server.
|
||||||
by the server.
|
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of the resource. Provided by the client when the resource is
|
- Name of the resource. Provided by the client when the resource is created. The name
|
||||||
created. The name must be 1-63 characters long, and comply with
|
must be 1-63 characters long, and comply with RFC1035. Specifically, the name must
|
||||||
RFC1035. Specifically, the name must be 1-63 characters long and
|
be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which
|
which means the first character must be a lowercase letter, and all following characters
|
||||||
means the first character must be a lowercase letter, and all
|
must be a dash, lowercase letter, or digit, except the last character, which cannot
|
||||||
following characters must be a dash, lowercase letter, or digit,
|
be a dash.
|
||||||
except the last character, which cannot be a dash.
|
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
port:
|
port:
|
||||||
|
@ -184,14 +180,14 @@ RETURN = '''
|
||||||
timeout_sec:
|
timeout_sec:
|
||||||
description:
|
description:
|
||||||
- How long (in seconds) to wait before claiming failure.
|
- How long (in seconds) to wait before claiming failure.
|
||||||
- The default value is 5 seconds. It is invalid for timeoutSec to
|
- The default value is 5 seconds. It is invalid for timeoutSec to have greater value
|
||||||
have greater value than checkIntervalSec.
|
than checkIntervalSec.
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
unhealthy_threshold:
|
unhealthy_threshold:
|
||||||
description:
|
description:
|
||||||
- A so-far healthy instance will be marked unhealthy after this many
|
- A so-far healthy instance will be marked unhealthy after this many consecutive failures.
|
||||||
consecutive failures. The default value is 2.
|
The default value is 2.
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
'''
|
'''
|
||||||
|
@ -215,7 +211,7 @@ def main():
|
||||||
module = GcpModule(
|
module = GcpModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
check_interval_sec=dict(type='int', aliases=['check_interval_seconds']),
|
check_interval_sec=dict(default=5, type='int', aliases=['check_interval_seconds']),
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
healthy_threshold=dict(type='int'),
|
healthy_threshold=dict(type='int'),
|
||||||
host=dict(type='str'),
|
host=dict(type='str'),
|
||||||
|
@ -227,6 +223,9 @@ def main():
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
kind = 'compute#httpHealthCheck'
|
kind = 'compute#httpHealthCheck'
|
||||||
|
|
||||||
|
@ -236,10 +235,10 @@ def main():
|
||||||
if fetch:
|
if fetch:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if is_different(module, fetch):
|
if is_different(module, fetch):
|
||||||
fetch = update(module, self_link(module), kind, fetch)
|
fetch = update(module, self_link(module), kind)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
delete(module, self_link(module), kind, fetch)
|
delete(module, self_link(module), kind)
|
||||||
fetch = {}
|
fetch = {}
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
|
@ -259,12 +258,12 @@ def create(module, link, kind):
|
||||||
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
def delete(module, link, kind, fetch):
|
def delete(module, link, kind):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
return wait_for_operation(module, auth.delete(link))
|
return wait_for_operation(module, auth.delete(link))
|
||||||
|
|
||||||
|
@ -374,7 +373,7 @@ def async_op_url(module, extra_data=None):
|
||||||
def wait_for_operation(module, response):
|
def wait_for_operation(module, response):
|
||||||
op_result = return_if_object(module, response, 'compute#operation')
|
op_result = return_if_object(module, response, 'compute#operation')
|
||||||
if op_result is None:
|
if op_result is None:
|
||||||
return None
|
return {}
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
wait_done = wait_for_completion(status, op_result, module)
|
wait_done = wait_for_completion(status, op_result, module)
|
||||||
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#httpHealthCheck')
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#httpHealthCheck')
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
- name: create a http health check
|
- name: create a http health check
|
||||||
|
@ -37,8 +35,6 @@
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is true
|
- name: assert changed is true
|
||||||
|
@ -47,13 +43,19 @@
|
||||||
- result.changed == true
|
- result.changed == true
|
||||||
- "result.kind == 'compute#httpHealthCheck'"
|
- "result.kind == 'compute#httpHealthCheck'"
|
||||||
- name: verify that http_health_check was created
|
- name: verify that http_health_check was created
|
||||||
shell: |
|
gcp_compute_http_health_check_facts:
|
||||||
gcloud compute http-health-checks describe --project="{{gcp_project}}" "{{ resource_name }}"
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
register: results
|
register: results
|
||||||
- name: verify that command succeeded
|
- name: verify that command succeeded
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- results.rc == 0
|
- results['items'] | length == 1
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
- name: create a http health check that already exists
|
- name: create a http health check that already exists
|
||||||
gcp_compute_http_health_check:
|
gcp_compute_http_health_check:
|
||||||
|
@ -65,8 +67,6 @@
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
@ -85,8 +85,6 @@
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is true
|
- name: assert changed is true
|
||||||
|
@ -95,15 +93,19 @@
|
||||||
- result.changed == true
|
- result.changed == true
|
||||||
- result.has_key('kind') == False
|
- result.has_key('kind') == False
|
||||||
- name: verify that http_health_check was deleted
|
- name: verify that http_health_check was deleted
|
||||||
shell: |
|
gcp_compute_http_health_check_facts:
|
||||||
gcloud compute http-health-checks describe --project="{{gcp_project}}" "{{ resource_name }}"
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
register: results
|
register: results
|
||||||
failed_when: results.rc == 0
|
|
||||||
- name: verify that command succeeded
|
- name: verify that command succeeded
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- results.rc == 1
|
- results['items'] | length == 0
|
||||||
- "\"'projects/{{ gcp_project }}/global/httpHealthChecks/{{ resource_name }}' was not found\" in results.stderr"
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
- name: delete a http health check that does not exist
|
- name: delete a http health check that does not exist
|
||||||
gcp_compute_http_health_check:
|
gcp_compute_http_health_check:
|
||||||
|
@ -115,8 +117,6 @@
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
|
Loading…
Reference in a new issue