动态inventory脚本必须支如下两个命令行参数
来源:互联网 发布:众人皆知的意思 编辑:程序博客网 时间:2024/06/05 04:23
#!/usr/bin/env python# -*- coding: utf-8 -*-import jsonimport sysimport cx_Oracle# def group():# info_dict = {"all":["192.168.137.3","192.168.137.4"]}# print json.dumps(info_dict,indent=4)# def host(ip):# info_dict = {"192.168.137.3":{"ansible_ssh_host":"测试环境1"},"192.168.1.6":{"ansible_ssh_host":"测试环境2"}}# print json.dumps(info_dict[ip],indent=4)# if len(sys.argv) == 2 and (sys.argv[1] == '--list'):# group()# elif len(sys.argv) == 3 and (sys.argv[1] == '--host'):# host(sys.argv[2])# else:# print "Usage: %s --list or --host <hostname>" % sys.argv[0]# sys.exit(1)def readDb(sql): conn = cx_Oracle.connect('system/oracle@192.168.137.2/serv') cursor = conn.cursor() xsql=sql print xsql r = cursor.execute(xsql) return rarr1=[]def groupList(): a=readDb('select ip from tlcb_mon_device') for x in a: arr1.append(x[0]) b={'test':arr1} c=json.dumps(b) print carr2=[]host_dict = {}def hostList(key): a=readDb('select * from tlcb_mon_device') for x in a: host_dict[x[0]]={"ansible_ssh_host":x[0],"ansible_ssh_desc":x[1]} return host_dict[key]print '------------hostList-----------------------------------------'a=hostList('192.168.137.3')print aprint type(a)print a['ansible_ssh_host']print a['ansible_ssh_desc'].decode('gbk').encode('utf-8')print len(a['ansible_ssh_desc'])print '---------------groupList--------------------------------------'groupList()C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a20.py------------hostList-----------------------------------------select * from tlcb_mon_device{'ansible_ssh_host': '192.168.137.3', 'ansible_ssh_desc': '\xb2\xe2\xca\xd4\xd6\xf7\xbb\xfa'}<type 'dict'>192.168.137.3测试主机8---------------groupList--------------------------------------select ip from tlcb_mon_device{"test": ["192.168.137.3", "192.168.137.4", "115.236.19.4"]}Process finished with exit code 0
阅读全文
0 0
- 动态inventory脚本必须支如下两个命令行参数
- ansible inventory.py 脚本
- ansible 动态生成Inventory
- ansible动态inventory
- Groovy 脚本接受命令行参数
- TCL脚本读取命令行参数
- 命令行参数解析 - Shell 脚本
- 开发动态的Inventory数据源
- 两个action动态传参数
- 两个Action 动态传参数
- 两个Action 动态传参数
- 在Shell脚本中处理命令行参数
- LinuxShell脚本命令行参数的写法
- autoit 编译脚本与命令行参数
- Shell脚本学习-命令行参数处理
- Bash脚本之命令行参数$@和$*
- shell脚本里读取命令行参数
- 命令行和ant脚本的参数传递
- 注解
- 云监控介绍
- 自媒体快速写文章和获取素材的几大途径
- Java网络编程
- C++之回调函数——转载
- 动态inventory脚本必须支如下两个命令行参数
- 哈希(3)
- Retrofit框架请求SOAP WebService
- test
- java内存泄露
- Effective Java中文第四章第18节(个人渣翻)
- TabLayout标题按钮
- priority queue
- 哈希(4)