Overview
Ansible playbook template to deploy Ubuntu 18.04 server on AWS EC2 and locally with Vagrant
Setup Local
- Enter relevant variables in the
local/vars/vars.yml
file - Create
~/.ssh/authorized_keys
on your local machine and with your public key. This is used as a shared folder with vagrant in order to connect:cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
(ssh-keygen
to setup) - Edit the config files in
local/vars/configs/
- Add any tasks you need to
local/tasks/
andlocal/main.yml
- Add any roles you need to
local/roles/
andlocal/main.yml
- Create the VM:
vagrant up
- Connect to the VM:
vagrant ssh
Web Setup
- Enter relevant variables in the
web/vars/vars.yml
file - Add your ssh public key(s) to
web/vars/ssh_keys/authorized_keys.yml
- Edit the config files in
web/vars/configs/
- Add any tasks you need to
web/tasks/
andweb/main.yml
- Add any roles you need to
web/roles/
andweb/main.yml
After the site is provisioned:
- Create certs with certbot (
--certonly
) - Create an associated domain name, DNS record, add it below
[web]
in thehosts
file.
Local Usage
Vagrant Commands:
- Build:
vagrant up
- Connect:
vagrant ssh
- Reload:
vagrant reload
- Re-provision:
vagrant provision
- Stop:
vagrant halt
- Delete:
vagrant destroy -f
VM Tips & Tricks:
- View login message:
motd
- File browser:
ranger
- Reload dotfiles:
sauce
- Netdata real-time performance monitor in the browser at
192.168.1.43:19999
- follow troubleshooting steps here if Netdata is not loading
Resource Allocation:
You can easily change resource allocation for the VM in the lab/local/Vagrantfile
.
v.memory = <memory>
= Memory / RAM allocated to the VMv.cpus = <cpu_cores>
= CPU Cores allocated to the VM
Web Usage
lab/web/main.yml
is used to build and manage servers and dependencies.
ansible-playbook --ask-vault-pass -i hosts --key-file "~/devops/local/key_pairs/<keypair>.pem" main.yml
Dependencies
Ansible
sudo easy_install pip
sudo pip install ansible
sudo mkdir /etc/ansible
sudo touch /etc/ansible/hosts
sudo touch /etc/ansible/ansible.cfg
Vagrant
Download and install from website.
Virtualbox
Download and install from website.
If experiencing issues installing on mac, follow this guide.
AWS CLI
First, create an AWS account if you haven't already.
Install pip3:
brew install python3
brew postinstall python3
If you encounter permissions issues do this:
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
Install aws-cli:
pip3 install awscli --upgrade --user
echo "export PATH=~/Library/Python/3.7/bin:$PATH" >> ~/.profile
sudo pip install boto
Go to AWS dashboard and create keys for your user.
Create ~/.aws directory and files:
mkdir ~/.aws
touch ~/.aws/config
touch ~/.aws/credentials
Add the text below to ~/.aws/config
:
[default]
region = us-east-2
Add the text below to ~/.aws/credentials
with relevant credentials:
[default]
aws_access_key_id = <aws access key>
aws_secret_access_key = <aws secret key>
Ansible Vault
UsingMake sure to encrypt any passwords/secrets with ansible vault:
- Creating encrypted files:
ansible-vault create file.yml
- Editing encrypted files:
ansible-vault edit file.yml
- Encrypting files:
ansible-vault encrypt file1.yml file2.yml file3.yml
- Decrypting files:
ansible-vault decrypt file.yml