This is a quick "Hands-on" tutorial, and I purposely avoid explaining every Term to keep it simple so you can just follow along quickly.
Click on the create button inside the Droplet page.
Select ubuntu (version 20.04 (LTS), Select whatever plan you wish, I choose the cheapest 6$ plan in the Premium Intel Cpu options and Choose your preferred location for the server
under Authentication: make sure you select your SSH keys. Ansible will need to use the SSH Keys in order to connect with the server.
I like to think about Ansible as a the tool for "Day two operations" for servers. You can create your server manually or with other tools like terraform and with Ansible you can configure that server using Infrastructure as code, automating all the manuall steps that you usually need to do when configuring or installing tools on the server. In Ansible, we call our configuration files ‘playbooks’, and inside a ‘playbook’ we list sets of tasks ('Plays' in Ansible world) and they are written in Yaml.
Ansible Roles are a way to take related configuration (Playbooks), and package them together so they are working nicely together.
you should have the following folder structure:
In the above playbook, in the second line, we tell Ansible to run the playbook against the "All" group of servers and if you take a look at the all.ini inventory file, we can see that there is only one server in the group and it's the digitalocean one. Bellow, we define the role "ansible-role-mysql" that should run (If you are not familiar at all with ansible, just keep in mind that if you run a "role" inside a playbook, then the tasks/main.yml file in that role is what actually executed. main.yml is the starting point for the Role)
To run the playbook, we use the command "ansible-playbook", we give it the inventory file, the playbook to execute, and in our case also the user that Ansible should use inorder to connect with the server.
The root user is not allowed to connect to the MySQL from a remote connection, that was purposely done by the Ansible role as a security best practice (You can check the exact task in ansible-role-mysql/tasks/secure-installation.yml). Inorder to connect to the database, first ssh into the digitalocean MySQL server that we just created and while your connected to the server, try to connect to the database. here's how it should look like:
The default root password is just "root", you should definitely change this to something more secure. Go to the ansible-role-mysql directory and open the file defaults/main.yml. change the values for
mysql_root_username: root
mysql_root_password: root
You now have a cheap (this also works great on the 5 dollar droplet) MySQL server running and configured in couple of minutes.