refactor(roles/common): naming and formatting improvements

This commit is contained in:
ITQ
2026-03-19 14:44:09 +03:00
parent 22a56aca43
commit a54b4272ce
4 changed files with 29 additions and 17 deletions
+2 -2
View File
@@ -1,3 +1,3 @@
--- ---
journal_retention_days: 21 common_journal_retention_days: 21
journal_max_disk_limit: "5%" common_journal_max_disk_limit: "5%"
+3 -2
View File
@@ -1,9 +1,10 @@
--- ---
- name: Create cron job to prune journald logs with configurable limits - name: Create cron job to prune journald logs with configurable limits
become: true
ansible.builtin.cron: ansible.builtin.cron:
name: "Prune systemd journal logs ({{ journal_retention_days }} days, {{ journal_max_disk_limit }} disk)" name: "Prune systemd journal logs ({{ common_journal_retention_days }} days, {{ common_journal_max_disk_limit }} disk)"
minute: "0" minute: "0"
hour: "2" hour: "2"
job: "/usr/bin/journalctl --vacuum-time={{ journal_retention_days }}d --vacuum-size={{ journal_max_disk_limit }} > /dev/null 2>&1" job: "/usr/bin/journalctl --vacuum-time={{ common_journal_retention_days }}d --vacuum-size={{ common_journal_max_disk_limit }} > /dev/null 2>&1"
user: root user: root
state: present state: present
+16 -8
View File
@@ -1,9 +1,10 @@
--- ---
- name: Include optimization tasks - name: Include optimization tasks
include_tasks: optimization.yaml ansible.builtin.include_tasks: optimization.yaml
tags: optimization tags: optimization
- name: Install essential packages - name: Install essential packages
become: true
ansible.builtin.apt: ansible.builtin.apt:
name: "{{ system_packages.essential }}" name: "{{ system_packages.essential }}"
state: present state: present
@@ -12,48 +13,54 @@
tags: packages tags: packages
- name: Set hostname and FQDN - name: Set hostname and FQDN
tags: system
block: block:
- name: Set hostname - name: Set hostname
become: true
ansible.builtin.hostname: ansible.builtin.hostname:
name: "{{ hostname | default(inventory_hostname) }}" name: "{{ hostname | default(inventory_hostname) }}"
- name: Configure FQDN in hosts file - name: Configure FQDN in hosts file
become: true
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: /etc/hosts path: /etc/hosts
regexp: '^127\.0\.1\.1.*' regexp: '^127\.0\.1\.1.*'
line: "127.0.1.1 {{ fqdn | default(hostname) }} {{ hostname | default(inventory_hostname) }}" line: "127.0.1.1 {{ fqdn | default(hostname) }} {{ hostname | default(inventory_hostname) }}"
state: present state: present
tags: system
- name: Deploy MOTD template - name: Deploy MOTD template
template: become: true
ansible.builtin.template:
src: motd.j2 src: motd.j2
dest: /etc/motd dest: /etc/motd
mode: '0644' mode: "0644"
- name: Configure timezone - name: Configure timezone
become: true
community.general.timezone: community.general.timezone:
name: "{{ timezone }}" name: "{{ timezone }}"
tags: system, ntp tags: system, ntp
- name: Install and configure NTP - name: Install and configure NTP
include_role: ansible.builtin.include_role:
name: geerlingguy.ntp name: geerlingguy.ntp
tags: system, ntp tags: system, ntp
- name: Deploy SSH configuration - name: Deploy SSH configuration
become: true
ansible.builtin.template: ansible.builtin.template:
src: sshd_config.j2 src: sshd_config.j2
dest: /etc/ssh/sshd_config dest: /etc/ssh/sshd_config
owner: root owner: root
group: root group: root
mode: '0600' mode: "0600"
validate: '/usr/sbin/sshd -t -f %s' validate: "/usr/sbin/sshd -t -f %s"
notify: Restart ssh notify: Restart ssh
- name: Create admin users with proper SSH keys - name: Create admin users with proper SSH keys
block: block:
- name: Ensure user exists - name: Ensure user exists
become: true
ansible.builtin.user: ansible.builtin.user:
name: "{{ item.name }}" name: "{{ item.name }}"
shell: "{{ item.shell | default('/bin/bash') }}" shell: "{{ item.shell | default('/bin/bash') }}"
@@ -66,6 +73,7 @@
tags: users tags: users
- name: Deploy SSH authorized keys - name: Deploy SSH authorized keys
become: true
ansible.posix.authorized_key: ansible.posix.authorized_key:
user: "{{ item.0.name }}" user: "{{ item.0.name }}"
state: present state: present
@@ -77,5 +85,5 @@
tags: users, ssh tags: users, ssh
- name: Include cron tasks - name: Include cron tasks
include_tasks: cron.yaml ansible.builtin.include_tasks: cron.yaml
tags: cron tags: cron
+4 -1
View File
@@ -1,6 +1,7 @@
--- ---
- name: Configure sysctl parameters - name: Configure sysctl parameters
ansible.builtin.sysctl: become: true
ansible.posix.sysctl:
name: "{{ item.key }}" name: "{{ item.key }}"
value: "{{ item.value }}" value: "{{ item.value }}"
state: present state: present
@@ -9,11 +10,13 @@
tags: optimization tags: optimization
- name: Configure file handle limits - name: Configure file handle limits
become: true
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: /etc/security/limits.conf path: /etc/security/limits.conf
regexp: "^{{ item.user | regex_escape }}.*{{ item.type }}" regexp: "^{{ item.user | regex_escape }}.*{{ item.type }}"
line: "{{ item.user }} - nofile {{ item.limit }}" line: "{{ item.user }} - nofile {{ item.limit }}"
create: true create: true
mode: "0644"
loop: loop:
- { user: "root", type: "soft", limit: "65536" } - { user: "root", type: "soft", limit: "65536" }
- { user: "root", type: "hard", limit: "65536" } - { user: "root", type: "hard", limit: "65536" }