提取ansible hosts分组IP
提取ansible hosts分组IP#!/usr/bin/env python##执行方式 python2.7 1.py bbg nnjiimport ConfigParserimport reimport sysroom = sys.argv[1: ] ##获取room分组for x in room:config = ConfigParser.RawConfigParser(allow_no_
·
提取ansible hosts分组IP
有时候机器太多,想预先看看需要执行的机器IP,看看有没有漏的,注释的机器不会列出来。默认查看ansible hosts文件路径/etc/ansible/hosts
#!/usr/bin/env python
##执行方式 python2.7 1.py bbg nnji
import ConfigParser
import re
import sys
room = sys.argv[1: ] ##获取room分组
for x in room:
config = ConfigParser.RawConfigParser(allow_no_value=True) ##必须带TRUE参数
config.read("/etc/ansible/hosts") ##读取配置文件
print x
str = config.items(x) ##读取配置组下内容
for k,v in str: ##字典的方式展示
str = re.findall("ansible_host=(.+?)ansible_user",v) ##正则匹配ip
for i in str:
print i
更多推荐
已为社区贡献1条内容
所有评论(0)