Skip to main content

LOCAL PROVISIONER

make one folder projectB
projectB : make one file index.html
generate key : ssh-kegen 



VIM AR.TF  

provider "aws" {

  region     = "us-east-1"

  access_key = "AUGQ"

  secret_key = "Kt1aurid"

}



variable "privatekey" {

  default = "dev"

}



resource "aws_key_pair" "dev" {

  key_name   = "dev"

  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhI176Z0ylP2WdWAbI2hrFf5oEHlnZ0zcSm85SGysuwx/lMl0F+muOcke0wS90f5NU+bUAKNL2hWFozx/HxEtaquM77go+eWY9lg1E7q9Ls8nzVv1pddNgtS7Cihgzd7UaXDq0ayhOUBO1y6nMZYobFNy4E63vBuCYyhHwPAT7mheZm2GphKYrkd1Qt4qvcZcJ4CBmjCwQ3VBdwOhk8ZdKc7BdpLNPENNCLkzswhNcpRInRADMAM1ZgPikKt8wEaeMX/Hg2Mrk0MS49mYFnPxc1G5DuSsW7P9L+7IzbGI2pl4RSLM8/IlFef/i1HWgdaDCJpejgxLX4Hux9EUyqtd1 root@ip-172-31-46-6.ap-south-1.compute.internal"


}


resource "aws_instance" "web" {

  ami           = "ami-02e136e904f3da870"

  instance_type = "t3.nano"

  key_name = "dev"

  tags = {

    Name = "prod"

}


provisioner "remote-exec"  {

inline = [

    "echo 'build ssh'"


]                                                           #note : tomake connection successful we need remote-exec

connection {

  host  = self.public_ip

  type  = "ssh"

  user  = "ec2-user"

  private_key  = file("./dev")



}


}

provisioner "local-exec" {

  command = "ansible-playbook -i ${aws_instance.web.public_ip}, --private-key ${var.privatekey} moon.yaml"


                                          target                            variable key         playbook name           

}

}

==========================================

VIM ANSIBLE.CFG

[defaults]
remote_user = ec2-user
host_key_checking = False
===============================================

VIM MOON.YAML

- hosts: all
  tasks:
     - name: exective commamd in remote
       shell: "echo 'welcome moon' > /tmp/moon"

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"   } }

ONLY & MULTIPLE PARAMTER IN PACKER

if we have to define 3 builders from different services azure, gcp,aws here we can  provisioner will run on all builders  if we want to run on specific builder then we can use only parameter  "only": ["prod-team","test-team"]  {        "builders": [            {            "name": "test-team",            "type": "amazon-ebs",            "access_key": "AUGQ",            "secret_key": "Kaurid",            "region": "us-east-1",            "instance_type": "t2.micro",            "source_ami": "ami-02e136e904f3da870",            "ssh_username": "ec2-user",            "ami_name": "test-team-{{timestamp}}"            },   ...