Skip to content

Instantly share code, notes, and snippets.

@amaudy
Created April 10, 2021 06:19
Show Gist options
  • Save amaudy/5004ae82e147d9e40e7e58c77c589617 to your computer and use it in GitHub Desktop.
Save amaudy/5004ae82e147d9e40e7e58c77c589617 to your computer and use it in GitHub Desktop.
Packer file for create AMI and provisioning server bu Ansible playbook
{
"variables": {
"aws_access_key": "ACCESSKEY",
"aws_secret_key": "SECRETKEY",
"aws_subnet_id": "SUBNETID"
},
"builders": [
{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"subnet_id": "{{user `aws_subnet_id`}}",
"region": "us-east-1",
"instance_type": "t3.micro",
"ami_name": "bookapp-{{timestamp}}",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "*ubuntu/images/*ubuntu-focal-20.04-amd64-server-*",
"root-device-type": "ebs"
},
"owners": ["xxx"],
"most_recent": true
},
"security_group_filter": {
"filters": {
"tag:Class": "packer"
}
},
"ssh_username": "ubuntu"
}
],
"provisioners": [
{
"type": "shell",
"max_retries": 5,
"inline": [
"sudo apt-get update -y && sudo apt-get upgrade -y",
"sudo apt install python -y"
]
},
{
"type": "ansible",
"playbook_file": "/home/amaudy/ansible/playbooks/apache.yml",
"groups": ["web"]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment