ansible-collection-hetzner-.../plugins/modules/hcloud_primary_ip_info.py
renovate[bot] 3058995219
deps: update pre-commit hook ansible/ansible-lint to v6.21.0 (#365)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [ansible/ansible-lint](https://togithub.com/ansible/ansible-lint) |
repository | minor | `v6.20.3` -> `v6.21.0` |

Note: The `pre-commit` manager in Renovate is not supported by the
`pre-commit` maintainers or community. Please do not report any problems
there, instead [create a Discussion in the Renovate
repository](https://togithub.com/renovatebot/renovate/discussions/new)
if you have any questions.

---

### Release Notes

<details>
<summary>ansible/ansible-lint (ansible/ansible-lint)</summary>

###
[`v6.21.0`](https://togithub.com/ansible/ansible-lint/releases/tag/v6.21.0)

[Compare
Source](https://togithub.com/ansible/ansible-lint/compare/v6.20.3...v6.21.0)

#### Minor Changes

- Allow linting plugin EXAMPLES as playbooks
([#&#8203;3309](https://togithub.com/ansible/ansible-lint/issues/3309))
[@&#8203;Qalthos](https://togithub.com/Qalthos)

#### Bugfixes

- Add support for Rocky
([#&#8203;3843](https://togithub.com/ansible/ansible-lint/issues/3843))
[@&#8203;facorazza](https://togithub.com/facorazza)
- Update supported Ubuntu versions in `meta.json`
([#&#8203;3845](https://togithub.com/ansible/ansible-lint/issues/3845))
[@&#8203;mcdonnnj](https://togithub.com/mcdonnnj)
- Avoid false positives for handler in roles handlers directory
([#&#8203;3838](https://togithub.com/ansible/ansible-lint/issues/3838))
[@&#8203;ajinkyau](https://togithub.com/ajinkyau)
- Hide stacktrace when loading invalid yaml
([#&#8203;3844](https://togithub.com/ansible/ansible-lint/issues/3844))
[@&#8203;ajinkyau](https://togithub.com/ajinkyau)
- Add some platforms to `meta.json`
([#&#8203;3841](https://togithub.com/ansible/ansible-lint/issues/3841))
[@&#8203;mcdonnnj](https://togithub.com/mcdonnnj)
- Temporary avoid auto-fixing YAML files not owned by ansible
([#&#8203;3837](https://togithub.com/ansible/ansible-lint/issues/3837))
[@&#8203;ssbarnea](https://togithub.com/ssbarnea)
- Add environment variable for skipping schema update
([#&#8203;3835](https://togithub.com/ansible/ansible-lint/issues/3835))
[@&#8203;ajinkyau](https://togithub.com/ajinkyau)
- Avoid creating temporary YAML files inside source tree
([#&#8203;3819](https://togithub.com/ansible/ansible-lint/issues/3819))
[@&#8203;Qalthos](https://togithub.com/Qalthos)
- Document environment variables
([#&#8203;3833](https://togithub.com/ansible/ansible-lint/issues/3833))
[@&#8203;ssbarnea](https://togithub.com/ssbarnea)
- Update schemas
([#&#8203;3832](https://togithub.com/ansible/ansible-lint/issues/3832))
[@&#8203;ssbarnea](https://togithub.com/ssbarnea)
- Support complex requirements in argument_specs.yml
([#&#8203;3823](https://togithub.com/ansible/ansible-lint/issues/3823))
[@&#8203;tapetersen](https://togithub.com/tapetersen)
- Fix SARIF-formatter severity levels
([#&#8203;3824](https://togithub.com/ansible/ansible-lint/issues/3824))
[@&#8203;4ch1m](https://togithub.com/4ch1m)
- Add play level autofix for key-order rule
([#&#8203;3815](https://togithub.com/ansible/ansible-lint/issues/3815))
[@&#8203;ajinkyau](https://togithub.com/ajinkyau)
- Add support for python 3.12
([#&#8203;3813](https://togithub.com/ansible/ansible-lint/issues/3813))
[@&#8203;ssbarnea](https://togithub.com/ssbarnea)
- Update SPDX license list
([#&#8203;3814](https://togithub.com/ansible/ansible-lint/issues/3814))
[@&#8203;ssbarnea](https://togithub.com/ssbarnea)
- Use checkout action in install docs
([#&#8203;3810](https://togithub.com/ansible/ansible-lint/issues/3810))
[@&#8203;gma](https://togithub.com/gma)
- Fix actions-tagger arguments
([#&#8203;3808](https://togithub.com/ansible/ansible-lint/issues/3808))
[@&#8203;ssbarnea](https://togithub.com/ssbarnea)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ansible-collections/hetzner.hcloud).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xOS4yIiwidXBkYXRlZEluVmVyIjoiMzcuMTkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: jo <ljonas@riseup.net>
2023-10-19 12:41:44 +02:00

203 lines
6.3 KiB
Python

#!/usr/bin/python
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
DOCUMENTATION = """
---
module: hcloud_primary_ip_info
short_description: Gather infos about the Hetzner Cloud Primary IPs.
description:
- Gather facts about your Hetzner Cloud Primary IPs.
author:
- Lukas Kaemmerling (@LKaemmerling)
- Kevin Castner (@kcastner)
options:
id:
description:
- The ID of the Primary IP you want to get.
- The module will fail if the provided ID is invalid.
type: int
name:
description:
- The name for the Primary IP you want to get.
type: str
label_selector:
description:
- The label selector for the Primary IP you want to get.
type: str
extends_documentation_fragment:
- hetzner.hcloud.hcloud
"""
EXAMPLES = """
- name: Gather hcloud Primary IP infos
hetzner.hcloud.hcloud_primary_ip_info:
register: output
- name: Gather hcloud Primary IP infos by id
hetzner.hcloud.hcloud_primary_ip_info:
id: 673954
register: output
- name: Gather hcloud Primary IP infos by name
hetzner.hcloud.hcloud_primary_ip_info:
name: srv1-v4
register: output
- name: Gather hcloud Primary IP infos by label
hetzner.hcloud.hcloud_primary_ip_info:
label_selector: srv03-ips
register: output
- name: Print the gathered infos
debug:
var: output
"""
RETURN = """
hcloud_primary_ip_info:
description: The Primary IP infos as list
returned: always
type: complex
contains:
id:
description: Numeric identifier of the Primary IP
returned: always
type: int
sample: 1937415
name:
description: Name of the Primary IP
returned: always
type: str
sample: my-primary-ip
ip:
description: IP address of the Primary IP
returned: always
type: str
sample: 131.232.99.1
type:
description: Type of the Primary IP
returned: always
type: str
sample: ipv4
assignee_id:
description: Numeric identifier of the ressource where the Primary IP is assigned to.
returned: always
type: int
sample: 19584637
assignee_type:
description: Name of the type where the Primary IP is assigned to.
returned: always
type: str
sample: server
home_location:
description: Location with datacenter where the Primary IP was created in
returned: always
type: str
sample: fsn1-dc1
dns_ptr:
description: Shows the DNS PTR Record for Primary IP.
returned: always
type: str
sample: srv01.example.com
labels:
description: User-defined labels (key-value pairs)
returned: always
type: dict
delete_protection:
description: True if the Primary IP is protected for deletion
returned: always
type: bool
"""
from typing import List, Optional
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from ..module_utils.hcloud import AnsibleHCloud
from ..module_utils.vendor.hcloud import HCloudException
from ..module_utils.vendor.hcloud.primary_ips import BoundPrimaryIP
class AnsibleHCloudPrimaryIPInfo(AnsibleHCloud):
represent = "hcloud_primary_ip_info"
hcloud_primary_ip_info: Optional[List[BoundPrimaryIP]] = None
def _prepare_result(self):
tmp = []
for primary_ip in self.hcloud_primary_ip_info:
if primary_ip is not None:
dns_ptr = None
if len(primary_ip.dns_ptr) > 0:
dns_ptr = primary_ip.dns_ptr[0]["dns_ptr"]
tmp.append(
{
"id": to_native(primary_ip.id),
"name": to_native(primary_ip.name),
"ip": to_native(primary_ip.ip),
"type": to_native(primary_ip.type),
"assignee_id": (
to_native(primary_ip.assignee_id) if primary_ip.assignee_id is not None else None
),
"assignee_type": to_native(primary_ip.assignee_type),
"home_location": to_native(primary_ip.datacenter.name),
"dns_ptr": to_native(dns_ptr) if dns_ptr is not None else None,
"labels": primary_ip.labels,
"delete_protection": primary_ip.protection["delete"],
}
)
return tmp
def get_primary_ips(self):
try:
if self.module.params.get("id") is not None:
self.hcloud_primary_ip_info = [self.client.primary_ips.get_by_id(self.module.params.get("id"))]
elif self.module.params.get("name") is not None:
self.hcloud_primary_ip_info = [self.client.primary_ips.get_by_name(self.module.params.get("name"))]
elif self.module.params.get("label_selector") is not None:
self.hcloud_primary_ip_info = self.client.primary_ips.get_all(
label_selector=self.module.params.get("label_selector")
)
else:
self.hcloud_primary_ip_info = self.client.primary_ips.get_all()
except HCloudException as exception:
self.fail_json_hcloud(exception)
@classmethod
def define_module(cls):
return AnsibleModule(
argument_spec=dict(
id={"type": "int"},
label_selector={"type": "str"},
name={"type": "str"},
**super().base_module_arguments()
),
supports_check_mode=True,
)
def main():
module = AnsibleHCloudPrimaryIPInfo.define_module()
hcloud = AnsibleHCloudPrimaryIPInfo(module)
hcloud.get_primary_ips()
result = hcloud.get_result()
ansible_info = {"hcloud_primary_ip_info": result["hcloud_primary_ip_info"]}
module.exit_json(**ansible_info)
if __name__ == "__main__":
main()