Skip to content

Instantly share code, notes, and snippets.

@leanderjanssen
Created August 17, 2018 12:19
Show Gist options
  • Save leanderjanssen/c178ed0c3c5a8a52fb7f352e410c22b1 to your computer and use it in GitHub Desktop.
Save leanderjanssen/c178ed0c3c5a8a52fb7f352e410c22b1 to your computer and use it in GitHub Desktop.
packer.json with ansible provisioner
{
"variables": {
"unique_id": "{{env `UNIQUE_ID`}}",
"ansible_path": "{{env `ANSIBLE_ROLES_PATH`}}",
"playbook_path": "{{env `ANSIBLE_PLAYBOOK_PATH`}}",
"ami": "{{ env `AMI`}}",
"subnet_id": "{{env `SUBNET`}}",
"vpc_id": "{{env `VPC`}}",
"owner": "{{env `OWNER`}}",
"ami_name": "{{env `AMI_NAME`}}",
"ansible_skip_tags": "notscored",
"source_ami": "{{env `SOURCE_AMI`}}",
"datetime": "{{env `DATETIME`}}",
"ansible_groups": "{{env `ANSIBLE_GROUPS`}}",
"ami_users": "{{env `PACKER_AMI_USERS`}}",
"root_volume_size": "{{env `ROOT_SIZE`}}",
"iam_instance_profile": "{{env `IAM_ROLE`}}",
"extra_vars": "{{env `ANSIBLE_EXTRA_VARS`}}",
"CI_BUILD_REF": "{{env `CI_BUILD_REF`}}",
"CI_BUILD_TAG": "{{env `CI_BUILD_TAG`}}",
"CI_BUILD_REF_NAME": "{{env `CI_BUILD_REF_NAME`}}",
"CI_BUILD_ID": "{{env `CI_BUILD_ID`}}",
"ami_source_name": "{{env `SOURCE_AMI_SOURCE_NAME`}}",
"ami_os": "{{env `SOURCE_AMI_OS`}}"
},
"builders": [
{
"name": "{{ user `ami_os` }}",
"type": "amazon-ebs",
"region": "eu-west-1",
"source_ami": "{{ user `source_ami` }}",
"instance_type": "t2.large",
"ami_name": "{{ user `ami_name` }}_{{ user `datetime` }}",
"ami_users": "{{ user `ami_users` }}",
"vpc_id": "{{ user `vpc_id` }}",
"subnet_id": "{{ user `subnet_id` }}",
"security_group_ids": [
"sg-1",
"sg-2"
],
"iam_instance_profile": "{{ user `iam_instance_profile` }}",
"launch_block_device_mappings": [
{
"device_name": "/dev/sda1",
"volume_type": "gp2",
"delete_on_termination": true,
"volume_size": "{{ user `root_volume_size`}}"
}
],
"ami_block_device_mappings": [
{
"device_name": "/dev/sda1",
"volume_type": "gp2",
"volume_size": "{{ user `root_volume_size`}}"
}
],
"associate_public_ip_address": false,
"ssh_file_transfer_method": "sftp",
"ssh_private_ip": true,
"ssh_username": "ec2-user",
"user_data_file": "{{template_dir}}/ec2_user_data.txt",
"run_tags": {
"Name": "temporary packer build {{ user `ami_name` }}",
"source": "{{ user `ami_os` }}-{{user `ami_source_name`}}-{{ user `source_ami` }}",
"owner": "{{ user `owner` }}",
"uuid": "{{ user `unique_id` }}",
"os": "{{ user `ami_os` }}",
"CI_BUILD_REF": "{{user `CI_BUILD_REF`}}",
"packer": "true"
},
"tags": {
"purpose": "{{ user `ami_name` }}",
"source": "{{user `ami_os`}}-{{user `ami_source_name`}}-{{ user `ami` }}",
"owner": "{{ user `owner` }}",
"uuid": "{{ user `unique_id` }}",
"os": "{{user `ami_os`}}",
"CI_BUILD_REF": "{{user `CI_BUILD_REF`}}",
"CI_BUILD_TAG": "{{user `CI_BUILD_TAG`}}",
"CI_BUILD_REF_NAME": "{{user `CI_BUILD_REF_NAME`}}",
"CI_BUILD_ID": "{{user `CI_BUILD_ID`}}",
"packer": "true"
}
}
],
"provisioners": [
{
"type": "ansible",
"playbook_file": "{{ user `playbook_path` }}/{{ user `ami` }}.yml",
"sftp_command": "/usr/libexec/openssh/sftp-server -e",
"groups": "{{user `ansible_groups`}}",
"user": "ec2-user",
"ansible_env_vars": [
"ANSIBLE_VAULT_PASSWORD_FILE=.ansible_vault_password",
"ANSIBLE_HOST_KEY_CHECKING=False",
"ANSIBLE_ROLES_PATH={{ user `ansible_path` }}",
"ANSIBLE_FORCE_COLOR=True",
"ANSIBLE_HASH_BEHAVIOUR=merge",
"ANSIBLE_SSH_PIPELINING=True",
"PYTHONUNBUFFERED=1",
"ANSIBLE_STDOUT_CALLBACK=debug",
"ANSIBLE_CALLBACK_WHITELIST=profile_tasks",
"CI_BUILD_REF={{user `CI_BUILD_REF`}}",
"CI_BUILD_TAG={{user `CI_BUILD_TAG`}}",
"CI_BUILD_REF_NAME={{user `CI_BUILD_REF_NAME`}}",
"CI_BUILD_ID={{user `CI_BUILD_ID`}}"
],
"extra_arguments": [
"--skip-tags",
"{{ user `ansible_skip_tags` }}"
]
}
],
"post-processors": [
{
"type": "vagrant",
"output": "{{ user `ami_name` }}.box"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment