...
|
...
|
@@ -52,6 +52,9 @@ def dns_inqure(SecretId,SecretKey,domain_name,value): |
|
|
# Comment: 目前仅支持IP和CNAME的修改
|
|
|
pattern = re.compile(r'(\d+\.\d+\.\d+\.\d+)')
|
|
|
recordType = "A" if pattern.match(value) else "CNAME"
|
|
|
if recordType == "CNAME":
|
|
|
if not value.endswith('.'):
|
|
|
value += '.'
|
|
|
# 通过调用域名解析接口RecordList来获取待修改的域名解析记录值(调用修改域名解析接口时必须要传入的参数值)
|
|
|
try:
|
|
|
domaininfo_query = QcloudApi(secretId=SecretId,secretKey=SecretKey)
|
...
|
...
|
@@ -65,6 +68,7 @@ def dns_inqure(SecretId,SecretKey,domain_name,value): |
|
|
ret["subDomain"] = subDomain
|
|
|
ret["domain"] = domain
|
|
|
ret["value_old"] = lines["value"]
|
|
|
ret["value"] = value
|
|
|
ret["recordType_old"] = lines["type"]
|
|
|
ret["recordType_new"] = recordType
|
|
|
ret["recordLine"] = lines["line"]
|
...
|
...
|
@@ -138,8 +142,8 @@ def run_module(): |
|
|
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"],"修改之后的解析地址":value ,"修改之后的记录类型":ret["recordType_new"]}
|
|
|
if ret["value_old"] == value:
|
|
|
result['message'] = {"需修改解析的DNS":domain_name ,"修改之前的解析地址":ret["value_old"],"修改之前的记录类型":ret["recordType_old"],"修改之后的解析地址":ret["value"] ,"修改之后的记录类型":ret["recordType_new"]}
|
|
|
if ret["value_old"] == ret["value"]:
|
|
|
module.fail_json(msg='Modify Failed: 修改的解析与原解析一致', **result)
|
|
|
|
|
|
# check模式下只执行查询接口 执行语句:ansible-playbook playbooks/domain.modify.yml -e '{"domain_name":"www.yohotest.xyz","new_record":"1.2.3.4"}' --check -vvv
|
...
|
...
|
@@ -148,7 +152,7 @@ def run_module(): |
|
|
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, value,ret["subDomain"],ret["domain"],ret["recordType_new"],ret["recordId"],ret["recordLine"],ret["ttl"])
|
|
|
modify_result = dns_modify(secretId,secretKey,domain_name, ret["value"],ret["subDomain"],ret["domain"],ret["recordType_new"],ret["recordId"],ret["recordLine"],ret["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
|
...
|
...
|
|