Basic playbook
This commit is contained in:
commit
a9ee6d691b
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Hetzner Playbooks
|
||||
|
||||
This playbooks use [the hetzner cloud ansible collection](https://docs.ansible.com/ansible/latest/collections/hetzner/hcloud/index.html) to create and manage Hetzner VMs.
|
||||
|
||||
## hetzner_basic.yml
|
||||
This playbook uses an [hetzner API key](https://docs.hetzner.com/cloud/api/getting-started/generating-api-token/) to create a simple cx11 server named "Squi". The server is located in Falkenstein and is configured using cloud-config. The goal is to have a simple example playbook.
|
||||
|
||||
The API key is encrypted using ansible-vault. Such an encrypted string can be obtained via:
|
||||
```
|
||||
ansible-vault encrypt_string "My_string"
|
||||
```
|
||||
|
||||
It can then simply be launched with:
|
||||
```
|
||||
ansible-playbook --ask-vault-pass hetzner_basic.yml
|
||||
```
|
||||
|
72
hetzner_basic.yml
Executable file
72
hetzner_basic.yml
Executable file
@ -0,0 +1,72 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
gather_facts: False
|
||||
become: True
|
||||
|
||||
vars:
|
||||
sshkey: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBNyMTbcbTDZ7RJQtet7R6RrJogk9sDEAfO6+j5RGFL0 justine@squi.fr
|
||||
apikey: !vault |
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
39303466366266326464646639663763306161373035646231643535613436616138306261623861
|
||||
3266326437343531653666633065353230663831333237380a643661376239333631613536363133
|
||||
35363531393161323463353162386430313566363132663732623563633838383036333266376635
|
||||
6639663565336162630a343362633164383064663532343732393264306133656638326639623137
|
||||
38626563363631376231623163376638323762363836653434363332396162636133
|
||||
|
||||
tasks:
|
||||
#SHOW INFO
|
||||
- name: Gather hcloud image infos
|
||||
hcloud_image_info:
|
||||
api_token: "{{ apikey }}"
|
||||
register: output
|
||||
|
||||
- name: dbg
|
||||
debug:
|
||||
var: output
|
||||
|
||||
- name: Gather hcloud location infos
|
||||
hcloud_location_info:
|
||||
api_token: "{{ apikey }}"
|
||||
register: output
|
||||
|
||||
- name: dbg
|
||||
debug:
|
||||
var: output
|
||||
|
||||
#SSH KEY MANAGEMENT
|
||||
- name: Create my ssh key
|
||||
hcloud_ssh_key:
|
||||
api_token: "{{ apikey }}"
|
||||
name: justine@squi.fr
|
||||
public_key: "{{ sshkey }}"
|
||||
state: present
|
||||
|
||||
#CREATE SERVER
|
||||
- name: Create a server
|
||||
hcloud_server:
|
||||
api_token: "{{ apikey }}"
|
||||
name: squi
|
||||
server_type: cx11
|
||||
image: debian-11
|
||||
location: fsn1
|
||||
state: started
|
||||
ssh_keys: ["justine@squi.fr"]
|
||||
user_data: |
|
||||
#cloud-config
|
||||
packages:
|
||||
- zsh
|
||||
- vim
|
||||
- fail2ban
|
||||
package_update: true
|
||||
package_upgrade: true
|
||||
|
||||
|
||||
- name: Gather server infos
|
||||
hcloud_server_info:
|
||||
api_token: "{{ apikey }}"
|
||||
register: outp
|
||||
|
||||
- name: Show
|
||||
debug:
|
||||
var: outp
|
Loading…
x
Reference in New Issue
Block a user