Skip to main content

ANSIBLE LOCAL-PROVISIONER

NOTE:


INSTALL ANSIBLE IN LOCAL MACHINE  


now to n.virginia region 


go to ami

launch image 

go to ec2 dashboard 

launch instance 

all traffic anywhere

use public ip of that with 8080 and see website'



{

       "builders": [

           {


           "type": "amazon-ebs",

           "access_key": "AKQ",

           "secret_key": "K1aurid",

           "region": "us-east-1",

           "instance_type": "t2.micro",

           "source_ami": "ami-02e136e904f3da870",

           "ssh_username": "ec2-user",

           "ami_name": "moonu-amiii"



           }


       ],

       "provisioners": [

              {

              "type": "shell",

              "inline":[

                 "sleep 30",

                 "sudo yum update -y",

                 "sudo amazon-linux-extras install ansible2"              

              ]

              },

             {

             "type": "ansible-local",

             "playbook_file": "./playbook.yaml"



             }


       ]



}

============================================
PLAYBOOK.YML
==============================

- name: packer project
  hosts: all
  become: true

  tasks:
     - name: install apache
       package:
           name: 'httpd'
           state: present

     - copy:
         src: /sourcepath/
         dest: /var/www/html/

     - lineinfile:
           path: /etc/httpd/conf/httpd.conf
           regexp: '^Listen'
           insertafter: '^#Listen'
           line: 'Listen 8080'


     - service:
            name: httpd
            state: started
            enabled: yes

Comments

Popular posts from this blog

Packer Environment Variable

Note:  1011  export AWS_ACCESS=AKGQ                         do this on console not on editor  1012  export AWS_SECRET=KfVkt1aurid  1013  echo $AWS_ACCESS  1014  AKVUGQ   vim moon.json {     "variables": {       "aws_access_key": "{{env `AWS_ACCESS`}}",       "aws_secret_key": "{{env `AWS_SECRET`}}"     },        "builders": [            {            "type": "amazon-ebs",            "region": "us-east-1",            "access_key": "{{user `aws_access_key`}}",            "secret_key": "{{user `aws_secret_key`}}",            "instance_type": "t2.micro",            "source_ami": "ami-02e136e904f3da870", ...

copying snap from one REGION to another

 while copying snap from one to another we need to change region provider "aws" {   region     = "us-west-1"   access_key = "AGQ"   secret_key = "Kurid" } resource "aws_ebs_snapshot_copy" "example_copy" {   source_snapshot_id = "snap-08bc5c27dad8e82b3"   source_region      = "us-east-1"   tags = {     Name = "HelloWorld_copy_snap"   } }

File Provisioner

 Note: file provisioner is used to copy file we have created one file vim clod now how to checck its been copied  go to ami and launch image and create instance  vi pro.json {        "builders": [            {            "type": "amazon-ebs",            "region": "us-east-1",            "access_key": "AUGQ",            "secret_key": "Kurid",            "instance_type": "t2.micro",            "source_ami": "ami-02e136e904f3da870",            "ssh_username": "ec2-user",            "ami_name": "moon-amiii"            }        ],        "provisioners": [                {   ...