Created
February 26, 2018 09:23
-
-
Save VireshDoshi/4f09a775eb628c9f8672733a5dae39f8 to your computer and use it in GitHub Desktop.
packer file for creating an AMI image with ansible provisioning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"variables": { | |
"aws_access_key": "", | |
"aws_secret_key": "" | |
}, | |
"provisioners": [ | |
{ | |
"type": "shell", | |
"execute_command": "echo 'ubuntu' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", | |
"inline": [ | |
"sleep 30", | |
"apt-add-repository ppa:ansible/ansible -y", | |
"/usr/bin/apt-get update", | |
"/usr/bin/apt-get -y install ansible", | |
"mkdir /home/ubuntu/node-app", | |
"chown ubuntu:ubuntu /home/ubuntu/node-app" | |
] | |
}, | |
{ | |
"type": "file", | |
"source": ".", | |
"destination": "/home/ubuntu/node-app/" | |
}, | |
{ | |
"type": "ansible-local", | |
"playbook_file": "packer/ansible-playbook.yml" | |
} | |
], | |
"builders": [{ | |
"type": "amazon-ebs", | |
"access_key": "{{user `aws_access_key`}}", | |
"secret_key": "{{user `aws_secret_key`}}", | |
"region": "us-east-1", | |
"source_ami_filter": { | |
"filters": { | |
"virtualization-type": "hvm", | |
"name": "ubuntu/images/*ubuntu-trusty-14.04-amd64-server-*", | |
"root-device-type": "ebs" | |
}, | |
"owners": ["099720109477"], | |
"most_recent": true | |
}, | |
"instance_type": "t2.micro", | |
"ssh_username": "ubuntu", | |
"ami_name": "packer-viresh {{timestamp}}", | |
"launch_block_device_mappings": [{ | |
"device_name": "/dev/sda1", | |
"volume_size": 8, | |
"volume_type": "gp2", | |
"delete_on_termination": true | |
}] | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment