This guide includes the following information:
First, we need the operating system to install to the USB drive. These are typically .iso images, though occasionally can be .img with subtle differences. For instance, this guide will not work for Windows OS images because how they package the operating system.
For Ubuntu, go to https://ubuntu.com/download and download the operating system you want. Once it is downloaded, run the following command to write the image to the USB drive. BE VERY VERY CAREFUL ABOUT WHICH DRIVE YOU SELECT AS THIS CAN DESTROY THE COMPUTER YOU ARE USING
dd bs=4M if=./ubuntu.iso of=<THE DRIVE LOCATION> ; sync
<THE DRIVE LOCATION> will be something like /dev/sda.
Once that command has finished, you will have a possible working USB Drive. If the installation fails, just rerun the above command and try again.
You can double check that the thumbdrive was created properly by:
cmp -n `stat -c '%s' ubuntu.iso` ubuntu_iso. /dev/sdX
Follow the guided installation. The following options are recommended:
Select a minimal installation
Select 'Third Party Drivers'
Those two are the main important options. If there is drive encryption and you deem it necessary, feel free to install that as well.
This is assuming you have opted to install a Desktop version of an operating system. We need to install an open-ssh server to allow Ansible to access the machine for the initial setup.
On the new machine:
sudo apt update
sudo apt install openssh-server
On the machine that you are going to run Ansible from, add the new machine into your /.ssh/config file. Then copy your ssh key over to the new machine:
One your already setup machine:
ssh-copy-id <MACHINE NAME>
The initial configuration will use your account that you set up on the machine. Afterwards, we will use the sysadmin account that Ansible sets up on the machine.
Create a new playbook file in the systems directory. You can name it the name of the machine with an extension of .yml. The contents should have:
---
- hosts: <HOSTNAME>
remote_user: <YOUR USER NAME>
become: yes
gather_facts: no
roles:
- base
We can add more roles later. Let's just make sure that the base role works. This will setup the base for everything else. It includes setting up SSH properly and a few other housekeeping tasks.
Then edit the inventory.yml file to include the new machines name. You can just follow the other examples. Be sure to supply a mannet_ip option to the new machine. This is used for the internal management VPN that we use for remote machines.
Now run Ansible:
ansible-playbook <New Playbook File> -K
And insert the password you setup on the other machine. This will run the base role.
Now that the base role has been applied to the machine, we can 'fix' some of the configuration for long term use. Open the playbook file you created in the last step and change:
remote_user: <YOUR USER NAME>
to
remote_user: sysadmin
This will allow for others to run the Ansible scripts. Now you can start adding other roles you would like to apply to the machine.