Skip to content

Instantly share code, notes, and snippets.

@gustavomcarmo
Created December 11, 2018 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavomcarmo/41446716d19ed0078ff4bbd89c4061d9 to your computer and use it in GitHub Desktop.
Save gustavomcarmo/41446716d19ed0078ff4bbd89c4061d9 to your computer and use it in GitHub Desktop.
Ansible playbook to find the latest Ubuntu 18.04 LTS (bionic) AMI in AWS.
---
- hosts: localhost
gather_facts: no
vars:
aws_region: "eu-west-2"
tasks:
- name: Find Ubuntu Server 18.04 LTS AMIs
ec2_ami_facts:
region: '{{ aws_region }}'
owners: 099720109477
filters:
name: 'ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*'
register: ec2_ami_facts_result
- name: Store the Ubuntu AMI's data
copy:
content: '{{ (ec2_ami_facts_result.images|sort(attribute="name",reverse=True))[0]|to_nice_json }}'
dest: '{{ aws_region }}/latest-ubuntu-bionic-ami.json'
when: ec2_ami_facts_result.images|length > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment