且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python ansible常用模块

更新时间:2022-09-19 22:12:42

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()

远程传输文件
hosts = [hosts]
host_inventory = ansible.inventory.Inventory(hosts)
pm = ansible.runner.Runner(module_name = 'copy',module_args = 'src='+file_path+' dest='+file_path+' mode=0644',timeout = 600,inventory = host_inventory,subset = 'all')
out = pm.run()


本文转自 aaron428 51CTO博客,原文链接:http://blog.51cto.com/aaronsa/2057442