dnsimple: refactor dnsimple module (#42548)

* Update dnsimple-python minimum version to 1.0.0 as it supports API v2 and API v1 is deprecated.
* Update examples.
* Update documentation.

Fixes: #42495

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2018-07-21 08:58:39 +05:30 committed by GitHub
parent bb35973e37
commit b02e0c07d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 51 deletions

View file

@ -1,102 +1,99 @@
#!/usr/bin/python #!/usr/bin/python
#
# Copyright: Ansible Project # Copyright: Ansible Project
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {
'status': ['preview'], 'metadata_version': '1.1',
'supported_by': 'community'} 'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: dnsimple module: dnsimple
version_added: "1.6" version_added: "1.6"
short_description: Interface with dnsimple.com (a DNS hosting service). short_description: Interface with dnsimple.com (a DNS hosting service)
description: description:
- "Manages domains and records via the DNSimple API, see the docs: U(http://developer.dnsimple.com/)" - "Manages domains and records via the DNSimple API, see the docs: U(http://developer.dnsimple.com/)."
notes:
- DNSimple API v1 is deprecated. Please install dnsimple-python>=1.0.0 which uses v2 API.
options: options:
account_email: account_email:
description: description:
- > - Account email. If omitted, the environment variables C(DNSIMPLE_EMAIL) and C(DNSIMPLE_API_TOKEN) will be looked for.
Account email. If omitted, the env variables DNSIMPLE_EMAIL and DNSIMPLE_API_TOKEN will be looked for. - "If those aren't found, a C(.dnsimple) file will be looked for, see: U(https://github.com/mikemaccana/dnsimple-python#getting-started)."
If those aren't found, a C(.dnsimple) file will be looked for, see: U(https://github.com/mikemaccana/dnsimple-python#getting-started)
account_api_token: account_api_token:
description: description:
- Account API token. See I(account_email) for info. - Account API token. See I(account_email) for more information.
domain: domain:
description: description:
- Domain to work with. Can be the domain name (e.g. "mydomain.com") or the numeric ID of the domain in DNSimple. If omitted, a list of domains - Domain to work with. Can be the domain name (e.g. "mydomain.com") or the numeric ID of the domain in DNSimple.
will be returned. - If omitted, a list of domains will be returned.
- If domain is present but the domain doesn't exist, it will be created. - If domain is present but the domain doesn't exist, it will be created.
record: record:
description: description:
- Record to add, if blank a record for the domain will be created, supports the wildcard (*) - Record to add, if blank a record for the domain will be created, supports the wildcard (*).
record_ids: record_ids:
description: description:
- List of records to ensure they either exist or don't exist - List of records to ensure they either exist or do not exist.
type: type:
description: description:
- The type of DNS record to create - The type of DNS record to create.
choices: [ 'A', 'ALIAS', 'CNAME', 'MX', 'SPF', 'URL', 'TXT', 'NS', 'SRV', 'NAPTR', 'PTR', 'AAAA', 'SSHFP', 'HINFO', 'POOL' ] choices: [ 'A', 'ALIAS', 'CNAME', 'MX', 'SPF', 'URL', 'TXT', 'NS', 'SRV', 'NAPTR', 'PTR', 'AAAA', 'SSHFP', 'HINFO', 'POOL' ]
ttl: ttl:
description: description:
- The TTL to give the new record - The TTL to give the new record in seconds.
default: 3600 (one hour) default: 3600
value: value:
description: description:
- Record value - Record value.
- "Must be specified when trying to ensure a record exists" - Must be specified when trying to ensure a record exists.
priority: priority:
description: description:
- Record priority - Record priority.
state: state:
description: description:
- whether the record should exist or not - whether the record should exist or not.
choices: [ 'present', 'absent' ] choices: [ 'present', 'absent' ]
solo: solo:
description: description:
- Whether the record should be the only one for that record type and record name. Only use with state=present on a record - Whether the record should be the only one for that record type and record name.
- Only use with C(state) is set to C(present) on a record.
requirements: [ dnsimple ] type: 'bool'
requirements:
- "dnsimple >= 1.0.0"
author: "Alex Coomans (@drcapulet)" author: "Alex Coomans (@drcapulet)"
''' '''
EXAMPLES = ''' EXAMPLES = '''
# authenticate using email and API token and fetch all domains - name: Authenticate using email and API token and fetch all domains
- dnsimple: dnsimple:
account_email: test@example.com account_email: test@example.com
account_api_token: dummyapitoken account_api_token: dummyapitoken
delegate_to: localhost delegate_to: localhost
# fetch my.com domain records - name: Fetch my.com domain records
- dnsimple: dnsimple:
domain: my.com domain: my.com
state: present state: present
delegate_to: localhost delegate_to: localhost
register: records register: records
# delete a domain - name: Delete a domain
- dnsimple: dnsimple:
domain: my.com domain: my.com
state: absent state: absent
delegate_to: localhost delegate_to: localhost
# create a test.my.com A record to point to 127.0.0.01 - name: Create a test.my.com A record to point to 127.0.0.1
- dnsimple: dnsimple:
domain: my.com domain: my.com
record: test record: test
type: A type: A
@ -104,14 +101,15 @@ EXAMPLES = '''
delegate_to: localhost delegate_to: localhost
register: record register: record
# and then delete it - name: Delete record using record_ids
- dnsimple: dnsimple:
domain: my.com domain: my.com
record_ids: '{{ record["id"] }}' record_ids: '{{ record["id"] }}'
state: absent
delegate_to: localhost delegate_to: localhost
# create a my.com CNAME record to example.com - name: Create a my.com CNAME record to example.com
- dnsimple: dnsimple:
domain: my.com domain: my.com
record: '' record: ''
type: CNAME type: CNAME
@ -119,8 +117,8 @@ EXAMPLES = '''
state: present state: present
delegate_to: localhost delegate_to: localhost
# change it's ttl - name: change TTL value for a record
- dnsimple: dnsimple:
domain: my.com domain: my.com
record: '' record: ''
type: CNAME type: CNAME
@ -129,8 +127,8 @@ EXAMPLES = '''
state: present state: present
delegate_to: localhost delegate_to: localhost
# and delete the record - name: Delete the record
- dnsimple: dnsimple:
domain: my.com domain: my.com
record: '' record: ''
type: CNAME type: CNAME
@ -139,10 +137,14 @@ EXAMPLES = '''
delegate_to: localhost delegate_to: localhost
''' '''
RETURN = r"""# """
import os import os
from distutils.version import LooseVersion
try: try:
from dnsimple import DNSimple from dnsimple import DNSimple
from dnsimple.dnsimple import __version__ as dnsimple_version
from dnsimple.dnsimple import DNSimpleException from dnsimple.dnsimple import DNSimpleException
HAS_DNSIMPLE = True HAS_DNSIMPLE = True
except ImportError: except ImportError:
@ -176,6 +178,10 @@ def main():
if not HAS_DNSIMPLE: if not HAS_DNSIMPLE:
module.fail_json(msg="dnsimple required for this module") module.fail_json(msg="dnsimple required for this module")
if LooseVersion(dnsimple_version) < LooseVersion('1.0.0'):
module.fail_json(msg="Current version of dnsimple Python module [%s] uses 'v1' API which is deprecated."
" Please upgrade to version 1.0.0 and above to use dnsimple 'v2' API." % dnsimple_version)
account_email = module.params.get('account_email') account_email = module.params.get('account_email')
account_api_token = module.params.get('account_api_token') account_api_token = module.params.get('account_api_token')
domain = module.params.get('domain') domain = module.params.get('domain')

View file

@ -659,8 +659,6 @@ lib/ansible/modules/net_tools/basics/uri.py E326
lib/ansible/modules/net_tools/cloudflare_dns.py E317 lib/ansible/modules/net_tools/cloudflare_dns.py E317
lib/ansible/modules/net_tools/cloudflare_dns.py E325 lib/ansible/modules/net_tools/cloudflare_dns.py E325
lib/ansible/modules/net_tools/cloudflare_dns.py E327 lib/ansible/modules/net_tools/cloudflare_dns.py E327
lib/ansible/modules/net_tools/dnsimple.py E325
lib/ansible/modules/net_tools/dnsimple.py E327
lib/ansible/modules/net_tools/haproxy.py E317 lib/ansible/modules/net_tools/haproxy.py E317
lib/ansible/modules/net_tools/haproxy.py E324 lib/ansible/modules/net_tools/haproxy.py E324
lib/ansible/modules/net_tools/haproxy.py E325 lib/ansible/modules/net_tools/haproxy.py E325