infra/ansible/setup-host.sh
2025-05-30 13:24:38 -05:00

50 lines
921 B
Bash
Executable file

#!/bin/bash
create_ansible_group() {
groupadd -g 10000 ansible
}
create_ansible_user() {
useradd -g 10000 -u 10000 -c "Ansible User" -m ansible
}
add_ansible_user_to_sudoers() {
echo -e "ansible\tALL=NOPASSWD: ALL" >/etc/sudoers.d/ansible
}
add_ansible_ssh_key() {
mkdir -v ~ansible/.ssh
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFghGMnDdkfNC6JPEhMxrKhYDmNcXjHXp/y/mf3uLtzb Ansible SSH Key" >~ansible/.ssh/authorized_keys
chown -vR ansible:ansible ~ansible/.ssh
chmod 700 ~ansible/.ssh
chmod 600 ~ansible/.ssh/authorized_keys
}
copy_setup_to_host() {
local HOST=$1
scp $0 ${HOST}:/tmp
}
install() {
local HOST=$1
if [[ -z ${HOST} ]]; then
echo "No host given."
exit 1
fi
copy_setup_to_host ${HOST}
ssh -t ${HOST} "sudo /tmp/$0 setup"
}
setup() {
create_ansible_group
create_ansible_user
add_ansible_user_to_sudoers
add_ansible_ssh_key
}
CMD=$1
shift
eval $CMD $*