Main menu

Packer Build and share AMI in AWS

{
  "builders": [
    {
      "access_key": "{{user `aws_access_key`}}",
      "ami_block_device_mappings": [
        {
          "device_name": "/dev/sdb",
          "virtual_name": "ephemeral0"
        },
        {
          "device_name": "/dev/sdc",
          "virtual_name": "ephemeral1"
        }
      ],
      "ami_description": "cis:{{user `ami-name`}}",
      "ami_name": "{{user `ami-name`}}",
      "ami_regions": [
        "us-west-1",
        "us-west-2"
      ],
      "ami_users": [
        "your_aws_Account_numbers",
        "XXXXXXXXXX"
      ],
      "enhanced_networking": "true",
      "instance_type": "t2.medium",
      "name": "us-east-1",
      "region": "us-east-1",
      "secret_key": "{{user `aws_secret_key`}}",
      "source_ami": "ami-e45c72f2",
      "ssh_username": "ubuntu",
      "tags": {
        "Name": "{{user `ami-name`}}"
      },
      "type": "amazon-ebs"
    }
  ],
  "post-processors": [],
  "provisioners": [
    {
      "inline": [
        "sudo chmod 777 /tmp/",
        "sudo chmod 777 /var/tmp/",
        "sudo rm -rf /home/ubuntu/.ssh/authorized_keys",
        "sudo rm -rf /root/.ssh/authorized_keys",
        "sudo rm -rf /home/ubuntu/.bash_history",
        "sudo rm -rf /root/.bash_history",
        "sudo mount /tmp -o remount,exec",
        "sudo apt-get update",
        "sudo DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' dist-upgrade -y -qq",
       "sudo apt-get -y autoremove"
      ],
      "remote_folder": "/home/ubuntu/",
      "type": "shell",
      "inline_shebang": "/bin/bash -x",
      "environment_vars": [
        "TERM=xterm",
        "DEBIAN_FRONTEND=noninteractive"
        ]
    }
  ],
  "variables": {
    "ami-name": "cis-{{isotime \"02-Jan-06-03-04-05\"}}",
    "aws_access_key": "XXXXXXXXXXXX",
    "aws_secret_key": "XXXXXXXXXXXXXXXXXXXXXXXXXXX"
  }
}


FacebookTwitterGoogle+RSS