#!/bin/env bash if [ -z $1 ]; then echo 'Please, provide the path to the Ansible public key as an argument' exit 1 fi PUBKEY=$1 useradd ansible --create-home --shell /bin/bash # Ensure existing but unusable password (for Ubuntu) usermod -p '*' ansible mkdir /home/ansible/.ssh install -m 600 $PUBKEY /home/ansible/.ssh/authorized_keys chown -R ansible:ansible /home/ansible/.ssh chmod 700 /home/ansible/.ssh # Allow passwordless sudo echo "ansible ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/ansible