testing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
packages:
|
||||
common_packages:
|
||||
- dnsutils
|
||||
- ncdu
|
||||
- tree
|
||||
- vim
|
||||
|
30
roles/common/tasks/debian.yml
Normal file
30
roles/common/tasks/debian.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
- name: Install useful software
|
||||
ansible.builtin.apt:
|
||||
name: "{{ common_packages }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Install the Uncomplicated Firewall
|
||||
ansible.builtin.apt:
|
||||
name: ufw
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Deny incoming traffic by default
|
||||
community.general.ufw:
|
||||
default: deny
|
||||
direction: incoming
|
||||
|
||||
- name: Allow outgoing traffic by default
|
||||
community.general.ufw:
|
||||
default: allow
|
||||
direction: outgoing
|
||||
|
||||
- name: Allow OpenSSH with rate limiting
|
||||
community.general.ufw:
|
||||
name: ssh
|
||||
rule: limit
|
||||
|
||||
- name: Enable firewall
|
||||
community.general.ufw:
|
||||
state: enabled
|
@@ -2,35 +2,38 @@
|
||||
ansible.builtin.file:
|
||||
path: "~/.ansible/tmp"
|
||||
state: directory
|
||||
mode: 0700
|
||||
mode: "700"
|
||||
|
||||
- name: Install useful software
|
||||
ansible.builtin.apt:
|
||||
name: "{{ packages }}"
|
||||
- name: Create system user groups
|
||||
ansible.builtin.group:
|
||||
name: "{{ item.key }}"
|
||||
gid: "{{ item.value.gid }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
loop: "{{ users | dict2items }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
when: users is defined
|
||||
|
||||
- name: Install the Uncomplicated Firewall
|
||||
ansible.builtin.apt:
|
||||
name: ufw
|
||||
- name: Create system users
|
||||
ansible.builtin.user:
|
||||
name: "{{ item.key }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
uid: "{{ item.value.uid }}"
|
||||
group: "{{ item.value.gid }}"
|
||||
groups: "{{ item.value.groups | default([]) }}"
|
||||
shell: "{{ item.value.shell | default('/bin/bash') }}"
|
||||
create_home: "{{ item.value.home | default(false) }}"
|
||||
home: "{{ item.value.homedir | default('/home/' + item.key) }}"
|
||||
system: "{{ item.value.system | default(false) }}"
|
||||
loop: "{{ users | dict2items }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
when: users is defined
|
||||
|
||||
- name: Deny incoming traffic by default
|
||||
community.general.ufw:
|
||||
default: deny
|
||||
direction: incoming
|
||||
- name: Include Debian-specific tasks
|
||||
ansible.builtin.include_tasks: debian.yml
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- name: Allow outgoing traffic by default
|
||||
community.general.ufw:
|
||||
default: allow
|
||||
direction: outgoing
|
||||
|
||||
- name: Allow OpenSSH with rate limiting
|
||||
community.general.ufw:
|
||||
name: ssh
|
||||
rule: limit
|
||||
|
||||
- name: Enable firewall
|
||||
community.general.ufw:
|
||||
state: enabled
|
||||
- name: Include Rocky Linux-specific tasks
|
||||
ansible.builtin.include_tasks: rocky.yml
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
42
roles/common/tasks/rocky.yml
Normal file
42
roles/common/tasks/rocky.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
- name: Install EPEL repository
|
||||
ansible.builtin.dnf:
|
||||
name: epel-release
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Install useful software
|
||||
ansible.builtin.dnf:
|
||||
name: "{{ common_packages }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Install firewalld
|
||||
ansible.builtin.dnf:
|
||||
name: firewalld
|
||||
state: present
|
||||
|
||||
- name: Start and enable firewalld service
|
||||
ansible.builtin.systemd:
|
||||
name: firewalld
|
||||
state: started
|
||||
enabled: true
|
||||
|
||||
- name: Set default zone to drop (deny incoming by default)
|
||||
ansible.posix.firewalld:
|
||||
zone: drop
|
||||
state: enabled
|
||||
permanent: true
|
||||
immediate: true
|
||||
|
||||
- name: Allow SSH in drop zone with rate limiting via rich rule
|
||||
ansible.posix.firewalld:
|
||||
zone: drop
|
||||
rich_rule: 'rule service name="ssh" accept limit value="10/m"'
|
||||
permanent: true
|
||||
immediate: true
|
||||
state: enabled
|
||||
|
||||
- name: Set drop as the default zone
|
||||
ansible.builtin.command:
|
||||
cmd: firewall-cmd --set-default-zone=drop
|
||||
changed_when: false
|
14
roles/podman/tasks/main.yml
Normal file
14
roles/podman/tasks/main.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
- name: Install Podman
|
||||
ansible.builtin.dnf:
|
||||
name: ["podman", "podman-docker", "podman-compose"]
|
||||
state: present
|
||||
|
||||
- name: Check if linger file exists
|
||||
ansible.builtin.stat:
|
||||
path: "/var/lib/systemd/linger/{{ target_user }}"
|
||||
register: linger_file
|
||||
changed_when: false
|
||||
|
||||
- name: Enable lingering if file doesn't exist
|
||||
ansible.builtin.command: loginctl enable-linger {{ target_user }}
|
||||
when: not linger_file.stat.exists
|
16
roles/webserver/tasks/debian.yml
Normal file
16
roles/webserver/tasks/debian.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
- name: Install MariaDB Server
|
||||
ansible.builtin.apt:
|
||||
name: mariadb-server
|
||||
state: present
|
||||
|
||||
- name: Change the bind-address to allow Docker
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/mysql/mariadb.conf.d/50-server.cnf
|
||||
regex: "^bind-address"
|
||||
line: "bind-address = 0.0.0.0"
|
||||
notify: restart_mariadb
|
||||
|
||||
- name: Install MySQL Support for Python 3
|
||||
ansible.builtin.apt:
|
||||
name: python3-pymysql
|
||||
state: present
|
@@ -1,19 +1,10 @@
|
||||
- name: Install MariaDB Server
|
||||
ansible.builtin.apt:
|
||||
name: mariadb-server
|
||||
state: present
|
||||
- name: Include Debian-specific tasks
|
||||
ansible.builtin.include_tasks: debian.yml
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- name: Change the bind-address to allow Docker
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/mysql/mariadb.conf.d/50-server.cnf
|
||||
regex: "^bind-address"
|
||||
line: "bind-address = 0.0.0.0"
|
||||
notify: restart_mariadb
|
||||
|
||||
- name: Install MySQL Support for Python 3
|
||||
ansible.builtin.apt:
|
||||
name: python3-pymysql
|
||||
state: present
|
||||
- name: Include Rocky Linux-specific tasks
|
||||
ansible.builtin.include_tasks: rocky.yml
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
- name: Create MariaDB databases
|
||||
community.mysql.mysql_db:
|
||||
@@ -27,7 +18,7 @@
|
||||
community.mysql.mysql_user:
|
||||
name: "{{ item.name }}"
|
||||
password: "{{ item.pass }}"
|
||||
host: '%'
|
||||
host: "%"
|
||||
state: present
|
||||
priv: "{{ item.name }}.*:ALL"
|
||||
login_unix_socket: /var/run/mysqld/mysqld.sock
|
||||
|
16
roles/webserver/tasks/rocky.yml
Normal file
16
roles/webserver/tasks/rocky.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
- name: Install MariaDB Server
|
||||
ansible.builtin.dnf:
|
||||
name: mariadb-server
|
||||
state: present
|
||||
|
||||
- name: Change the bind-address to allow Docker
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/my.cnf.d/mariadb-server.cnf
|
||||
regex: "^bind-address"
|
||||
line: "bind-address = 0.0.0.0"
|
||||
notify: restart_mariadb
|
||||
|
||||
- name: Install MySQL Support for Python 3
|
||||
ansible.builtin.apt:
|
||||
name: python3-pymysql
|
||||
state: present
|
Reference in New Issue
Block a user