Authored by chunhua.zhang

modify

... ... @@ -6,7 +6,7 @@
vars_prompt:
- name: "confirmation"
prompt: "Modify DNS record . Please Enter YES to continue."
prompt: "Start to change . Please Enter YES to continue."
private: no
vars_files:
... ... @@ -21,9 +21,9 @@
msg: "user do not type YES"
when: confirmation != 'YES'
- name: 修改域名映射的IP或CNAME
- name: 修改java域名解析
domain_modify:
secretId: "{{ qcloud_key.SecretId }}"
secretKey: "{{ qcloud_key.SecretKey }}"
domain_name: "{{ domain_name }}"
value: "{{ new_record }}"
domain_name: "api.yoho.cn,service.yoho.cn,union.yoho.cn,webunion.yohobuy.com"
value: "java-public-lb-862332839.cn-north-1.elb.amazonaws.com.cn"
... ...
... ... @@ -10,7 +10,7 @@ ANSIBLE_METADATA = {
DOCUMENTATION = '''
---
module: domain_modify
short_description: 修改域名解析
short_description: 修改域名解析(支持同时修改多个域名到一个解析值,域名以逗号分隔)
'''
EXAMPLES = '''
... ... @@ -21,14 +21,14 @@ EXAMPLES = '''
domain_modify:
secretId: "{{ qcloud_key.SecretId }}"
secretKey: "{{ qcloud_key.SecretKey }}"
domain_name: "switch.test.yohops.com"
domain_name: "www.yohotest.xyz,*.yohotest.xyz"
value: "1.2.3.4"
- name: "修改域名对应的CNAME"
domain_modify:
secretId: "{{ qcloud_key.SecretId }}"
secretKey: "{{ qcloud_key.SecretKey }}"
domain_name: "switch.test.yohops.com"
domain_name: "2.yohotest.xyz"
value: "cname.dnspod.com."
'''
... ... @@ -136,23 +136,43 @@ def run_module():
secretId = module.params['secretId']
secretKey = module.params['secretKey']
domain_name = module.params['domain_name']
value = module.params['value']
value = module.params['value'].strip()
domain_name_list = domain_name.split(',')
rets = {}
message_list = []
for domain_name in domain_name_list:
domain_name = domain_name.strip()
ret = dns_inqure(secretId,secretKey,domain_name,value)
if ret['code'] != 0:
module.fail_json(msg='查询失败: code: %s err: %s' % (ret["code"],ret['err']), **result)
result['message'] = {"需修改解析的DNS":domain_name ,"修改之前的解析地址":ret["value_old"],"修改之前的记录类型":ret["recordType_old"],"修改之后的解析地址":ret["value"] ,"修改之后的记录类型":ret["recordType_new"]}
messages = {"需修改解析的DNS":domain_name ,"修改之前的解析地址":ret["value_old"],"修改之前的记录类型":ret["recordType_old"],"修改之后的解析地址":ret["value"] ,"修改之后的记录类型":ret["recordType_new"]}
message_list.append(messages)
result['message'] = message_list
if ret["value_old"] == ret["value"]:
module.fail_json(msg='Modify Failed: 修改的解析与原解析一致', **result)
rets[domain_name] = ret
# check模式下只执行查询接口 执行语句:ansible-playbook playbooks/domain.modify.yml -e '{"domain_name":"www.yohotest.xyz","new_record":"1.2.3.4"}' --check -vvv
if module.check_mode:
#result['response'] = ret
module.exit_json(**result)
# 非check模式下执行修改接口 执行语句:ansible-playbook playbooks/domain.modify.yml -e '{"domain_name":"www.yohotest.xyz","new_record":"1.2.3.4"}'
else:
modify_result = dns_modify(secretId,secretKey,domain_name, ret["value"],ret["subDomain"],ret["domain"],ret["recordType_new"],ret["recordId"],ret["recordLine"],ret["ttl"])
for domain_name in domain_name_list:
domain_name = domain_name.strip()
value = rets[domain_name]["value"]
subDomain = rets[domain_name]["subDomain"]
domain = rets[domain_name]["domain"]
recordType = rets[domain_name]["recordType_new"]
recordId = rets[domain_name]["recordId"]
recordLine = rets[domain_name]["recordLine"]
ttl = rets[domain_name]["ttl"]
modify_result = dns_modify(secretId,secretKey,domain_name,value,subDomain,domain,recordType,recordId,recordLine,ttl)
if modify_result['code'] != 0:
module.fail_json(msg='Modify Failed: code: %i, err: %s' % (modify_result['code'], modify_result['err']), **result)
result['changed'] = True
... ...