import ansible.runner
import ansible.playbook
import ansible.inventory
from ansible import callbacks
from ansible import utils
遠端執行指令
hosts = [hosts]
host_inventory = ansible.inventory.Inventory(hosts)
pm = ansible.runner.Runner(module_name = 'command',module_args = cmds,timeout = 600,inventory = host_inventory,subset = 'all')
out = pm.run()
遠端傳輸檔案
pm = ansible.runner.Runner(module_name = 'copy',module_args = 'src='+file_path+' dest='+file_path+' mode=0644',timeout = 600,inventory = host_inventory,subset = 'all')
本文轉自aaron428 51CTO部落格,原文連結:http://blog.51cto.com/aaronsa/2057442,如需轉載請自行聯系原作者