Files
public/automation/iac/old-content/Packer/rocky10-proxmox-template/scripts/setup-ansible-user.sh
T
thesabear c05c7164c8 Restructure into one folder per private repo/host, not a flat Docker/ dump
rocky-docker-lxc/, caddy-vm/, monitoring-vm/ (was missing entirely -
Grafana+Loki+Prometheus stack, refreshed and CA mount stripped same as
everything else), and automation/{ansible,automation-vm,iac}/ for the
three repos that live on the automation VM. Hawser is genuinely
deployed on all three of caddy-vm/monitoring-vm/automation-vm so it's
duplicated in each rather than picking one canonical home.

Old Ansible/ and "Infrastrucutre as Code/" content moved under
automation/ansible/old-playbooks and automation/iac/old-content as-is
for now - contents still need refreshing against the current repos and
a per-folder README, that's the next pass.
2026-07-06 02:41:53 +03:00

34 lines
861 B
Bash

#!/bin/bash
set -euo pipefail
USERNAME="$1"
SSH_KEY="$2"
echo "Creating ansible user: $USERNAME"
# --- Create user if not exists
if ! id "$USERNAME" &>/dev/null; then
useradd -m "$USERNAME"
mkdir -p "/home/$USERNAME/.ssh"
echo "$SSH_KEY" > "/home/$USERNAME/.ssh/authorized_keys"
chmod 700 "/home/$USERNAME/.ssh"
chmod 600 "/home/$USERNAME/.ssh/authorized_keys"
chown -R "$USERNAME:$USERNAME" "/home/$USERNAME/.ssh"
else
echo "User $USERNAME already exists, skipping creation"
fi
# --- Harden the ansible user
# Disable password (no password login)
passwd -d "$USERNAME"
passwd -l "$USERNAME"
# Allow full passwordless sudo (needed for playbook tasks)
cat <<EOF > "/etc/sudoers.d/99_${USERNAME}"
${USERNAME} ALL=(ALL) NOPASSWD: ALL
EOF
chmod 0440 "/etc/sudoers.d/99_${USERNAME}"
echo "✅ User $USERNAME hardened for automation-only access"