From 6581ed50db8fd7a3e7525cb364acd63fec256c3a Mon Sep 17 00:00:00 2001 From: Jonas L Date: Thu, 23 Nov 2023 14:16:05 +0100 Subject: [PATCH] feat: add `hetzner.hcloud.all` action group (#396) ##### SUMMARY This allows to use `module_defaults` against all the modules at once using the new `hetzner.hcloud.all` `action_group`. You can now pass the `api_token` argument using module_defaults: ```yaml - name: Demonstrate the usage of the 'hetzner.hcloud.all' module_defaults group hosts: localhost connection: local module_defaults: group/hetzner.hcloud.all: api_token: "{{ _vault_hcloud_api_token }}" tasks: - name: Create a volume hetzner.hcloud.volume: name: my-volume location: fsn1 size: 100 state: present register: volume ``` See the documentation and examples for more details. ##### ISSUE TYPE - Feature Pull Request --- .ansible-lint | 3 ++ ...-module-defaults-group-for-all-modules.yml | 2 ++ docs/docsite/rst/authentification.rst | 22 ++++++++++++ examples/use-module-defaults-group.yml | 27 +++++++++++++++ meta/runtime.yml | 34 +++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 changelogs/fragments/add-module-defaults-group-for-all-modules.yml create mode 100644 examples/use-module-defaults-group.yml diff --git a/.ansible-lint b/.ansible-lint index 4b03f62..5062e31 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -21,3 +21,6 @@ exclude_paths: - tests/integration/targets/volume - tests/integration/targets/setup_selfsigned_certificate - tests/integration/targets/setup_ssh_keypair + +warn_list: + - internal-error diff --git a/changelogs/fragments/add-module-defaults-group-for-all-modules.yml b/changelogs/fragments/add-module-defaults-group-for-all-modules.yml new file mode 100644 index 0000000..167ba12 --- /dev/null +++ b/changelogs/fragments/add-module-defaults-group-for-all-modules.yml @@ -0,0 +1,2 @@ +minor_changes: + - Add the `hetzner.hcloud.all` group to configure all the modules using `module_defaults`. diff --git a/docs/docsite/rst/authentification.rst b/docs/docsite/rst/authentification.rst index 366170f..ca0f10e 100644 --- a/docs/docsite/rst/authentification.rst +++ b/docs/docsite/rst/authentification.rst @@ -24,3 +24,25 @@ Alternatively, you may provide the API token directly as module argument: server_type: cx11 image: debian-12 state: present + +To reduce the duplication of the above solution, you may configure the +``hetzner.hcloud.*`` modules using the ``hetzner.hcloud.all`` action group, for +example if you want to store your API token in a vault: + +.. code-block:: yaml + + - name: Demonstrate the usage of the 'hetzner.hcloud.all' module_defaults group + hosts: localhost + connection: local + + module_defaults: + group/hetzner.hcloud.all: + api_token: "{{ _vault_hcloud_api_token }}" + + tasks: + - name: Create server + hetzner.hcloud.server: + name: my-server + server_type: cx11 + image: debian-12 + state: present diff --git a/examples/use-module-defaults-group.yml b/examples/use-module-defaults-group.yml new file mode 100644 index 0000000..f3de9ad --- /dev/null +++ b/examples/use-module-defaults-group.yml @@ -0,0 +1,27 @@ +--- +- name: Demonstrate the usage of the 'hetzner.hcloud.all' module_defaults group + hosts: localhost + connection: local + + module_defaults: + group/hetzner.hcloud.all: + api_token: LRK9DAWQ1ZAEFSrCNEEzLCUwhYX1U3g7wMg4dTlkkDC96fyDuyJ39nVbVjCKSDfj + + tasks: + - name: Create a volume + hetzner.hcloud.volume: + name: my-volume + location: fsn1 + size: 100 + state: present + register: volume + + - name: Create a server + hetzner.hcloud.server: + name: my-server + server_type: cx11 + image: debian-12 + location: fsn1 + volumes: + - "{{ volume.hcloud_volume.id }}" + state: present diff --git a/meta/runtime.yml b/meta/runtime.yml index 94ea738..fc99a12 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,5 +1,39 @@ requires_ansible: ">=2.13.0" +action_groups: + all: + - certificate + - certificate_info + - datacenter_info + - firewall + - floating_ip + - floating_ip_info + - image_info + - iso_info + - load_balancer + - load_balancer_info + - load_balancer_network + - load_balancer_service + - load_balancer_target + - load_balancer_type_info + - location_info + - network + - network_info + - placement_group + - primary_ip + - primary_ip_info + - rdns + - route + - server + - server_info + - server_network + - server_type_info + - ssh_key + - ssh_key_info + - subnetwork + - volume + - volume_info + plugin_routing: modules: hcloud_certificate_info: