Last active
January 28, 2022 14:50
-
-
Save b-reich/29bebb78e8b9543505b2718ef7112111 to your computer and use it in GitHub Desktop.
Hetzner Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Create a Server | |
hosts: localhost | |
connection: local | |
gather_facts: False | |
user: root | |
vars: | |
hcloud_token: xxxx | |
tasks: | |
- name: Create a basic server | |
hcloud_server: | |
api_token: "{{ hcloud_token }}" | |
name: my-server | |
server_type: cx11 | |
image: debian-10 | |
state: present | |
ssh_keys: | |
- Benjamin | |
register: server | |
- name: Print IP | |
debug: | |
msg: "{{ server.hcloud_server.ipv4_address }}" | |
- name: Add new instance to host group | |
add_host: | |
hostname: "{{ server.hcloud_server.ipv4_address }}" | |
groupname: launched | |
- name: Configure instance(s) | |
hosts: launched | |
gather_facts: False | |
vars: | |
ansible_user: root | |
tasks: | |
- name: Wait 60 seconds | |
wait_for_connection: | |
timeout: 60 | |
- name: upgrade hosts | |
apt: | |
update_cache: True | |
upgrade: True | |
- name: install utilities | |
apt: | |
name: | |
- htop | |
- gpg | |
- sudo | |
state: present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Create a Server and a Volume with server | |
hosts: localhost | |
connection: local | |
gather_facts: True | |
user: root | |
vars: | |
hcloud_token: xxx | |
tasks: | |
- name: Create a basic server | |
hcloud_server: | |
api_token: "{{ hcloud_token }}" | |
name: "{{ item }}" | |
server_type: cx11 | |
image: debian-10 | |
state: present | |
ssh_keys: | |
- Benjamin | |
register: server | |
with_items: | |
- "worker1-{{ansible_date_time.date}}" | |
- "worker2-{{ansible_date_time.date}}" | |
- "worker3-{{ansible_date_time.date}}" | |
- name: Print IP | |
debug: | |
msg: "{{ item.hcloud_server.ipv4_address }}" | |
loop: "{{ server.results }}" | |
- name: Add new instance to host group | |
add_host: | |
hostname: "{{ item.hcloud_server.ipv4_address }}" | |
groupname: launched | |
loop: "{{ server.results }}" | |
- name: Configure instance(s) | |
hosts: launched | |
gather_facts: False | |
vars: | |
ansible_user: root | |
tasks: | |
- name: Wait 60 seconds | |
wait_for_connection: | |
timeout: 60 | |
- name: upgrade hosts | |
apt: | |
update_cache: True | |
upgrade: True | |
- name: install utilities | |
apt: | |
name: | |
- htop | |
- gpg | |
- sudo | |
state: present |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment