A) Installation on Ansible Master Node
Note: All installation instructions are specific to
[Ubuntu Server 18.04 LTS (HVM), SSD Volume Type - ami-0dc8d444ee2a42d8a (64-bit x86) / ami-0c7316a2d5e1a85a1 (64-bit Arm)]
-
Prerequisite
- Running EC2 instance
[Ubuntu Server 18.04 LTS (HVM), SSD Volume Type - ami-0dc8d444ee2a42d8a (64-bit x86) / ami-0c7316a2d5e1a85a1 (64-bit Arm)]
- Security groups having
SSH permission
Note: This Security group ID further need to set in
Ansible_EC2/ec2-vars/webservers.yml
- Running EC2 instance
-
Install python 2.7
>sudo apt-get install python-dev build-essential
Note: Probably need to also:
>sudo apt-get update --fix-missing
-
Install boto
> sudo apt-get install python-pip > pip install boto
-
Install Ansible
>sudo apt-get update >sudo apt-get install software-properties-common >sudo apt-add-repository ppa:ansible/ansible >sudo apt-get update >sudo apt-get install ansible
B) Configuration
-
Add AWS Private Key:
>vi ~/.ssh/id_rsa
Copy entire contents of the .pem file into id_rsa.To save and exit: press “Esc” then enter “:wq!”
-
Add AWS Public Key:
>vi ~/.ssh/id_rsa.pub
Open the .ppk private key in puttygen or in other tool, copy the public key to the clipboard, and place into id_rsa.pub.
Note Add read/write privileges
>chmod 0600 ~/.ssh/id*
-
Authentication: Authentication on AWS-related modules is handled by specifying the access and private key as ENV variables
For environment variables:
>export AWS_ACCESS_KEY_ID='<Your_ACCESS_KEY_ID>' >export AWS_SECRET_ACCESS_KEY='<Your_AWS_SECRET_ACCESS_KEY>'
Note You can also add environment variables permanently as below
vi ~/.bash_profile'
Add below in file. To save and exit: press “Esc” then enter “:wq!”
>export AWS_ACCESS_KEY_ID='<Your_ACCESS_KEY_ID>' >export AWS_SECRET_ACCESS_KEY='<Your_AWS_SECRET_ACCESS_KEY>'
-
Copy
Ansible_EC2
and Permission Setting- Copy the
Ansible_EC2
from local to Master node using winscp or any other tool. - Go to root dir
Ansible_EC2
- Run below command
>
chmod +x ec2.py
>chmod +x ec2.ini
- Go to root dir
/etc/ansible/
- Run below command
>
sudo chmod 700 hosts
- Copy the
-
Config parameters defined in
Ansible_EC2/ec2-vars/webservers.yml
- ec2_instance_type (default
t2.micro
) - ec2_image (default
ami-0dc8d444ee2a42d8a
) - ec2_region (default
eu-west-1
) - ec2_tag_Name (default
AnsibleHost
) - ec2_tag_Type (default
webserver
) - ec2_security_grp
- ec2_keypair
- ec2_tag_Environment (default
testing
) - aws_access_key
- aws_secret_key
- ec2_volume_size (default
8GB
)
- ec2_instance_type (default
-
Config parameters defined in
Ansible_EC2/AnsibleCLI.py
- host_group for dynamic inventory (default
tag_Type_webserver
)
- host_group for dynamic inventory (default
C) RUN