Authored by root

确保ttl参数值保持不变以及添加YES确认

---
- hosts: localhost
vars_prompt:
- name: "confirmation"
prompt: "Modify DNS record . Please Enter YES to continue."
private: no
vars_files:
- extra_vars/all.yml
vars:
qcloud_key: "{{ lookup('hashi_vault', 'secret=yoho/ops/qcloud token='+'{{vault.token}}'+' url='+'{{vault.server}}') }}"
tasks:
- name: "make sure user type YES to confirm"
fail:
msg: "user do not type YES"
when: confirmation != 'YES'
- name: 修改域名映射的IP或CNAME
domain_modify:
secretId: "{{ qcloud_key.SecretId }}"
secretKey: "{{ qcloud_key.SecretKey }}"
domain_name: "www.yohotest.xyz"
#value: "java-public-lb-862332839.cn-north-1.elb.amazonaws.com.cn"
value: '1.1.1.1'
value: '1.11.11.22'
... ...
... ... @@ -67,6 +67,8 @@ def dns_inqure(SecretId,SecretKey,domain_name,value):
ret["recordType_old"] = lines["type"]
ret["recordType_new"] = recordType
ret["recordLine"] = lines["line"]
ret["ttl"] = lines["ttl"]
#ret["mx"] = lines["mx"]
ret["code"] = 0
break
else:
... ... @@ -86,12 +88,12 @@ def dns_inqure(SecretId,SecretKey,domain_name,value):
'''
通过调用接口RecordModify修改域名解析记录
'''
def dns_modify(SecretId,SecretKey,domain_name,value,subDomain,domain,recordType,recordId,recordLine):
def dns_modify(SecretId,SecretKey,domain_name,value,subDomain,domain,recordType,recordId,recordLine,ttl):
ret = {}
# 调用域名解析接口RecordModify修改域名解析记录
try:
domain_modify_api = QcloudApi(secretId=SecretId,secretKey=SecretKey)
dns_info = domain_modify_api.do_query(params={'Action':'RecordModify','domain':domain,'recordId':recordId,'subDomain':subDomain,'recordType':recordType,'recordLine':recordLine,'value':value})
dns_info = domain_modify_api.do_query(params={'Action':'RecordModify','domain':domain,'recordId':recordId,'subDomain':subDomain,'recordType':recordType,'recordLine':recordLine,'value':value,'ttl':ttl})
ret["code"] = dns_info["code"]
ret["err"] = dns_info['message']
except Exception,e:
... ... @@ -144,7 +146,7 @@ def run_module():
module.exit_json(**result)
# 非check模式下执行修改接口 执行语句:ansible-playbook playbooks/domain.modify.yml
else:
modify_result = dns_modify(secretId,secretKey,domain_name, value,ret["subDomain"],ret["domain"],ret["recordType_new"],ret["recordId"],ret["recordLine"])
modify_result = dns_modify(secretId,secretKey,domain_name, 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
... ...