feat(ansible): add linux-baseline role and day0_linux_baseline playbook
Introduces a single, idempotent baseline role to supersede the overlapping day0-baseline and common roles. Capabilities are feature-flagged so they can be toggled per-host: - packages (common + OS-family + per-host extras) - timezone + locale - chrony time sync against sundial - baseline users (jarvis admin account with SSH key + NOPASSWD sudo) - SSH hardening via /etc/ssh/sshd_config.d/ drop-in - unattended security upgrades (Debian family) - sysctl drop-in at /etc/sysctl.d/99-mk-labs.conf - journald retention caps - branded MOTD Ubuntu/Debian is first-class; vars/RedHat.yml provides a placeholder for future distros via the ansible_os_family pattern. The legacy day0-baseline and common roles remain in place for now and will be removed during the playbook cleanup sweep, alongside the existing playbook naming inconsistencies.
This commit is contained in:
51
ansible/roles/linux-baseline/tasks/users.yml
Normal file
51
ansible/roles/linux-baseline/tasks/users.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
# ============================================================================
|
||||
# Baseline users
|
||||
# ============================================================================
|
||||
# Creates each user defined in baseline_users with their primary group,
|
||||
# SSH key(s), and optional passwordless sudo.
|
||||
# ============================================================================
|
||||
|
||||
- name: Create primary group for baseline users
|
||||
ansible.builtin.group:
|
||||
name: "{{ item.name }}"
|
||||
state: present
|
||||
loop: "{{ baseline_users }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: Create baseline users
|
||||
ansible.builtin.user:
|
||||
name: "{{ item.name }}"
|
||||
comment: "{{ item.comment | default('') }}"
|
||||
group: "{{ item.name }}"
|
||||
groups: "{{ item.groups | default(omit) }}"
|
||||
append: true
|
||||
shell: "{{ item.shell | default('/bin/bash') }}"
|
||||
create_home: true
|
||||
state: present
|
||||
loop: "{{ baseline_users }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: Deploy SSH authorized keys for baseline users
|
||||
ansible.posix.authorized_key:
|
||||
user: "{{ item.0.name }}"
|
||||
key: "{{ item.1 }}"
|
||||
state: present
|
||||
loop: "{{ baseline_users | subelements('ssh_authorized_keys', skip_missing=True) }}"
|
||||
loop_control:
|
||||
label: "{{ item.0.name }}"
|
||||
|
||||
- name: Grant passwordless sudo to baseline users
|
||||
ansible.builtin.copy:
|
||||
dest: "/etc/sudoers.d/{{ item.name }}"
|
||||
content: "{{ item.name }} ALL=(ALL) NOPASSWD:ALL\n"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0440"
|
||||
validate: "visudo -cf %s"
|
||||
loop: "{{ baseline_users }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
when: item.sudo_nopasswd | default(false) | bool
|
||||
Reference in New Issue
Block a user