标签:nginx devops res HERE 虚拟 term new and url
1.起因: 内网环境整体架构如下
2.优化方案思路如下;
1.程序和对应的基础运维服务程序以及完全记录在CMDB中,切对应有应用名称和使用IP地址对应关系;
2.cmdb 提供对应的应用IP Restfu接口;
3.通过脚本读取程序接口读取应用名称和对应ip地址,使用ansible 模块执行对应的ip地址上 部署的应用;
4.本实例中cmdb 接口开发大神使用了sql 语句接口调用即可返回对应的数据;
3.脚本内容如下; #!/usr/bin/env python import sys import json import requests import subprocess url = 'http://192.168.1.200:80/sql' data = { 'sql': 'select app.ip,instance.app_name from app,instance where app.instance_id = instance.id and app.ip like "192.168.54.%"'} Put_data = requests.post(url, json=data) Data_text = Put_data.text weatherJSON = json.loads(Data_text) with open('/tmp/Docker_Test_ip_txt','w') as f: ###落地磁盘保存### j = 0 for i in weatherJSON["data"]: j = j + 1 # APP_ip = i['ip'] +" "+ if j == 1 : ansible_host_name = "[Docker-Test]" + "\n" f.write(ansible_host_name) else: APP_ip = i['ip'] + "\n" f.write(APP_ip) APP_name=i['app_name'] + "\n" print "###", APP_name, APP_ip cmd = """ansible -i {}, all -m shell -a 'su - root -c "/chj/app/{}/bin/console restart"' -b """.format(APP_ip.strip(), APP_name.strip()) print cmd p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True) result = p.communicate() print result[0]
标签:nginx devops res HERE 虚拟 term new and url
原文地址:http://blog.51cto.com/breaklinux/2149801