Skip to content

Instantly share code, notes, and snippets.

@texdc
Created October 6, 2017 21:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texdc/9c94d5bd7cf4938bc1c680846f67e8a3 to your computer and use it in GitHub Desktop.
Save texdc/9c94d5bd7cf4938bc1c680846f67e8a3 to your computer and use it in GitHub Desktop.
Two ansible commands to get the Route53 zone id for a given DNS zone
---
- name: get hosted zone info
route53_facts:
query: hosted_zone
register: zone_info
- name: get zone id
set_fact:
zone_id: "{{ zone.Id | regex_replace('/hostedzone/', '') }}"
when: zone.Name == route53_zone + '.'
with_items: "{{ zone_info.HostedZones }}"
loop_control:
loop_var: zone
@t-readyroc
Copy link

Much cleaner than my jinja mess, which outputs a list, anyway. Great stuff.

new_record_zone_id: "{{ hosted_zones.HostedZones | selectattr('Name', 'equalto', new_record_zone) | map(attribute='Id') | regex_replace('\/hostedzone\/', '') }}"

@pauby
Copy link

pauby commented Dec 15, 2020

route53_facts has been deprecated and route53_info is now what should be used instead.

But thank you for this. Saved me a lot of time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment