�
�Udac @` s d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d d
l Z d d
l
Z
d d
l Z d d
l Z d d l
m Z m Z d d l m Z d d
l m Z d d l m Z d d l m Z d e f d � � YZ d � Z e d k re � n d
S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bysW
---
module: dnsmadeeasy
version_added: "1.3"
short_description: Interface with dnsmadeeasy.com (a DNS hosting service).
description:
- >
Manages DNS records via the v2 REST API of the DNS Made Easy service. It handles records only; there is no manipulation of domains or
monitor/account support yet. See: U(https://www.dnsmadeeasy.com/integration/restapi/)
options:
account_key:
description:
- Account API Key.
required: true
account_secret:
description:
- Account Secret Key.
required: true
domain:
description:
- Domain to work with. Can be the domain name (e.g. "mydomain.com") or the numeric ID of the domain in DNS Made Easy (e.g. "839989") for faster
resolution
required: true
sandbox:
description:
- Decides if the sandbox API should be used. Otherwise (default) the production API of DNS Made Easy is used.
type: bool
default: 'no'
version_added: 2.7
record_name:
description:
- Record name to get/create/delete/update. If record_name is not specified; all records for the domain will be returned in "result" regardless
of the state argument.
record_type:
description:
- Record type.
choices: [ 'A', 'AAAA', 'CNAME', 'ANAME', 'HTTPRED', 'MX', 'NS', 'PTR', 'SRV', 'TXT' ]
record_value:
description:
- >
Record value. HTTPRED: <redirection URL>, MX: <priority> <target name>, NS: <name server>, PTR: <target name>,
SRV: <priority> <weight> <port> <target name>, TXT: <text value>"
- >
If record_value is not specified; no changes will be made and the record will be returned in 'result'
(in other words, this module can be used to fetch a record's current id, type, and ttl)
record_ttl:
description:
- record's "Time to live". Number of seconds the record remains cached in DNS servers.
default: 1800
state:
description:
- whether the record should exist or not
required: true
choices: [ 'present', 'absent' ]
validate_certs:
description:
- If C(no), SSL certificates will not be validated. This should only be used
on personally controlled sites using self-signed certificates.
type: bool
default: 'yes'
version_added: 1.5.1
monitor:
description:
- If C(yes), add or change the monitor. This is applicable only for A records.
type: bool
default: 'no'
version_added: 2.4
systemDescription:
description:
- Description used by the monitor.
required: true
default: ''
version_added: 2.4
maxEmails:
description:
- Number of emails sent to the contact list by the monitor.
required: true
default: 1
version_added: 2.4
protocol:
description:
- Protocol used by the monitor.
required: true
default: 'HTTP'
choices: ['TCP', 'UDP', 'HTTP', 'DNS', 'SMTP', 'HTTPS']
version_added: 2.4
port:
description:
- Port used by the monitor.
required: true
default: 80
version_added: 2.4
sensitivity:
description:
- Number of checks the monitor performs before a failover occurs where Low = 8, Medium = 5,and High = 3.
required: true
default: 'Medium'
choices: ['Low', 'Medium', 'High']
version_added: 2.4
contactList:
description:
- Name or id of the contact list that the monitor will notify.
- The default C('') means the Account Owner.
required: true
default: ''
version_added: 2.4
httpFqdn:
description:
- The fully qualified domain name used by the monitor.
version_added: 2.4
httpFile:
description:
- The file at the Fqdn that the monitor queries for HTTP or HTTPS.
version_added: 2.4
httpQueryString:
description:
- The string in the httpFile that the monitor queries for HTTP or HTTPS.
version_added: 2.4
failover:
description:
- If C(yes), add or change the failover. This is applicable only for A records.
type: bool
default: 'no'
version_added: 2.4
autoFailover:
description:
- If true, fallback to the primary IP address is manual after a failover.
- If false, fallback to the primary IP address is automatic after a failover.
type: bool
default: 'no'
version_added: 2.4
ip1:
description:
- Primary IP address for the failover.
- Required if adding or changing the monitor or failover.
version_added: 2.4
ip2:
description:
- Secondary IP address for the failover.
- Required if adding or changing the failover.
version_added: 2.4
ip3:
description:
- Tertiary IP address for the failover.
version_added: 2.4
ip4:
description:
- Quaternary IP address for the failover.
version_added: 2.4
ip5:
description:
- Quinary IP address for the failover.
version_added: 2.4
notes:
- The DNS Made Easy service requires that machines interacting with the API have the proper time and timezone set. Be sure you are within a few
seconds of actual time by using NTP.
- This module returns record(s) and monitor(s) in the "result" element when 'state' is set to 'present'.
These values can be be registered and used in your playbooks.
- Only A records can have a monitor or failover.
- To add failover, the 'failover', 'autoFailover', 'port', 'protocol', 'ip1', and 'ip2' options are required.
- To add monitor, the 'monitor', 'port', 'protocol', 'maxEmails', 'systemDescription', and 'ip1' options are required.
- The monitor and the failover will share 'port', 'protocol', and 'ip1' options.
requirements: [ hashlib, hmac ]
author: "Brice Burgess (@briceburg)"
s/
# fetch my.com domain records
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
register: response
# create / ensure the presence of a record
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
# update the previously created record
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_value: 192.0.2.23
# fetch a specific record
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
register: response
# delete a record / ensure it is absent
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
record_type: A
state: absent
record_name: test
# Add a failover
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
failover: True
ip1: 127.0.0.2
ip2: 127.0.0.3
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
failover: True
ip1: 127.0.0.2
ip2: 127.0.0.3
ip3: 127.0.0.4
ip4: 127.0.0.5
ip5: 127.0.0.6
# Add a monitor
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
monitor: yes
ip1: 127.0.0.2
protocol: HTTP # default
port: 80 # default
maxEmails: 1
systemDescription: Monitor Test A record
contactList: my contact list
# Add a monitor with http options
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
monitor: yes
ip1: 127.0.0.2
protocol: HTTP # default
port: 80 # default
maxEmails: 1
systemDescription: Monitor Test A record
contactList: 1174 # contact list id
httpFqdn: http://my.com
httpFile: example
httpQueryString: some string
# Add a monitor and a failover
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
failover: True
ip1: 127.0.0.2
ip2: 127.0.0.3
monitor: yes
protocol: HTTPS
port: 443
maxEmails: 1
systemDescription: monitoring my.com status
contactList: emergencycontacts
# Remove a failover
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
failover: no
# Remove a monitor
- dnsmadeeasy:
account_key: key
account_secret: secret
domain: my.com
state: present
record_name: test
record_type: A
record_value: 127.0.0.1
monitor: no
N( t strftimet gmtime( t
AnsibleModule( t fetch_url( t urlencode( t string_typest DME2c B` s� e Z d � Z d � Z d � Z d � Z d d � Z d � Z d � Z d � Z
d � Z d � Z d
� Z
d � Z d � Z d
� Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z RS( c C` s� | | _ | | _ | | _ | rG d | _ | j j d d | j � n d | _ t | � | _ d | _ d | _ d | _
d | _ d | _ | j j
� s� | j | j � d | _ n d t | j � d | _ d | _ d | _ d S(
Ns) https://api.sandbox.dnsmadeeasy.com/V2.0/t warnings; Sandbox is enabled. All actions are made against the URL %ss! https://api.dnsmadeeasy.com/V2.0/t ids dns/managed/s /recordst monitort contactList( t modulet apit secrett baseurlt warnt strt domaint Nonet
domain_mapt
record_mapt recordst all_recordst contactList_mapt isdigitt getDomainByNamet
record_urlt monitor_urlt contactList_url( t selft apikeyR R t sandboxR ( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyt __init__} s$ c C` sD | j � } | j | � } i | j d 6| d 6| d 6d d 6} | S( Ns x-dnsme-apiKeys x-dnsme-hmacs x-dnsme-requestDates application/jsons content-type( t _get_datet _create_hashR ( R% t currTimet
hashstringt headers( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyt _headers� s
c C` s# t j t j d � t d t � � S( Nt Cs %a, %d %b %Y %H:%M:%S GMT( t localet setlocalet LC_TIMER R ( R% ( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyR) � s c C` s+ t j | j j � | j � t j � j � S( N( t hmact newR t encodet hashlibt sha1t hexdigest( R% t rightnow( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyR* � s c
C` s� | j | } | r2 t | t � r2 t | � } n t | j | d | d | d | j � �\ } } | d d
k r� | j j d d | | d | d f � n y t j | � SWn t
k
r� i SXd S( Nt datat methodR- R i� i� i� t msgs %s returned %s, with body: %s( i� i� i� ( R t
isinstanceR
R R R R. t fail_jsont jsont loadt Exception( R% t resourceR; R: t urlt responset info( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyt query� s
0+
c C` s, | j s | j d � n | j j | t � S( NR ( R t _instMapt domainst gett False( R% t domain_id( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyt getDomain� s c C` s5 | j s | j d � n | j | j j | d � � S( NR i ( R RG RL RI ( R% t domain_name( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyR! � s c C` s | j d d � d S( Ns dns/managedt GETR: ( RF ( R% ( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyt
getDomains� s c C` s, | j s | j d � n | j j | t � S( Nt record( R RG R RI RJ ( R% t record_id( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyt getRecord� s c C` s | j s | j � | _ n | d k rc x5 | j D]* } | d | k r1 | d | k r1 | Sq1 Wt S| d k rx� | j D]� } | d k r� | j d
� d } n( | d k r� | j d
� d } n | } | d | k ry | d | k ry | d | k ry | Sqy Wt St d � � d S( Nt CNAMEt ANAMEt HTTPREDt PTRt namet typet At AAAAt MXt NSt TXTt SRVt i i t values record_type not yet supported( RS RT RU RV ( RY RZ R[ R\ R] R^ ( R t
getRecordsRJ t splitRA ( R% t record_namet record_typet record_valuet resultR` ( ( sI /usr/lib/python2.7/site-packages/ansible/modules/net_tools/dnsmadeeasy.pyt getMatchingRecord� s$ 0c C` s | j | j d � d S( NRN R: ( RF R"