Created
December 11, 2018 19:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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