mirror of
https://github.com/2martens/cloud-configuration.git
synced 2026-10-18 09:06:51 +02:00
Created ansible files to create server with initial sane defaults
This commit is contained in:
@@ -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
|
||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
#cloud-config
|
#cloud-config
|
||||||
users:
|
users:
|
||||||
- name: holu
|
- name: {{ admin_user }}
|
||||||
groups: users, admin
|
groups: users, admin
|
||||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
- <public_ssh_key>
|
- {{ ssh_key_admin_user }}
|
||||||
packages:
|
packages:
|
||||||
- fail2ban
|
- fail2ban
|
||||||
- ufw
|
- ufw
|
||||||
@@ -23,5 +23,5 @@ runcmd:
|
|||||||
- sed -i -e '/^\(#\|\)AllowTcpForwarding/s/^.*$/AllowTcpForwarding no/' /etc/ssh/sshd_config
|
- 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 '/^\(#\|\)AllowAgentForwarding/s/^.*$/AllowAgentForwarding no/' /etc/ssh/sshd_config
|
||||||
- sed -i -e '/^\(#\|\)AuthorizedKeysFile/s/^.*$/AuthorizedKeysFile .ssh\/authorized_keys/' /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
|
- reboot
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Create server
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
roles:
|
||||||
|
- server-setup
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
- include: setup.yaml
|
||||||
Reference in New Issue
Block a user