Created
October 6, 2017 21:06
-
-
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
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
--- | |
- 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 |
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
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\/', '') }}"