Skip to content

Commit

Permalink
route53: Restore support for zero weighted DNS records (ansible-colle…
Browse files Browse the repository at this point in the history
…ctions#1379)

route53: Restore support for zero weighted DNS records

SUMMARY
In ansible-collections#1117 (comment) and https://github.com/ansible-collections/community.aws/pull/1117/files#r869391659 this line was recommended to be simplified, but not any will also return true if weight_in has a value of 0, not only when it is None
Fixes ansible-collections#1378
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
route53
ADDITIONAL INFORMATION

Previously it was possible to create weighted records with a weight of 0. Currently the playbook below returns the error:
You have specified identifier which makes sense only if you specify one of: weight, region, geo_location or failover.

- name: Bug demo
  hosts: localhost
  tasks:
    - name: Set 0 weight for old env
      route53:
        wait: yes
        ttl: '5'
        type: 'CNAME'
        identifier: old
        overwrite: yes
        record: 'record.example.com.'
        zone: 'example.com.'
        value: 'record-old.example.com.'
        weight: '0'
        state: present

Reviewed-by: Mark Chappell <None>

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@9195021
  • Loading branch information
wp-davisona authored and goneri committed Sep 21, 2022
1 parent 6310b5d commit d1c04ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/modules/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def main():
if command_in == 'create' or command_in == 'delete':
if alias_in and len(value_in) != 1:
module.fail_json(msg="parameter 'value' must contain a single dns name for alias records")
if not any([weight_in, region_in, failover_in, geo_location]) and identifier_in is not None:
if (weight_in is None and region_in is None and failover_in is None and geo_location is None) and identifier_in is not None:
module.fail_json(msg="You have specified identifier which makes sense only if you specify one of: weight, region, geo_location or failover.")

retry_decorator = AWSRetry.jittered_backoff(
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/targets/route53/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,42 @@
- weighted_record is not failed
- weighted_record is not changed

- name: 'Create a zero weighted record'
route53:
state: present
zone: '{{ zone_one }}'
record: 'zero_weighted.{{ zone_one }}'
type: CNAME
value: 'zid_test.{{ zone_one }}'
overwrite: True
identifier: "host1@www"
weight: 0
region: '{{ omit }}'
register: weighted_record
- name: 'This should be changed'
assert:
that:
- weighted_record is not failed
- weighted_record is changed

- name: 'Re-Create a zero weighted record'
route53:
state: present
zone: '{{ zone_one }}'
record: 'zero_weighted.{{ zone_one }}'
type: CNAME
value: 'zid_test.{{ zone_one }}'
overwrite: True
identifier: "host1@www"
weight: 0
region: '{{ omit }}'
register: weighted_record
- name: 'This should not be changed'
assert:
that:
- weighted_record is not failed
- weighted_record is not changed

#Test Geo Location - Continent Code
- name: Create a record with geo_location - continent_code (check_mode)
route53:
Expand Down

0 comments on commit d1c04ae

Please sign in to comment.