The purpose is to get used to the different building blocks of the cloud infrastructure in order to set it up automatically using scripts and Ansible.
The infrastructure I am going to set up is:
Ansible Inventory
Create Ansible configuration file
vi ansible.cfg
I defined the host that we are going to work with, and folder called “my_inventory”. In the inventory section, we are using ini text format
[defaults]
inventory = my_inventory
[inventory]
enabled_plugins = ini
So, now I have a SSH key pair for EC2 instance, configuration file, and working directory called my_inventory.
my_inventory/hosts
Next, I am going to create hosts file in my_inventory folder which will be contained all the ansible hosts.
vi my_inventory/hosts
[aws]
tutorials ansible_host=52.41.237.170 ansible_user=ubuntu ansible_ssh_private_key_file=yourkeyname.pem
ansible-inventory --list
ansible-inventory --graph
# more info
ansible-inventory --graph --vars
Connect host machine to AWS EC2 instance
Run ansible -m ping to check if the configuration is successfully done. If you don’t have EC2 instance, Follow this link to create EC2 instance so that you can follow my tutorial
ansible -m ping tutorials
Connection timed out Error
If you got Connection timed out error, check your configuration file is correctly configured. It’s mostly because of syntax error or IP address is not matched to your EC2 instance.
Permission denied (UNPROTECTED PRIVATE KEY FILE) Error
This is because of your key pair permissions. Change permission 0644 to 600
chmod 600 yourkey.pem