...
|
...
|
@@ -5,7 +5,7 @@ import json |
|
|
|
|
|
# dingding
|
|
|
DING = "https://oapi.dingtalk.com/robot/send?access_token=31cf1a526c98862b7945e561c5a0d857a069350dbee0e807074b83b39fa1e1af"
|
|
|
ansible_url = "https://ansible.yohops.com/api/v2"
|
|
|
ansible_url = "http://ansible.yohops.com/api/v2"
|
|
|
ansible_user = "chunhua.zhang"
|
|
|
ansible_password = "Zch@2019"
|
|
|
|
...
|
...
|
@@ -28,7 +28,7 @@ def ansible_tower_process(newmaster, failmaster): |
|
|
## az1, az2, az3
|
|
|
for inventory in [6, 5, 4]:
|
|
|
extra_var = {}
|
|
|
r = requests.get(ansible_url + "/inventories/%i" %inventory, auth=(ansible_user, ansible_password))
|
|
|
r = requests.get(ansible_url + "/inventories/%i/" %inventory, auth=(ansible_user, ansible_password))
|
|
|
inventory_vars = json.loads( r.json()['variables'])
|
|
|
for key in inventory_vars:
|
|
|
# only proccess variable's name starts with db and variable's value equals [failmaster]
|
...
|
...
|
@@ -36,17 +36,24 @@ def ansible_tower_process(newmaster, failmaster): |
|
|
extra_var[key] = newmaster
|
|
|
|
|
|
if not extra_var:
|
|
|
print("can not find any variables in all inventory files starts with db and value is %s" %failmaster)
|
|
|
return
|
|
|
print("can not find any variables in inventory:%i starts with db and value is %s" %(inventory,failmaster))
|
|
|
continue
|
|
|
|
|
|
# update dns
|
|
|
# 1. update dns
|
|
|
extra_var['confirmation'] = 'DNS'
|
|
|
dns_payload = {}
|
|
|
dns_payload['inventory'] = inventory
|
|
|
|
|
|
dns_payload['extra_vars'] = json.dumps(extra_var)
|
|
|
print("start to update dns for inventory: %i , params is: %s" %(inventory, dns_payload))
|
|
|
#r_dns = requests.post(ansible_url + "/api/v2/job_templates/36/launch", json = dns_payload)
|
|
|
r_dns = requests.post(ansible_url + "/job_templates/36/launch/", json = dns_payload, auth=(ansible_user, ansible_password))
|
|
|
|
|
|
# 2. reload cobar
|
|
|
cobar_payload = {}
|
|
|
cobar_payload['inventory'] = inventory
|
|
|
print("start to reload cobar for inventory: %i , params is: %s" %(inventory, cobar_payload))
|
|
|
r_cobar = requests.post(ansible_url + "/job_templates/35/launch/", json = cobar_payload, auth=(ansible_user, ansible_password))
|
|
|
|
|
|
|
|
|
|
|
|
def alert_to_dingding(newmaster, failmaster):
|
...
|
...
|
|