`cloudflare_dns`: add support for `comment` and `tags` (#9132)
* `cloudflare_dns`: add support for `comment` and `tags` * `cloudflare_dns`: add return values for `comment`/`tags` fields * `cloudflare_dns`: fix return values samples * `cloudflare_dns`: changelog fragment formatting * `cloudflare_dns`: add missing `version_added` * `cloudflare_dns`: remove explicit `required: false` * `cloudflare_dns`: empty `comment` idempotency fixpull/9190/head
parent
a9449ccc2e
commit
3c23ce4a7b
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- cloudflare_dns - add support for ``comment`` and ``tags`` (https://github.com/ansible-collections/community.general/pull/9132).
|
|
@ -31,7 +31,6 @@ options:
|
||||||
- "You can obtain your API token from the bottom of the Cloudflare 'My Account' page, found here: U(https://dash.cloudflare.com/)."
|
- "You can obtain your API token from the bottom of the Cloudflare 'My Account' page, found here: U(https://dash.cloudflare.com/)."
|
||||||
- Can be specified in E(CLOUDFLARE_TOKEN) environment variable since community.general 2.0.0.
|
- Can be specified in E(CLOUDFLARE_TOKEN) environment variable since community.general 2.0.0.
|
||||||
type: str
|
type: str
|
||||||
required: false
|
|
||||||
version_added: '0.2.0'
|
version_added: '0.2.0'
|
||||||
account_api_key:
|
account_api_key:
|
||||||
description:
|
description:
|
||||||
|
@ -39,13 +38,11 @@ options:
|
||||||
- Required for api keys authentication.
|
- Required for api keys authentication.
|
||||||
- "You can obtain your API key from the bottom of the Cloudflare 'My Account' page, found here: U(https://dash.cloudflare.com/)."
|
- "You can obtain your API key from the bottom of the Cloudflare 'My Account' page, found here: U(https://dash.cloudflare.com/)."
|
||||||
type: str
|
type: str
|
||||||
required: false
|
|
||||||
aliases: [ account_api_token ]
|
aliases: [ account_api_token ]
|
||||||
account_email:
|
account_email:
|
||||||
description:
|
description:
|
||||||
- Account email. Required for API keys authentication.
|
- Account email. Required for API keys authentication.
|
||||||
type: str
|
type: str
|
||||||
required: false
|
|
||||||
algorithm:
|
algorithm:
|
||||||
description:
|
description:
|
||||||
- Algorithm number.
|
- Algorithm number.
|
||||||
|
@ -57,6 +54,11 @@ options:
|
||||||
- Required for O(type=TLSA) when O(state=present).
|
- Required for O(type=TLSA) when O(state=present).
|
||||||
type: int
|
type: int
|
||||||
choices: [ 0, 1, 2, 3 ]
|
choices: [ 0, 1, 2, 3 ]
|
||||||
|
comment:
|
||||||
|
description:
|
||||||
|
- Comments or notes about the DNS record.
|
||||||
|
type: str
|
||||||
|
version_added: 10.1.0
|
||||||
flag:
|
flag:
|
||||||
description:
|
description:
|
||||||
- Issuer Critical Flag.
|
- Issuer Critical Flag.
|
||||||
|
@ -134,6 +136,12 @@ options:
|
||||||
type: str
|
type: str
|
||||||
choices: [ absent, present ]
|
choices: [ absent, present ]
|
||||||
default: present
|
default: present
|
||||||
|
tags:
|
||||||
|
description:
|
||||||
|
- Custom tags for the DNS record.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
version_added: 10.1.0
|
||||||
timeout:
|
timeout:
|
||||||
description:
|
description:
|
||||||
- Timeout for Cloudflare API calls.
|
- Timeout for Cloudflare API calls.
|
||||||
|
@ -191,6 +199,18 @@ EXAMPLES = r'''
|
||||||
value: 127.0.0.1
|
value: 127.0.0.1
|
||||||
api_token: dummyapitoken
|
api_token: dummyapitoken
|
||||||
|
|
||||||
|
- name: Create a record with comment and tags
|
||||||
|
community.general.cloudflare_dns:
|
||||||
|
zone: example.net
|
||||||
|
record: test
|
||||||
|
type: A
|
||||||
|
value: 127.0.0.1
|
||||||
|
comment: Local test website
|
||||||
|
tags:
|
||||||
|
- test
|
||||||
|
- local
|
||||||
|
api_token: dummyapitoken
|
||||||
|
|
||||||
- name: Create a example.net CNAME record to example.com
|
- name: Create a example.net CNAME record to example.com
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
zone: example.net
|
zone: example.net
|
||||||
|
@ -299,6 +319,18 @@ record:
|
||||||
returned: success, except on record deletion
|
returned: success, except on record deletion
|
||||||
type: complex
|
type: complex
|
||||||
contains:
|
contains:
|
||||||
|
comment:
|
||||||
|
description: Comments or notes about the DNS record.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: Domain verification record
|
||||||
|
version_added: 10.1.0
|
||||||
|
comment_modified_on:
|
||||||
|
description: When the record comment was last modified. Omitted if there is no comment.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: "2024-01-01T05:20:00.12345Z"
|
||||||
|
version_added: 10.1.0
|
||||||
content:
|
content:
|
||||||
description: The record content (details depend on record type).
|
description: The record content (details depend on record type).
|
||||||
returned: success
|
returned: success
|
||||||
|
@ -333,7 +365,7 @@ record:
|
||||||
type: bool
|
type: bool
|
||||||
sample: false
|
sample: false
|
||||||
meta:
|
meta:
|
||||||
description: No documentation available.
|
description: Extra Cloudflare-specific information about the record.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
sample: { auto_added: false }
|
sample: { auto_added: false }
|
||||||
|
@ -362,6 +394,19 @@ record:
|
||||||
returned: success
|
returned: success
|
||||||
type: bool
|
type: bool
|
||||||
sample: false
|
sample: false
|
||||||
|
tags:
|
||||||
|
description: Custom tags for the DNS record.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ['production', 'app']
|
||||||
|
version_added: 10.1.0
|
||||||
|
tags_modified_on:
|
||||||
|
description: When the record tags were last modified. Omitted if there are no tags.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: "2025-01-01T05:20:00.12345Z"
|
||||||
|
version_added: 10.1.0
|
||||||
ttl:
|
ttl:
|
||||||
description: The time-to-live for the record.
|
description: The time-to-live for the record.
|
||||||
returned: success
|
returned: success
|
||||||
|
@ -410,9 +455,11 @@ class CloudflareAPI(object):
|
||||||
self.account_email = module.params['account_email']
|
self.account_email = module.params['account_email']
|
||||||
self.algorithm = module.params['algorithm']
|
self.algorithm = module.params['algorithm']
|
||||||
self.cert_usage = module.params['cert_usage']
|
self.cert_usage = module.params['cert_usage']
|
||||||
|
self.comment = module.params['comment']
|
||||||
self.hash_type = module.params['hash_type']
|
self.hash_type = module.params['hash_type']
|
||||||
self.flag = module.params['flag']
|
self.flag = module.params['flag']
|
||||||
self.tag = module.params['tag']
|
self.tag = module.params['tag']
|
||||||
|
self.tags = module.params['tags']
|
||||||
self.key_tag = module.params['key_tag']
|
self.key_tag = module.params['key_tag']
|
||||||
self.port = module.params['port']
|
self.port = module.params['port']
|
||||||
self.priority = module.params['priority']
|
self.priority = module.params['priority']
|
||||||
|
@ -662,7 +709,7 @@ class CloudflareAPI(object):
|
||||||
def ensure_dns_record(self, **kwargs):
|
def ensure_dns_record(self, **kwargs):
|
||||||
params = {}
|
params = {}
|
||||||
for param in ['port', 'priority', 'proto', 'proxied', 'service', 'ttl', 'type', 'record', 'value', 'weight', 'zone',
|
for param in ['port', 'priority', 'proto', 'proxied', 'service', 'ttl', 'type', 'record', 'value', 'weight', 'zone',
|
||||||
'algorithm', 'cert_usage', 'hash_type', 'selector', 'key_tag', 'flag', 'tag']:
|
'algorithm', 'cert_usage', 'hash_type', 'selector', 'key_tag', 'flag', 'tag', 'tags', 'comment']:
|
||||||
if param in kwargs:
|
if param in kwargs:
|
||||||
params[param] = kwargs[param]
|
params[param] = kwargs[param]
|
||||||
else:
|
else:
|
||||||
|
@ -798,6 +845,9 @@ class CloudflareAPI(object):
|
||||||
}
|
}
|
||||||
search_value = None
|
search_value = None
|
||||||
|
|
||||||
|
new_record['comment'] = params['comment'] or None
|
||||||
|
new_record['tags'] = params['tags'] or []
|
||||||
|
|
||||||
zone_id = self._get_zone_id(params['zone'])
|
zone_id = self._get_zone_id(params['zone'])
|
||||||
records = self.get_dns_records(params['zone'], params['type'], search_record, search_value)
|
records = self.get_dns_records(params['zone'], params['type'], search_record, search_value)
|
||||||
# in theory this should be impossible as cloudflare does not allow
|
# in theory this should be impossible as cloudflare does not allow
|
||||||
|
@ -826,6 +876,10 @@ class CloudflareAPI(object):
|
||||||
do_update = True
|
do_update = True
|
||||||
if (params['type'] == 'CNAME') and (cur_record['content'] != new_record['content']):
|
if (params['type'] == 'CNAME') and (cur_record['content'] != new_record['content']):
|
||||||
do_update = True
|
do_update = True
|
||||||
|
if cur_record['comment'] != new_record['comment']:
|
||||||
|
do_update = True
|
||||||
|
if sorted(cur_record['tags']) != sorted(new_record['tags']):
|
||||||
|
do_update = True
|
||||||
if do_update:
|
if do_update:
|
||||||
if self.module.check_mode:
|
if self.module.check_mode:
|
||||||
result = new_record
|
result = new_record
|
||||||
|
@ -856,11 +910,13 @@ def main():
|
||||||
account_email=dict(type='str', required=False),
|
account_email=dict(type='str', required=False),
|
||||||
algorithm=dict(type='int'),
|
algorithm=dict(type='int'),
|
||||||
cert_usage=dict(type='int', choices=[0, 1, 2, 3]),
|
cert_usage=dict(type='int', choices=[0, 1, 2, 3]),
|
||||||
|
comment=dict(type='str'),
|
||||||
hash_type=dict(type='int', choices=[1, 2]),
|
hash_type=dict(type='int', choices=[1, 2]),
|
||||||
key_tag=dict(type='int', no_log=False),
|
key_tag=dict(type='int', no_log=False),
|
||||||
port=dict(type='int'),
|
port=dict(type='int'),
|
||||||
flag=dict(type='int', choices=[0, 1]),
|
flag=dict(type='int', choices=[0, 1]),
|
||||||
tag=dict(type='str', choices=['issue', 'issuewild', 'iodef']),
|
tag=dict(type='str', choices=['issue', 'issuewild', 'iodef']),
|
||||||
|
tags=dict(type='list', elements='str'),
|
||||||
priority=dict(type='int', default=1),
|
priority=dict(type='int', default=1),
|
||||||
proto=dict(type='str'),
|
proto=dict(type='str'),
|
||||||
proxied=dict(type='bool', default=False),
|
proxied=dict(type='bool', default=False),
|
||||||
|
|
Loading…
Reference in New Issue