[root@yyjk ansible]# cat iventory.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cx_Oracle
from pprint import pprint
import csv
import time
import re
import binascii
import json
conn = cx_Oracle.connect('tlcbuser/tlcbuser@192.5.1920.232/tlyy')
cursor = conn.cursor()
xsql="select distinct trim(ipaddr),descp from tlcb_mon_device where devicetype='General Linux' and hasdeployed='1'"
r = cursor.execute(xsql)
#print r
arr=[]
for x in r:
#y=x[1].decode('gbk').encode('utf-8')
#print x[0]
#print x[1]
arr.append(x[0])
b=json.dumps(arr)
c={'test':arr}
d=json.dumps(c)
print d
[root@yyjk ansible]# python /etc/ansible/iventory.py -list
{"test": ["192.16.32.6", "192.16.34.192", "192.16.34.3", "192.16.34.6", "192.16.67.2", "192.16.67.4", "192.16.68.3", "192.16.69.5", "192.2.231.11", "192.2.231.20", "192.2.231.30", "192.2.231.42", "192.2.231.43", "192.2.231.9", "192.2.232.15", "192.2.232.2", "192.2.232.6", "192.2.233.1", "192.2.234.3", "192.2.234.4", "192.2.237.5", "192.2.239.33", "192.2.247.24", "192.2.247.35", "192.2.247.38", "192.2.248.9", "192.3.172.15", "192.3.220.5", "192.3.235.5", "192.3.246.11", "192.168.18.15", "192.168.18.18", "192.16.20.3", "192.16.20.5", "192.16.39.1", "192.2.231.8", "192.2.232.1", "192.2.247.37", "192.2.247.61", "192.2.247.82", "192.3.215.192", "192.3.215.14", "192.3.215.16", "192.3.215.19", "192.3.215.24", "192.3.219.56", "192.3.222.23", "192.3.227.5", "192.3.242.63", "192.3.245.14", "192.3.246.5", "192.3.249.41", "192.3.249.50", "192.3.250.16", "192.3.252.3", "192.168.2.23", "192.168.2.25", "192.16.32.32", "192.16.34.21", "192.16.34.5", "192.16.69.4", "192.16.69.6", "192.2.231.4", "192.2.232.5", "192.2.232.9", "192.2.239.15", "192.2.248.192", "192.3.220.4", "192.3.220.6", "192.3.221.3", "192.3.222.22", "192.3.222.25", "192.3.227.3", "192.3.244.3", "192.3.252.11", "192.16.20.4", "192.16.20.6", "192.16.34.20", "192.16.69.1", "192.16.82.1", "192.2.231.1", "192.2.231.31", "192.2.232.7", "192.2.233.2", "192.2.237.1", "192.2.237.4", "192.2.240.1", "192.2.240.9", "192.3.215.15", "192.3.215.20", "192.3.220.3", "192.3.227.6", "192.3.249.192", "192.3.249.51", "192.168.18.17", "192.16.20.1", "192.16.32.33", "192.16.34.2", "192.16.67.1", "192.16.67.3", "192.2.232.4", "192.2.247.36", "192.2.247.62", "192.2.247.81", "192.2.247.83", "192.3.172.16", "192.3.215.12", "192.3.215.17", "192.3.215.23", "192.3.215.27", "192.3.215.28", "192.3.222.26", "192.3.227.2", "192.168.18.16", "192.168.2.85", "192.16.32.31", "192.16.32.5", "192.16.68.4", "192.16.69.3", "192.16.83.1", "192.2.231.25", "192.2.231.3", "192.2.233.5", "192.2.239.30", "192.2.247.14", "192.3.215.13", "192.3.219.62", "192.3.222.24", "192.3.229.192", "192.3.242.61", "192.3.249.42", "192.3.252.192", "192.3.243.3", "192.16.20.2", "192.16.34.1", "192.16.34.4", "192.16.67.11", "192.2.231.12", "192.2.232.14", "192.2.232.3", "192.2.232.8", "192.2.247.15", "192.2.247.23", "192.2.247.80", "192.2.248.8", "192.3.219.57", "192.3.227.4", "192.3.235.4", "192.3.242.62", "192.3.242.64", "192.3.243.192", "192.3.245.15", "192.3.250.17", "192.3.252.4", "192.168.18.18", "192.168.19.6", "192.168.2.24", "192.168.2.26", "192.168.2.86", "192.16.32.30", "192.16.36.192", "192.16.36.11", "192.16.36.2", "192.16.39.2", "192.16.69.2", "192.16.83.2", "192.2.232.192", "192.2.232.11", "192.2.237.4", "192.2.239.31", "192.2.239.32", "192.2.247.13", "192.2.247.16", "192.2.247.84", "192.2.248.7", "192.3.215.11", "192.3.215.18", "192.3.215.21", "192.3.215.22", "192.3.219.58", "192.3.221.1"]}
[root@yyjk ansible]#
[root@yyjk ansible]# time ansible -i /etc/ansible/iventory.py test -m raw -a "hostname"
192.3.215.22 | SUCCESS | rc=0 >>
eoffice.zjtlcb.com
Shared connection to 192.3.215.22 closed.
192.3.221.1 | SUCCESS | rc=0 >>
shtc-a
Shared connection to 192.3.221.1 closed.
real 1m47.696s
user 0m37.418s
sys 0m15.516s
You have mail in /var/spool/mail/root
跑下来 需要1m47.696s,太慢
通过
filename prepend with @
-f FORKS, --forks=FORKS
specify number of parallel processes to use
(default=5)
-m MODULE_NAME, --module-name=MODULE_NAME
module name to execute (default=command)
-a MODULE_ARGS, --args=MODULE_ARGS
module arguments