Created ansible files to create server with initial sane defaults

This commit is contained in:
2023-07-31 20:32:29 +02:00
parent 6cf9154d85
commit 9bb574b95e
8 changed files with 48 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
localhost ansible_python_interpreter=/usr/bin/python3
@@ -0,0 +1,6 @@
---
hcloud_api_token: someAPIToken
admin_user: nameForNewAdminUser
ssh_key_admin_user: publicKeyForNewAdminUser
ssh_key_admin_user_name: nameForSSHKeyForNewAdminUser
server_name: nameOfTheNewServer
@@ -0,0 +1,6 @@
---
basic_firewall: basic-firewall
server_image: ubuntu-22.04
server_location: fsn1
server_placement_group: default
server_type: cax11
@@ -0,0 +1,22 @@
---
- name: create SSH key
hetzner.hcloud.hcloud_ssh_key:
api_token: "{{ hcloud_api_token }}"
public_key: "{{ ssh_key_admin_user }}"
name: "{{ ssh_key_admin_user_name }}"
state: present
- name: create server via HCloud
hetzner.hcloud.hcloud_server:
api_token: "{{ hcloud_api_token }}"
firewalls:
- "{{ basic_firewall }}"
image: "{{ server_image }}"
location: "{{ server_location }}"
name: "{{ server_name }}"
placement_group: "{{ server_placement_group }}"
server_type: "{{ server_type }}"
ssh_keys:
- "{{ ssh_key_admin_user_name }}"
user_data: "{{ lookup('ansible.builtin.template', 'basic-ssh-hardening.yaml.j2', convert_data=false) }}"
state: present
register: server
@@ -0,0 +1,2 @@
---
- import_tasks: create-server.yaml
@@ -1,11 +1,11 @@
#cloud-config
users:
- name: holu
- name: {{ admin_user }}
groups: users, admin
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
ssh_authorized_keys:
- <public_ssh_key>
- {{ ssh_key_admin_user }}
packages:
- fail2ban
- ufw
@@ -23,5 +23,5 @@ runcmd:
- sed -i -e '/^\(#\|\)AllowTcpForwarding/s/^.*$/AllowTcpForwarding no/' /etc/ssh/sshd_config
- sed -i -e '/^\(#\|\)AllowAgentForwarding/s/^.*$/AllowAgentForwarding no/' /etc/ssh/sshd_config
- sed -i -e '/^\(#\|\)AuthorizedKeysFile/s/^.*$/AuthorizedKeysFile .ssh\/authorized_keys/' /etc/ssh/sshd_config
- sed -i '$a AllowUsers holu' /etc/ssh/sshd_config
- sed -i '$a AllowUsers {{ admin_user }}' /etc/ssh/sshd_config
- reboot
+6
View File
@@ -0,0 +1,6 @@
---
- name: Create server
hosts: localhost
connection: local
roles:
- server-setup
+2
View File
@@ -0,0 +1,2 @@
---
- include: setup.yaml