Commit graph

45 commits

Author SHA1 Message Date
Jonas L
fb8c2a9f58
chore: replace deprecated server type with cx22 (#510)
Learn more:
https://docs.hetzner.cloud/changelog#2024-06-06-old-server-types-with-shared-intel-vcpus-are-deprecated

- Updated docs with newer server types
- Use ARM server type for tests
2024-06-11 15:30:47 +02:00
Jonas L
a98cf72f92
fix(inventory): ensure host ipv6 variable is json serializable (#496)
##### SUMMARY

Fix https://github.com/ansible-collections/hetzner.hcloud/issues/495
Related to
https://github.com/ansible-collections/hetzner.hcloud/pull/477

##### ISSUE TYPE

- Bugfix Pull Request


##### COMPONENT NAME
inventory
2024-04-16 11:48:03 +02:00
Jonas L
4bb02b9cd2
refactor: remove unneeded to_native calls (#477)
##### SUMMARY

Since we only support python >=3.8, the `to_native` python2/3
compatibility function is not needed anymore. We only keep it for
printing a traceback free exception message. Where a type conversion is
needed, we use the built-in `str()` function.
2024-03-27 14:11:30 +01:00
Jonas L
be404ef181
feat(inventory): allow templating instances hostname (#455)
##### SUMMARY

Adds a `hostname` option that allow the user to pass a template to add a
prefix or use the hostvars to build the hostname.

For example:
```yml
plugin: hetzner.hcloud.hcloud

hostname: "hcloud-{{ location }}-{{ name }}"
```

OR with a hostvars_prefix:
```yml
plugin: hetzner.hcloud.hcloud

hostvars_prefix: hcloud_
hostname: "hcloud-{{ hcloud_location }}-{{ hcloud_name }}"
```

Fixes #115

##### ISSUE TYPE

- Feature Pull Request

##### COMPONENT NAME

inventory
2024-02-05 14:32:01 +01:00
Jonas L
d0c82aec86
feat!: remove inventory api_token_env option (#454)
##### SUMMARY

Remove the previously deprecated `api_token_env` to fully leverage the
ansible inventory options loader.

##### ISSUE TYPE

- Feature Pull Request


##### COMPONENT NAME

inventory
2024-02-05 12:18:39 +01:00
Jonas L
9495b9f25a
docs: improve hcloud inventory documentation (#434)
##### SUMMARY

- Re add some examples that were removed during a dep upgrade.
- Improve link to other reference (plugins/modules/options)
- Remove duplicate docs.
2023-12-21 17:49:24 +01:00
Jonas L
4e3f89aed3
feat: add hostvars_prefix and hostvars_suffix options to inventory hostvars (#423)
##### SUMMARY

Add `hostvars_prefix` and `hostvars_suffix` options to customize the
inventory host variables keys.

For example, with `hostvars_prefix: hcloud_ `, the host vars will be
stored as follows:
```json
{
    "_meta": {
        "hostvars": {
            "tmp": {
                "ansible_host": "65.109.169.27",
                "hcloud_architecture": "x86",
                "hcloud_datacenter": "hel1-dc2",
                "hcloud_id": 40573407,
                "hcloud_image_id": 114690387,
                "hcloud_image_name": "debian-12",
                "hcloud_image_os_flavor": "debian",
                "hcloud_ipv4": "65.109.169.27",
                "hcloud_ipv6_network_mask": "64",
                "hcloud_ipv6_network": "2a01:4f9:c012:4377::",
                "hcloud_ipv6": "2a01:4f9:c012:4377::1",
                "hcloud_labels": {},
                "hcloud_location": "hel1",
                "hcloud_name": "tmp",
                "hcloud_private_networks": [],
                "hcloud_server_type": "cx11",
                "hcloud_status": "running",
                "hcloud_type": "cx11"
            }
        }
    }
}
``` 

Related to #116
2023-12-15 15:40:37 +01:00
Jonas L
e4501c1086
refactor: reorder inventory server type host vars (#427)
Outlines the fact that `type` and `server_type` are the same value.
2023-12-15 15:25:12 +01:00
Jonas L
f85d8f4492
fix(inventory): improve performance (#402)
##### SUMMARY

Improve the performance of the inventory plugin by:
- Cache client requests
- Move servers `status` filtering to query params.
2023-11-24 13:43:34 +01:00
Jonas L
fb40a00689
refactor: extract client utils in reusable functions (#399)
##### SUMMARY



Extract some client utils functions in reusable function, to be used in
the inventory plugin.
2023-11-24 12:14:04 +01:00
Jonas L
df8c3b6a59
refactor: add future annotations imports (#398)
##### SUMMARY

This adds future annotations imports to benefit from the modern python
typing system.
2023-11-23 14:53:10 +01:00
Jonas L
9905bd0e01
feat(inventory): improve api options (#397)
##### SUMMARY

- Rename the inventory `token` option to `api_token`, use aliases for
backward compatibility.
- Rename the inventory `token_env` option to `api_token_env`, use
aliases for backward compatibility.
- Deprecate the inventory `api_token_env` option, suggest using a lookup
plugin (`{{ lookup('ansible.builtin.env', 'YOUR_ENV_VAR') }}`) or use
the well-known `HCLOUD_TOKEN` environment variable name.
- Let ansible parse the options, remove homemade options parsing.
- Improve and document the existing `api_endpoint` option.

##### ISSUE TYPE

- Feature Pull Request

##### COMPONENT NAME

hcloud inventory
2023-11-23 14:29:27 +01:00
Jonas L
2e82e0e6ef
docs: remove hcloud-python requirements from modules (#388)
##### SUMMARY

Since we vendored the hcloud-python library, those requirements are not
needed anymore.


##### ISSUE TYPE

- Docs Pull Request
2023-11-17 15:12:52 +01:00
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
Jonas L
6844317920
refactor: fix pylint invalid variable name (#312)
##### SUMMARY

Pylint complains about too short/meaningless variable names. We want to
be explicit when naming variables.
2023-08-25 16:19:15 +02:00
Jonas L
c56cbab1a0
refactor: use f-strings (#310)
##### SUMMARY

Replace string interpolation with f-strings. Improves readability, and
should help prevent #309
2023-08-24 11:27:40 +02:00
Jonas L
32b44647ef
feat: allow caching the hcloud inventory (#287)
* feat: allow caching the hcloud inventory

* chore: add changelog fragment
2023-08-16 11:59:17 +02:00
Jonas L
2d739edc88
feat: use collection version for the inventory user agent (#297) 2023-08-14 15:55:04 +02:00
Jonas L
64b6804b41
refactor: use relative imports for local modules (#279) 2023-07-31 10:12:55 +02:00
Jonas L
652a41df9d
fix!: don't set inventory image vars if server image is undefined (#275)
Related to #116

Don't set "No Image * found" string if the server image is not defined. This is not an intuitive behavior.

This is a breaking change.
2023-07-24 14:44:52 +02:00
Jonas L
8a6157e8b2
feat: vendor hcloud python dependency (#244)
* chore: ignore venv directories

* chore: ignore integration test generated inventory

* feat: vendor hcloud package

* import https://github.com/hetznercloud/hcloud-python

* use vendored hcloud in modules

* update integration test requirements

* make vendor script self contained

* chore: add  check-hcloud-vendor pre-commit hook

* pin hcloud version to v.1.24.0

* move vendored __version__.py file to _version.py

* update comment about galaxy-importer filename lint
2023-07-11 11:15:08 +02:00
Jonas L
0fcf4aad22
refactor: use new to_native function path (#238)
e535eb625b/lib/ansible/module_utils/_text.py
2023-06-27 13:17:21 +02:00
Jonas L
dfff49e31f
chore: setup pre-commit (#234)
* chore: add pre-commit config

* chore: fix pre-commit errors

* chore: add black pre-commit hook

* style: format python files with black

* chore: add isort pre-commit hook

* style: format python files using isort

* chore: add pyupgrade pre-commit hook

* refactor: upgrade code to python3.7

* Allow stacking PRs

Co-authored-by: Julian Tölle <julian.toelle97@gmail.com>

---------

Co-authored-by: Julian Tölle <julian.toelle97@gmail.com>
2023-06-27 11:50:13 +02:00
Julian Tölle
3c2d4df8bb
feat: add support for ARM APIs (#208)
* feat: add architecture fields for image & server type

* feat: filter images by architecture

* feat: select right image by arch on server create & rebuild

* feat(inventory): add architecture field to returned servers

* docs: add changelog for arm features

* chore: prepare v1.11.0
2023-04-12 10:43:19 +02:00
Julian Tölle
1863fe512c
feat(inventory): add variable for ipv6 address (#188)
This variable matches the `ansible_host` variable that we set when
`connect_with: public_ipv6`, and allows the user to dynamically choose the
connection method in `compose`.
2023-02-01 12:56:21 +01:00
Julian Tölle
bfe0f7a575
feat(inventory): handle servers that dont work with connect_with setting (#187)
Currently if any of the servers in the inventory do not work with the
selected `connect_with` mode, the script exits and returns 0 servers.
This can happen for example if one of your servers does not have a public
ipv4 address, but you set `connect_with: public_ipv4` (default).

This commit changes the behaviour to log a warning message, and just skip
setting `ansible_host` for this server. This server will not be reachable
by ansible by default, but users can use `compose` to override the
`ansible_host` that we set based on the other variables.
2023-02-01 10:41:36 +01:00
Julian Tölle
83094a121d
feat(inventory): add all private networks as variables (#186)
This can be used in the `compose`, `groups` and `keyed_groups` settings
to dynamically build the inventory.

It also makes it possible for the user to override the `ansible_host`
in `compose`, based on wether or not the server has a public ipv4 address,
with fallback to the address in a specific private network.
2023-01-31 17:09:54 +01:00
n00b42
ccfa51bf66
feat: Pass extra vars to templating of api_token. (#156)
Co-authored-by: Maximilian Senftleben <maximilian.senftleben@frogblue-tec.com>
2023-01-30 12:08:09 +01:00
Julian Tölle
b5f205485a
feat(inventory): connect via public ipv6 address (#176)
Add a new `connect_with` option `public_ipv6` that uses the first
address from the servers publically-routed ipv6 network.
2022-12-21 11:10:58 +01:00
Lukas Kämmerling
d1c97c7e89
Inventory Plugin: Add support for changing the name of the top level group all servers are added to (#164)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
2022-11-08 09:01:14 +01:00
Lukas Kämmerling
0965f79093
Add support for Primary IPs (#141)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
2022-06-29 09:58:01 +02:00
Tagir Bakirov
38d3aa6c51
add server status as an option to filter the server inventory list (#126)
* add status as an option to filter the server list

* Update plugins/inventory/hcloud.py

fix the sanity check

Co-authored-by: Lukas Kämmerling <github@lukas-kaemmerling.de>

Co-authored-by: Tagir Bakirov <tagir.bakirov@reservix.de>
Co-authored-by: Lukas Kämmerling <github@lukas-kaemmerling.de>
2022-06-13 08:57:16 +02:00
Andrew Klychkov
181949d165
Sanity tests: copy ignore-2.13.txt to ignore-2.14.txt (#125)
* Sanity tests: copy ignore-2.13.txt to ignore-2.14.txt

* Fix sanity
2022-04-22 09:35:17 +02:00
Lukas Kämmerling
51865c29ab
inventory - support jinjia templating within network (#107)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
2021-08-25 10:57:03 +02:00
Lukas Kämmerling
5d6b5b7c3f
Add full collection name as option to inventory plugin (#90)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
2021-05-27 08:14:13 +02:00
Lukas Kämmerling
45af6f150c
Fix inventory: server type had the wrong value (#78) 2021-04-14 09:57:35 +02:00
Tobias Fischer
a393f4e862
expand template instructions in 'token' property (#49)
fixes #48
2021-04-07 08:17:03 +02:00
John R Barker
0d955cab88
AZP fixes (#52)
* Tidy up files
* Add Sanity ignore files
* Use master as branch name instead of main
* Use targets in integration jobs
* Remove tests/sanity/requirements.txt (not used by ansible-test)
* sanity: prevent import exception for inventory script

Co-authored-by: David Moreau Simard <moi@dmsimard.com>
2021-02-22 16:25:44 -05:00
Lukas Kämmerling
ff359431a1
Restore Python 2.7 support (#45)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
2020-12-07 08:30:50 +01:00
Robert Kaussow
0d8a8bf7f3
add token_env option to load token from custom env variable (#43)
Co-authored-by: Lukas Kämmerling <github@lukas-kaemmerling.de>
2020-12-01 08:39:08 +01:00
Lukas Kämmerling
0617bc65f8
Add hcloud_load_balancer_info module (#41)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
2020-11-27 12:25:06 +01:00
Lukas Kämmerling
8bb449d3de
Improve imports of APIException (#37)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
2020-11-24 06:39:21 +01:00
Torben Hørup
11af14289a
document private_ipv4 connect_with option (#24) 2020-08-31 12:50:12 +02:00
Lukas Kämmerling
41354355e6
Fix inventory plugin does not work with old configuration files (#15) 2020-06-30 13:48:24 +02:00
Ansible Core Team
36309bd27a Initial commit 2020-03-09 13:36:01 +00:00