#!/usr/bin/python
# -*- coding:UTF-8 -*-
import os
import sys
import commands
import MySQLdb
import json
#获取全部的fact并以主机名为文件名存到某个路径下
(status, output) = commands.getstatusoutput('ansible all -m setup --tree /root/hosts')
#print status,'++++++++++++++'
#为/root/hosts下文件加入.json后缀
def rename_file(path):
# -*- coding:UTF-8 -*-
import os
import sys
import commands
import MySQLdb
import json
#获取全部的fact并以主机名为文件名存到某个路径下
(status, output) = commands.getstatusoutput('ansible all -m setup --tree /root/hosts')
#print status,'++++++++++++++'
#为/root/hosts下文件加入.json后缀
def rename_file(path):
for file in os.listdir(path):
if os.path.isfile(os.path.join(path,file)) == True:
if file.find('.json') < 0:
newname = file + '.json'os.rename(os.path.join(path,file),os.path.join(path,newname))print file,'ok'
else:
continue
else: