ansible inventory.py 脚本
来源:互联网 发布:excel取消数据验证 编辑:程序博客网 时间:2024/06/01 09:51
#!/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(sql): a=readDb(sql) 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]} print host_dict[key]if len(sys.argv) == 3 and (sys.argv[1] == '--list'): groupList(sys.argv[2])elif len(sys.argv) == 3 and (sys.argv[1] == '--host'): hostList(sys.argv[2])else: print "Usage: %s --list sql or --host <hostname>" % sys.argv[0] sys.exit(1)group 函数:[root@node01 ansible]# python p3.py --list 'select ip from tlcb_mon_device'{"test": ["192.168.137.3", "192.168.137.4", "115.236.19.4"]}[root@node01 ansible]# host函数;[root@node01 ansible]# python inventory.py --host '192.168.137.3'{ "ansible_ssh_host": "\u6d4b\u8bd5\u73af\u58831"}
阅读全文
0 0
- ansible inventory.py 脚本
- [ansible] Ansible Inventory Manager
- ansible 动态生成Inventory
- ansible之inventory文件
- ansible动态inventory
- ansible inventory文件 定义host
- ansible的inventory文件含义
- ansible——inventory文件
- ansible动态inventory获取主机列表
- ansible小结(三)Inventory与Patterns
- ansible小结(五)Dynamic Inventory
- Ansible之 Inventory 资源清单介绍
- Ansible之 Inventory 资源清单介绍
- Ansible之 Inventory 资源清单介绍
- Ansible之 Inventory 资源清单介绍
- Ansible之 Inventory 资源清单介绍
- Ansible之 Inventory 资源清单介绍
- Ansible 系列之 Inventory 资源清单介绍
- js购物车
- mysql5.17组复制安装
- oracle中sequence详解
- Android Okhttp缓存:精细化每一个Request的CacheControl缓存控制策略(二)
- 2006年培养学员8万人,每年增长%25,请问按此增长速度,到那一年培训学员人数将达到20万人用for,while,dowhile,实现
- ansible inventory.py 脚本
- mysql数据库show tables 显示表名,但是查询的时候却提示此表不存在
- UEditor 富文本编辑器拓展之-----上传图片至项目之外或资源服务器
- 解决使用tf.slim找不到slim.utils函数问题
- The Monochrome Picture SGU
- switch case的定义
- js 判断是否为空对象
- 关于C++中的虚拟继承的一些总结
- MFS+Keepalived双机高可用热备方案