---
|
- name: Get all custom AMI for that environment / version
|
environment:
|
AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}"
|
AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}"
|
AWS_DEFAULT_REGION: "{{aws_region_loop|d(aws_region)}}"
|
ec2_ami_facts:
|
owner: self
|
filters:
|
tag:env_type: "{{ env_type }}"
|
tag:version: "{{ osrelease }}"
|
tag:stages: "*{{ custom_image_stage | d('unknown') }}*"
|
register: amifacts
|
|
# by default do not skip docker tasks
|
- set_fact:
|
skip_packer_tasks: false
|
|
- when: amifacts.images | length > 0
|
block:
|
# For now, use one image for all the machines of the config. Start simple.
|
# TODO: add another tag to the image to apply it to specific group of hosts in the config
|
- set_fact:
|
custom_image: "{{ amifacts | json_query('images[]') | sort(attribute='creation_date') | last }}"
|
|
- name: Print debug information about the custom image used
|
debug:
|
var: custom_image
|
|
- name: Skip packer tasks if the tags in the image say to do so
|
set_fact:
|
skip_packer_tasks: true
|
when:
|
- custom_image is defined
|
- custom_image.tags.skip_packer_tasks is defined
|
- custom_image.tags.skip_packer_tasks in ['true', 'yes', 'True', 'Yes']
|