summaryrefslogtreecommitdiffstats
path: root/ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml')
-rw-r--r--ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml35
1 files changed, 35 insertions, 0 deletions
diff --git a/ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml b/ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml
new file mode 100644
index 000000000..fd4c351b6
--- /dev/null
+++ b/ansible_collections/hetzner/hcloud/examples/use-refresh-inventory.yml
@@ -0,0 +1,35 @@
+---
+- name: Demonstrate the usage of 'refresh_inventory'
+ hosts: localhost
+ connection: local
+
+ tasks:
+ - name: Print hostvars
+ ansible.builtin.debug:
+ var: hostvars
+
+ - name: Create new server
+ hetzner.hcloud.server:
+ name: my-server
+ server_type: cx11
+ image: debian-12
+
+ - name: Refresh inventory
+ ansible.builtin.meta: refresh_inventory
+
+ - name: Run tests
+ block:
+ - name: Print updated inventory
+ ansible.builtin.debug:
+ var: hostvars
+
+ - name: Verify hostvars is not empty
+ ansible.builtin.assert:
+ that:
+ - hostvars != {}
+
+ always:
+ - name: Cleanup server
+ hetzner.hcloud.server:
+ name: my-server
+ state: absent