Skip to content

kryp33/Ansible_ec2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Ansible_ec2

EC2 provision

It took me a couple of hours to compile workable provision of EC2 using ansible. I found some bits and pieces none of which work from scratch in my MacOS environment. So I documented for myself all steps I had to take.

Assuming AWS account is open and in good shape...:

1 CreateVirtual Environment

python3 -m venv ansi_env
source  ./bin/activate

2 Install tools:

pip install boto
pip install ansible

3 Create user/group in AWS for ansible:

a Create group (via aws console):

name: asw_deployer
policy: PowerUser

b Create ansible user

name: asw_ansible
group: asw_deployer

c Generate credentials for user and place them in AWS credential file under profile like

Credetials_file in ~/.aws

[default]
aws_access_key_id=xxx
aws_secret_access_key=xxx
[asw_ansible]
aws_access_key_id=xxx
aws_secret_access_key=xxx

Setting profile env var to be used by ansible/boto

export AWS_PROFILE=asw_ansible

4 Make SSH AWS Key_pair:

Via console make new key_pair. Get *.pem file from AWS and place it in ~/.ssh It will be used when Ansible talk with new EC2. Add this key to ssh-agent to forward it( read docs if you need https://developer.github.com/v3/guides/using-ssh-agent-forwarding/)

ssh-add ~/.ssh/my_new_key.pem 

5 Create hosts file:

The ansible_python_interpreter addition should point ansible to use boto from virtual env installation. Otherwise it will be looking on machine level installation..

[local]
localhost ansible_python_interpreter=/Users/thats_me/projects/dev_ops/ansi_env/bin/python

[webserver]

6 Create YML file: (see github src) and run it as:

ansible-playbook -i ./hosts ec2_test.yml 

Most of the steps above were adapted from here: https://www.agix.com.au/build-an-ec2-using-ansible-step-by-step/

7 Testing:

When it's all set and done on the 7th day you may test success of creation:

ansible all -i hosts -u ec2-user -m ping

About

EC2 provision

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published