From 1c84cd30e8b8b5e05e4eda48d74efd0da05cbd02 Mon Sep 17 00:00:00 2001 From: "Jonas L." Date: Fri, 12 Dec 2025 12:56:02 +0100 Subject: [PATCH] docs: add example with cloud-init user-data and custom host ssh keys (#770) ##### SUMMARY Document how to user user data with cloud-init, and configure custom host ssh keys. --- examples/server-with-user_data.yml | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/server-with-user_data.yml diff --git a/examples/server-with-user_data.yml b/examples/server-with-user_data.yml new file mode 100644 index 0000000..cbce98c --- /dev/null +++ b/examples/server-with-user_data.yml @@ -0,0 +1,40 @@ +--- +- name: Demonstrate the usage of 'user_data' + hosts: localhost + connection: local + + tasks: + - name: Create host ssh keys + community.crypto.openssh_keypair: + path: "ssh_host_{{ item }}_key" + type: "{{ item }}" + loop: [ed25519, ecdsa, rsa] + register: host_ssh_keys + + - name: Print host ssh keys fingerprint + ansible.builtin.debug: + msg: "{{ item.fingerprint }}" + loop: "{{ host_ssh_keys.results }}" + loop_control: + label: "{{ item.type }}" + + - name: Create server + hetzner.hcloud.server: + name: my-server + server_type: cx23 + image: debian-13 + user_data: | + #cloud-config + ssh_deletekeys: true + ssh_keys: + ed25519_private: | + {{ lookup('file', 'ssh_host_ed25519_key') | indent(4) }} + ed25519_public: "{{ lookup('file', 'ssh_host_ed25519_key.pub') }}" + + ecdsa_private: | + {{ lookup('file', 'ssh_host_ecdsa_key') | indent(4) }} + ecdsa_public: "{{ lookup('file', 'ssh_host_ecdsa_key.pub') }}" + + rsa_private: | + {{ lookup('file', 'ssh_host_rsa_key') | indent(4) }} + rsa_public: "{{ lookup('file', 'ssh_host_rsa_key.pub') }}"