Git initial commit

This commit is contained in:
lhahn committed 2023-08-20 10:30:25 +02:00
commit 368b8f1444
24 files changed
+789

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
---
- name: setup Cloud Control script
template:
src: "templates{{ cloud_control_path }}/cloud-control.j2"
dest: "{{ cloud_control_path }}/{{ cloud_control_name }}"
owner: root
group: root
mode: 0754
+30
View File
@@ -0,0 +1,30 @@
---
- name: install fail2ban service
apt:
update_cache: yes
state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}"
install_recommends: yes
pkg: fail2ban
- name: setup fail2ban config jail.local
template:
backup: yes
src: "templates{{ fail2ban_jail_conf }}.j2"
dest: "{{ fail2ban_jail_conf }}"
owner: root
group: root
mode: 0644
notify: restart fail2ban service
- name: Install fail2ban filter plugins nginx
template:
src: "templates{{ fail2ban_path }}/filter.d/{{ filter }}.local.j2"
dest: "{{ fail2ban_path }}/filter.d/{{ filter }}.local"
owner: root
group: root
mode: 0644
loop: "{{ fail2ban_nginx_filter }}"
loop_control:
label: "{{ filter }}"
loop_var: filter
notify: restart fail2ban service
Executable
+64
View File
@@ -0,0 +1,64 @@
---
- name: Limit access to cloude home only for root
file:
state: directory
path: "{{ cloud_home }}"
owner: root
group: root
mode: 0700
recurse: yes
- name: Install basic apps via apt
apt:
update_cache: yes
autoclean: yes
autoremove: yes
state: latest
install_recommends: yes
pkg: "{{ basis_apps }}"
- name: set timezone
timezone:
name: "{{ cloud_tzdata }}"
- name: Setup hahn-cloud users
import_tasks: users.yml
- name: Setup and configure sshd service
import_tasks: sshd.yml
- name: Setup and configure fail2ban service
import_tasks: fail2ban.yml
- name: Setup and configure cloud control script
import_tasks: cloud_control.yml
- name: Setup mount points
import_tasks: mount.yml
- name: Setup swap
import_tasks: swap.yml
when: swap_on
- name: Setup basic cloud folders for apps and storage
file:
state: directory
path: "{{ item }}"
mode: 0755
owner: root
group: "{{ shared_group }}"
loop:
- "{{ cloud_apps }}"
- "{{ cloud_storage }}"
- name: Setup shared python environment for all cloud users
file:
state: directory
path: "{{ cloud_python_envs }}"
mode: 0755
owner: root
group: "{{ shared_group }}"
- name: Setup wireguard vpn
import_tasks: wireguard.yml
when: wireguard_enabled
+20
View File
@@ -0,0 +1,20 @@
- name: generate filesystem on mounts if not defined
filesystem:
fstype: "{{ mnt.fstype | default('ext4') }}"
dev: "{{ mnt.dev }}"
loop: "{{ mount_points }}"
loop_control:
loop_var: mnt
label: "{{ mnt.dev }}: {{ mnt.fstype | default('ext4') }}"
- name: mount required points
mount:
path: "{{ mnt.path }}"
src: "{{ mnt.dev }}"
state: "{{ mnt.state | default('mounted') }}"
fstype: "{{ mnt.fstype | default('ext4') }}"
opts: "{{ mnt.opts | default('defaults') }}"
loop: "{{ mount_points }}"
loop_control:
loop_var: mnt
label: "{{ mnt.dev }}: {{ mnt.path }}"
Executable
+21
View File
@@ -0,0 +1,21 @@
---
- name: install OpenSSH server
apt:
update_cache: yes
state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}"
install_recommends: yes
pkg: openssh-server
- name: setup sshd_config
lineinfile:
path: "{{ sshd_conf }}"
regexp: '^#?{{ configline.split(" ")[0] }}{% if configline.split(" ") | length > 1 %} {% endif %}'
line: "{{ configline }}"
owner: root
group: root
mode: 0644
loop: "{{ ssh_configs }}"
loop_control:
loop_var: configline
label: "{{ configline }}"
notify: restart sshd service
Executable
+35
View File
@@ -0,0 +1,35 @@
---
- name: generate file for swapping
command:
cmd: "dd if=/dev/zero of={{ swap_file }} bs={{ swap_block_size }} count={{ swap_block_count }}"
chdir: "/"
creates: "{{ swap_file }}"
register: swapfile_setup
- name: prepare swap file
command:
cmd: "mkswap {{ swap_file }}"
chdir: "/"
when: swapfile_setup.changed
register: swapfile_creation
- name: set swap permission
file:
path: "{{ swap_file }}"
mode: 0600
- name: activate swap
command:
cmd: "swapon {{ swap_file }}"
chdir: "/"
when: swapfile_creation.changed
- name: mount swap on boot
mount:
path: none
src: "{{ swap_file }}"
fstype: swap
opts: sw
passno: 0
dump: 0
state: present
+47
View File
@@ -0,0 +1,47 @@
---
- name: list active users
shell: cat /etc/passwd | grep -v "nologin" | cut -f 1 -d ":"
changed_when: false
register: active_users
- name: Setup required groups of users
group:
name: "{{ group }}"
state: present
loop: "{{ ((users | json_query('[*].groups') | flatten) + default_groups) | unique }}"
loop_control:
loop_var: group
label: "{{ group }}"
- name: Setup users
user:
name: "{{ user.name }}"
state: "{{ user.state }}"
comment: "{{ user.displayname }}"
group: "{{ user.name }}"
groups: "{{ default_groups | default([]) + user.groups }}"
append: yes
shell: "{{ user.shell }}"
loop: "{{ users }}"
loop_control:
loop_var: user
label: "{{ user.name }}"
register: new_user_setup
- name: Setup User ssh_key
authorized_key:
user: "{{ user.name }}"
state: "{{ user.state | default('present') }}"
key: "{{ user.ssh_key }}"
loop: "{{ users | selectattr('ssh_key', 'defined') | list }}"
loop_control:
label: "{{ user.name }}"
loop_var: user
- name: Activate password setup for newly created users
shell: " set -e pipefail; passwd -d {{ user }}; chage -d0 {{ user }}"
loop: "{{ new_user_setup | json_query('results[?changed==`true`].name') | difference(active_users.stdout_lines) }}"
loop_control:
label: "{{ user }}"
loop_var: user
when: new_user_setup.changed
+34
View File
@@ -0,0 +1,34 @@
---
- name: install fail2ban service
apt:
update_cache: yes
state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}"
install_recommends: yes
pkg: wireguard
register: wireguard_installed
- name: setup key files
template:
src: "etc/wireguard/{{ item }}.j2"
dest: "/etc/wireguard/{{ item }}"
owner: root
mode: 0600
loop:
- private.key
- public.key
notify: restart wireguard service
- name: setup wireguard config
template:
src: "etc/wireguard/wireguard-{% if wireguard_is_gateway %}server{% else %}client{% endif %}.conf.j2"
dest: "/etc/wireguard/{{ cloud_name }}.conf"
owner: root
mode: 0600
notify: restart wireguard service
- name: enable wireguard systemd unit
systemd:
name: wg-quick@{{ cloud_name }}
enabled: yes
daemon_reload: yes
state: started