This playbook shows how to automates the initial server setup of Ubuntu 22.04 servers using Ansible. It implements all the steps given in the Initial Server Setup Guide for Ubuntu 20.04 tutorial, then adds a few more steps to make the servers more secure.
Variables required to execute some parts of the playbook are specified in the vars/default.yml
variable file. You'll need to modify the default Ansible inventory, or hosts, file (/etc/ansible/hosts
) on your local machine so that it contains the IP addresses of the target hosts.
The following variables are defined in vars/default.yml
.
create_user
: the name of the remote user to create.ssh_port
: the custom port for logging into the hosts after the initial server setup.copy_local_key
: path to a local SSH public key that will be copied as authorized key for the new user. By default, it copies the key from the home directory of the user running Ansible.
Quick Steps:
git clone https://github.com/finid/ansible-ubuntu.git
cd ansible-ubuntu
nano vars/default.yml
#vars/default.yml
create_user: sammy
ssh_port: 5995
copy_local_key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
Details in the tutorial...
Best to perform a syntax-check of the playbook.
ansible-playbook --syntax-check initial.yml
Then run the the playbook.
ansible-playbook --ask-vault-pass initial.yml
As a bonus, another playbook is included that you can use to maintain the servers after the initial server setup.
ansible-playbook --syntax-check ongoing.yml
Then run the the playbook.
ansible-playbook --ask-vault-pass ongoing.yml
For more information on how to run this Ansible setup, please check this guide: Automate Initial Server Setup of Multiple Ubuntu 22.04 Servers Using Ansible.