mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
docs
This commit is contained in:
parent
396e7f83bc
commit
4635c787b3
5 changed files with 235 additions and 99 deletions
|
|
@ -162,7 +162,8 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
self.hcloud_load_balancer = None
|
||||
|
||||
def _prepare_result(self):
|
||||
private_ipv4_address = None if len(self.hcloud_load_balancer.private_net) == 0 else to_native(self.hcloud_load_balancer.private_net[0].ip)
|
||||
private_ipv4_address = None if len(self.hcloud_load_balancer.private_net) == 0 else to_native(
|
||||
self.hcloud_load_balancer.private_net[0].ip)
|
||||
return {
|
||||
"id": to_native(self.hcloud_load_balancer.id),
|
||||
"name": to_native(self.hcloud_load_balancer.name),
|
||||
|
|
@ -211,7 +212,7 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
)
|
||||
elif self.module.params.get("location") is None and self.module.params.get("network_zone") is not None:
|
||||
params["network_zone"] = self.module.params.get("network_zone")
|
||||
|
||||
|
||||
if not self.module.check_mode:
|
||||
resp = self.client.load_balancers.create(**params)
|
||||
resp.action.wait_until_finished(max_retries=1000)
|
||||
|
|
@ -274,9 +275,9 @@ class AnsibleHcloudLoadBalancer(Hcloud):
|
|||
load_balancer_type={"type": "str"},
|
||||
location={"type": "str"},
|
||||
network_zone={"type": "str"},
|
||||
volumes={"type": "list"},
|
||||
labels={"type": "dict"},
|
||||
delete_protection={"type": "bool"},
|
||||
disable_public_interface={"type": "bool", "default": False},
|
||||
state={
|
||||
"choices": ["absent", "present"],
|
||||
"default": "present",
|
||||
|
|
|
|||
|
|
@ -8,12 +8,6 @@ from __future__ import absolute_import, division, print_function
|
|||
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
"metadata_version": "1.1",
|
||||
"status": ["preview"],
|
||||
"supported_by": "community",
|
||||
}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: hcloud_load_balancer_network
|
||||
|
|
@ -50,7 +44,7 @@ options:
|
|||
type: str
|
||||
|
||||
requirements:
|
||||
- hcloud-python >= 1.9.0
|
||||
- hcloud-python >= 1.8.1
|
||||
|
||||
extends_documentation_fragment:
|
||||
- hetzner.hcloud.hcloud
|
||||
|
|
@ -116,7 +110,7 @@ class AnsibleHcloudLoadBalancerNetwork(Hcloud):
|
|||
def __init__(self, module):
|
||||
super(AnsibleHcloudLoadBalancerNetwork, self).__init__(module, "hcloud_load_balancer_network")
|
||||
self.hcloud_network = None
|
||||
self.hcloud_load_balancer= None
|
||||
self.hcloud_load_balancer = None
|
||||
self.hcloud_load_balancer_network = None
|
||||
|
||||
def _prepare_result(self):
|
||||
|
|
@ -129,7 +123,7 @@ class AnsibleHcloudLoadBalancerNetwork(Hcloud):
|
|||
def _get_load_balancer_and_network(self):
|
||||
try:
|
||||
self.hcloud_network = self.client.networks.get_by_name(self.module.params.get("network"))
|
||||
self.hcloud_load_balancer= self.client.load_balancers.get_by_name(self.module.params.get("load_balancer"))
|
||||
self.hcloud_load_balancer = self.client.load_balancers.get_by_name(self.module.params.get("load_balancer"))
|
||||
self.hcloud_load_balancer_network = None
|
||||
except APIException as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
|
|
@ -168,7 +162,8 @@ class AnsibleHcloudLoadBalancerNetwork(Hcloud):
|
|||
self._get_load_balancer_network()
|
||||
if self.hcloud_load_balancer_network is not None and self.hcloud_load_balancer is not None:
|
||||
if not self.module.check_mode:
|
||||
self.hcloud_load_balancer.detach_from_network(self.hcloud_load_balancer_network.network).wait_until_finished()
|
||||
self.hcloud_load_balancer.detach_from_network(
|
||||
self.hcloud_load_balancer_network.network).wait_until_finished()
|
||||
self._mark_as_changed()
|
||||
self.hcloud_load_balancer_network = None
|
||||
|
||||
|
|
|
|||
|
|
@ -24,40 +24,91 @@ author:
|
|||
options:
|
||||
load_balancer:
|
||||
description:
|
||||
- The ID of the Hetzner Cloud Load Balancer to manage.
|
||||
- The Name of the Hetzner Cloud Load Balancer the service belongs to
|
||||
type: int
|
||||
listen_port:
|
||||
description:
|
||||
- The Name of the Hetzner Cloud Load Balancer to manage.
|
||||
type: str
|
||||
load_balancer_type:
|
||||
- The port the service listens on, i.e. the port users can connect to.
|
||||
type: int
|
||||
destination_port:
|
||||
description:
|
||||
- The Load Balancer Type of the Hetzner Cloud Load Balancer to manage.
|
||||
- The port traffic is forwarded to, i.e. the port the targets are listening and accepting connections on.
|
||||
- Required if services does not exists and protocol == tcp.
|
||||
type: int
|
||||
protocol:
|
||||
description:
|
||||
- Protocol of the service.
|
||||
- Required if Load Balancer does not exists.
|
||||
type: str
|
||||
location:
|
||||
description:
|
||||
- Location of Load Balancer.
|
||||
- Required if no I(network_zone) is given and Load Balancer does not exists.
|
||||
type: str
|
||||
network_zone:
|
||||
description:
|
||||
- Network Zone of Load Balancer.
|
||||
- Required of no I(location) is given and Load Balancer does not exists.
|
||||
type: str
|
||||
labels:
|
||||
description:
|
||||
- User-defined labels (key-value pairs).
|
||||
choices: [ http, https, tcp]
|
||||
proxyprotocol:
|
||||
description:
|
||||
- Enable the PROXY protocol.
|
||||
- Please note that the software running on the targets and handling connections needs to support the PROXY protocol.
|
||||
type: bool
|
||||
http:
|
||||
description: Configuration for HTTP and HTTPS services
|
||||
type: dict
|
||||
disable_public_interface:
|
||||
description:
|
||||
- Disables the public interface.
|
||||
type: bool
|
||||
default: False
|
||||
delete_protection:
|
||||
description:
|
||||
- Protect the Load Balancer for deletion.
|
||||
type: bool
|
||||
options:
|
||||
cookie_name:
|
||||
description: Name of the cookie which will be set when you enable sticky sessions
|
||||
type: str
|
||||
cookie_lifetime:
|
||||
description: Lifetime of the cookie which will be set when you enable sticky sessions, in seconds
|
||||
type: int
|
||||
certificates:
|
||||
description: List of Names or IDs of certificates
|
||||
type: list
|
||||
sticky_sessions:
|
||||
description: Enable or disable sticky_sessions
|
||||
type: bool
|
||||
redirect_http:
|
||||
description: Redirect Traffic from Port 80 to Port 443, only available if protocol is https
|
||||
type: bool
|
||||
health_check:
|
||||
description: Configuration for health checks
|
||||
type: dict
|
||||
options:
|
||||
protocol:
|
||||
description: Protocol the health checks will be performed over
|
||||
type: str
|
||||
choices: [ http, https, tcp ]
|
||||
port:
|
||||
description: Port the health check will be performed on
|
||||
type: int
|
||||
interval:
|
||||
description: Interval of health checks, in seconds
|
||||
type: int
|
||||
timeout:
|
||||
description: Timeout of health checks, in seconds
|
||||
type: int
|
||||
retries:
|
||||
description: Number of retries until a target is marked as unhealthy
|
||||
type: int
|
||||
http:
|
||||
description: Additional Configuration of health checks with protocol http/https
|
||||
type: dict
|
||||
options:
|
||||
domain:
|
||||
description: Domain we will set within the HTTP HOST header
|
||||
returned: always
|
||||
type: str
|
||||
sample: example.com
|
||||
path:
|
||||
description: Path we will try to access
|
||||
returned: always
|
||||
type: str
|
||||
sample: /
|
||||
response:
|
||||
description: Response we expect, if response is not within the health check response the target is unhealthy
|
||||
type: str
|
||||
status_codes:
|
||||
description: List of HTTP status codes we expect to get when we perform the health check.
|
||||
type: list
|
||||
elements: str
|
||||
tls:
|
||||
description: Verify the TLS certificate, only available if health check protocol is https
|
||||
type: bool
|
||||
state:
|
||||
description:
|
||||
- State of the Load Balancer.
|
||||
|
|
@ -68,79 +119,152 @@ extends_documentation_fragment:
|
|||
- hetzner.hcloud.hcloud
|
||||
|
||||
requirements:
|
||||
- hcloud-python >= 1.8.0
|
||||
- hcloud-python >= 1.8.1
|
||||
'''
|
||||
|
||||
EXAMPLES = """
|
||||
- name: Create a basic Load Balancer
|
||||
- name: Create a basic Load Balancer service with Port 80
|
||||
hcloud_load_balancer_service:
|
||||
name: my-Load Balancer
|
||||
load_balancer_type: lb11
|
||||
location: fsn1
|
||||
load_balancer: my-load-balancer
|
||||
protocol: http
|
||||
listen_port: 80
|
||||
state: present
|
||||
|
||||
- name: Ensure the Load Balancer is absent (remove if needed)
|
||||
hcloud_load_balancer_service:
|
||||
name: my-Load Balancer
|
||||
protocol: http
|
||||
listen_port: 80
|
||||
state: absent
|
||||
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
hcloud_load_balancer_service:
|
||||
description: The Load Balancer instance
|
||||
description: The Load Balancer service instance
|
||||
returned: Always
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description: Numeric identifier of the Load Balancer
|
||||
load_balancer:
|
||||
description: The name of the Load Balancer where the service belongs to
|
||||
returned: always
|
||||
type: string
|
||||
sample: my-load-balancer
|
||||
listen_port:
|
||||
description: The port the service listens on, i.e. the port users can connect to.
|
||||
returned: always
|
||||
type: int
|
||||
sample: 1937415
|
||||
name:
|
||||
description: Name of the Load Balancer
|
||||
sample: 443
|
||||
protocol:
|
||||
description: Protocol of the service
|
||||
returned: always
|
||||
type: str
|
||||
sample: my-Load-Balancer
|
||||
status:
|
||||
description: Status of the Load Balancer
|
||||
sample: http
|
||||
choices: [ http, https, tcp ]
|
||||
destination_port:
|
||||
description: The port traffic is forwarded to, i.e. the port the targets are listening and accepting connections on.
|
||||
returned: always
|
||||
type: str
|
||||
sample: running
|
||||
load_balancer_type:
|
||||
description: Name of the Load Balancer type of the Load Balancer
|
||||
type: int
|
||||
sample: 80
|
||||
proxyprotocol:
|
||||
description:
|
||||
- Enable the PROXY protocol.
|
||||
- Please note that the software running on the targets and handling connections needs to support the PROXY protocol.
|
||||
returned: always
|
||||
type: str
|
||||
sample: cx11
|
||||
ipv4_address:
|
||||
description: Public IPv4 address of the Load Balancer
|
||||
returned: always
|
||||
type: str
|
||||
sample: 116.203.104.109
|
||||
ipv6_address:
|
||||
description: Public IPv6 address of the Load Balancer
|
||||
returned: always
|
||||
type: str
|
||||
sample: 2a01:4f8:1c1c:c140::1
|
||||
location:
|
||||
description: Name of the location of the Load Balancer
|
||||
returned: always
|
||||
type: str
|
||||
sample: fsn1
|
||||
labels:
|
||||
description: User-defined labels (key-value pairs)
|
||||
returned: always
|
||||
type: dict
|
||||
delete_protection:
|
||||
description: True if Load Balancer is protected for deletion
|
||||
type: bool
|
||||
returned: always
|
||||
sample: false
|
||||
disable_public_interface:
|
||||
description: True if Load Balancer public interface is disabled
|
||||
type: bool
|
||||
http:
|
||||
description: Configuration for HTTP and HTTPS services
|
||||
returned: always
|
||||
sample: false
|
||||
type: complex
|
||||
contains:
|
||||
cookie_name:
|
||||
description: Name of the cookie which will be set when you enable sticky sessions
|
||||
returned: always
|
||||
type: str
|
||||
sample: HCLBSTICKY
|
||||
cookie_lifetime:
|
||||
description: Lifetime of the cookie which will be set when you enable sticky sessions, in seconds
|
||||
returned: always
|
||||
type: int
|
||||
sample: 3600
|
||||
certificates:
|
||||
description: List of Names or IDs of certificates
|
||||
returned: always
|
||||
type: list
|
||||
elements: str
|
||||
sticky_sessions:
|
||||
description: Enable or disable sticky_sessions
|
||||
returned: always
|
||||
type: bool
|
||||
sample: true
|
||||
redirect_http:
|
||||
description: Redirect Traffic from Port 80 to Port 443, only available if protocol is https
|
||||
returned: always
|
||||
type: bool
|
||||
sample: false
|
||||
health_check:
|
||||
description: Configuration for health checks
|
||||
returned: always
|
||||
type: complex
|
||||
contains:
|
||||
protocol:
|
||||
description: Protocol the health checks will be performed over
|
||||
returned: always
|
||||
type: str
|
||||
sample: http
|
||||
choices: [ http, https, tcp ]
|
||||
port:
|
||||
description: Port the health check will be performed on
|
||||
returned: always
|
||||
type: int
|
||||
sample: 80
|
||||
interval:
|
||||
description: Interval of health checks, in seconds
|
||||
returned: always
|
||||
type: int
|
||||
sample: 15
|
||||
timeout:
|
||||
description: Timeout of health checks, in seconds
|
||||
returned: always
|
||||
type: int
|
||||
sample: 10
|
||||
retries:
|
||||
description: Number of retries until a target is marked as unhealthy
|
||||
returned: always
|
||||
type: int
|
||||
sample: 3
|
||||
http:
|
||||
description: Additional Configuration of health checks with protocol http/https
|
||||
returned: always
|
||||
type: complex
|
||||
contains:
|
||||
domain:
|
||||
description: Domain we will set within the HTTP HOST header
|
||||
returned: always
|
||||
type: str
|
||||
sample: example.com
|
||||
path:
|
||||
description: Path we will try to access
|
||||
returned: always
|
||||
type: str
|
||||
sample: /
|
||||
response:
|
||||
description: Response we expect, if response is not within the health check response the target is unhealthy
|
||||
returned: always
|
||||
type: str
|
||||
sample: "{\"status\": \"ok\"}"
|
||||
status_codes:
|
||||
description: List of HTTP status codes we expect to get when we perform the health check.
|
||||
returned: always
|
||||
type: list
|
||||
elements: str
|
||||
sample: ["2??","3??"]
|
||||
tls:
|
||||
description: Verify the TLS certificate, only available if health check protocol is https
|
||||
returned: always
|
||||
type: bool
|
||||
sample: false
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
|
@ -162,12 +286,40 @@ class AnsibleHcloudLoadBalancerService(Hcloud):
|
|||
self.hcloud_load_balancer_service = None
|
||||
|
||||
def _prepare_result(self):
|
||||
http = None
|
||||
if self.hcloud_load_balancer_service.protocol != "tcp":
|
||||
http = {
|
||||
"cookie_name": to_native(self.hcloud_load_balancer_service.http.cookie_name),
|
||||
"cookie_lifetime": self.hcloud_load_balancer_service.http.cookie_name,
|
||||
"redirect_http": self.hcloud_load_balancer_service.http.redirect_http,
|
||||
"sticky_sessions": self.hcloud_load_balancer_service.http.sticky_sessions,
|
||||
"certificates": [to_native(certificate.name) for certificate in
|
||||
self.hcloud_load_balancer_service.http.certificates],
|
||||
}
|
||||
health_check = {
|
||||
"protocol": to_native(self.hcloud_load_balancer_service.health_check.protocol),
|
||||
"port": self.hcloud_load_balancer_service.health_check.port,
|
||||
"interval": self.hcloud_load_balancer_service.health_check.interval,
|
||||
"timeout": self.hcloud_load_balancer_service.health_check.timeout,
|
||||
"retries": self.hcloud_load_balancer_service.health_check.retries,
|
||||
}
|
||||
if self.hcloud_load_balancer_service.health_check.protocol != "tcp":
|
||||
health_check["http"] = {
|
||||
"domain": to_native(self.hcloud_load_balancer_service.health_check.http.domain),
|
||||
"path": to_native(self.hcloud_load_balancer_service.health_check.http.path),
|
||||
"response": to_native(self.hcloud_load_balancer_service.health_check.http.response),
|
||||
"certificates": [to_native(status_code) for status_code in
|
||||
self.hcloud_load_balancer_service.health_check.http.status_codes],
|
||||
"tls": self.hcloud_load_balancer_service.health_check.tls,
|
||||
}
|
||||
return {
|
||||
"load_balancer": to_native(self.hcloud_load_balancer.name),
|
||||
"protocol": to_native(self.hcloud_load_balancer_service.protocol),
|
||||
"listen_port": self.hcloud_load_balancer_service.listen_port,
|
||||
"destination_port": self.hcloud_load_balancer_service.destination_port,
|
||||
"proxyprotocol": self.hcloud_load_balancer_service.proxyprotocol,
|
||||
"http": http,
|
||||
"health_check": health_check,
|
||||
}
|
||||
|
||||
def _get_load_balancer(self):
|
||||
|
|
|
|||
|
|
@ -8,12 +8,6 @@ from __future__ import absolute_import, division, print_function
|
|||
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
"metadata_version": "1.1",
|
||||
"status": ["preview"],
|
||||
"supported_by": "community",
|
||||
}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: hcloud_load_balancer_target
|
||||
|
|
@ -57,7 +51,7 @@ options:
|
|||
type: str
|
||||
|
||||
requirements:
|
||||
- hcloud-python >= 1.9.0
|
||||
- hcloud-python >= 1.8.1
|
||||
|
||||
extends_documentation_fragment:
|
||||
- hetzner.hcloud.hcloud
|
||||
|
|
|
|||
|
|
@ -8,12 +8,6 @@ from __future__ import absolute_import, division, print_function
|
|||
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {
|
||||
"metadata_version": "1.1",
|
||||
"status": ["preview"],
|
||||
"supported_by": "community",
|
||||
}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: hcloud_load_balancer_type_info
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue