prole/infrastructure/setup/cr_ansible_user.sh

16 lines
581 B
Bash

set -x
HOST=$1
PUBKEY="$(cat ~/.ssh/id_ed25519_ansible.pub)"
ssh $HOST "sudo bash -s" <<EOF
set -e
id ansible >/dev/null 2>&1 || useradd -m -s /bin/bash ansible
install -d -m 700 -o ansible -g ansible /home/ansible/.ssh
touch /home/ansible/.ssh/authorized_keys
chmod 600 /home/ansible/.ssh/authorized_keys
chown ansible:ansible /home/ansible/.ssh/authorized_keys
grep -qxF '$PUBKEY' /home/ansible/.ssh/authorized_keys || echo '$PUBKEY' >> /home/ansible/.ssh/authorized_keys
echo 'ansible ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/90-ansible
chmod 440 /etc/sudoers.d/90-ansible
EOF