#!/bin/bash # Exit immediately on error set -e # Create ansible user with /bin/bash shell sudo useradd -m -s /bin/bash ansible # Add ansible user to the sudo group sudo usermod -aG sudo ansible # Grant passwordless sudo access echo "ansible ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers > /dev/null # Create .ssh directory and add public key sudo mkdir -p /home/ansible/.ssh echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzq9JFipLZUMOqPIckLgBhnc/QkybYhzJdPr9AElebQuVef+6mjE5kw7pi4Se+XmjBh32HSXAPgZ4QKH88FePtAoHMDXRICVuP7hBSP6Z24VEOthSE9DywPSSokdT1K30SRYqCiS+4cdTCC8qDjACINrPyHO6w+hS6XUnoMU5OHia2Es41u/S5VHYrETj92iPzXwtiLAzLH2z5A1gESi5N9UK2hqojks0p4Z4LUhr5P+a/LPYxZ0jJTK3Vy1gRI8+r/nua2OAHT/pXiWgAnt56o+iMbqjQFGQEEfSgHsprLU7NXWqDLZyP00/JKp27IsZREOnt8jcFzcK1Jby9JOO1 ansible@AMS-ANS01" | sudo tee /home/ansible/.ssh/authorized_keys > /dev/null # Set proper permissions and ownership sudo chown -R ansible:ansible /home/ansible/.ssh sudo chmod 700 /home/ansible/.ssh sudo chmod 600 /home/ansible/.ssh/authorized_keys echo "Ansible user created and configured successfully."