Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save suz-lab/9364620e6bd3634a9a9e to your computer and use it in GitHub Desktop.
Save suz-lab/9364620e6bd3634a9a9e to your computer and use it in GitHub Desktop.
- hosts: localhost
gather_facts: no
connection: local
tasks:
- name: cloudformation
cloudformation:
state: present
region: "{{ Region }}"
template: ../../cloudformation/packer.json
stack_name: Packer
register: cloudformation
- name: epoch
shell: date +%s
register: epoch
- name: get amazonlinux ami
shell: >
aws ec2 describe-images
--region {{ Region }}
--owners amazon
--filters "Name=name,Values=amzn-ami-hvm-*-gp2"
--query 'reverse(sort_by(Images,&CreationDate))[0].ImageId'
--output text
register: amazonlinux_image_id
- name: packer
shell: >
packer build
-var 'Region={{ Region }}'
-var 'VpcId={{ cloudformation.stack_outputs.Vpc }}'
-var 'SubnetId={{ cloudformation.stack_outputs.Subnet }}'
-var 'Name={{ Name }}'
-var 'Epoch={{ epoch.stdout }}'
-var 'SourceAmi={{ amazonlinux_image_id.stdout }}'
../../packer/ansible-amazonlinux.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment