Skip to content

Latest commit

 

History

History
88 lines (56 loc) · 1.97 KB

File metadata and controls

88 lines (56 loc) · 1.97 KB

Ansible Installation on Linux

  1. Install EPEL Repo

sudo yum install epel-release

Note : Ansible needs python to be installed.

  1. Install Ansible on Linux distribution

sudo yum install python

sudo yum install -y ansible

  1. Install Ansible on Mac OS.

pip install ansible

  1. Create a directory

mkdir /etc/ansible

  1. Create a configuration file named "hosts"

vi hosts

  1. Add the following line

[server] 18.222.176.34 ansible_ssh_private_key_file=/Users/shubham/Documents/aws-keys/devops-ec2.pem

Note : 18.222.176.34 is the ip address of the aws ec2 machine and devops-ec2.pem is the key file that you have downloaded while launching the ec2 instance.

  1. Run the below command to check the connectivity.

ansible all -m ping -u ec2-user

  1. Running Ansible playbook

In order to run ansible playbook, please make sure you have installed the python boto package in your system. it offers the packages for aws connectivity.

To Install Boto3

pip Install boto3

9 Post installation of boto, go to user home directory /Users// and create a file as below.

vi .boto

  1. Add the following linds and credentials provided by AWS and save.

[Credentials]

aws_access_key_id=Access key provided by AWS

aws_secret_access_key=Access key secret provided by AWS

Ansible Playbooks

  1. Go to the directory /etc/ansible/

cd /etc/ansible/

12 Create a ansible playbook file using below command.

vi task.yml

- name : ec2-launcher
 hosts : localhost
 connection : local
 tasks :
 - name : launch ec2
   ec2 : 
    instance_type : t2.micro
    key_name : devops-ec2
    image : ami-097834fcb3081f51a
    region : us-east-2
    group : launch-wizard-1
    count : 1
    vpc_subnet_id : subnet-9f5562e5
    wait : yes
    assign_public_ip : yes

13 To run the ansible playbook, execute below command.

ansible-playbook task.yml

this will create an ec2 instance for us and install the necessary softwares like docker.