Python ansible常用模块

简介:

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,如需转载请自行联系原作者


相关文章
|
8天前
|
安全 Linux 网络安全
Kali 渗透测试:基于结构化异常处理的渗透-使用Python编写渗透模块(一)
Kali 渗透测试:基于结构化异常处理的渗透-使用Python编写渗透模块(一)
37 2
|
8天前
|
Python Windows 网络安全
Kali 渗透测试:基于结构化异常处理的渗透-使用Python编写渗透模块(二)
Kali 渗透测试:基于结构化异常处理的渗透-使用Python编写渗透模块(二)
30 2
|
7天前
|
Python
Datetime模块应用:Python计算上周周几对应的日期
Datetime模块应用:Python计算上周周几对应的日期
33 1
|
6天前
|
JSON Java Linux
python有用的模块
python有用的模块
|
7天前
|
安全 测试技术 数据库
Python编程--sys模块及OS模块简单用例
Python编程--sys模块及OS模块简单用例
10 1
|
7天前
|
JSON 数据格式 Python
Python编程:利用JSON模块编程验证用户
Python编程:利用JSON模块编程验证用户
13 1
|
8天前
|
网络安全 开发工具 iOS开发
macOS 系统安装Python-nmap模块
macOS 系统安装Python-nmap模块
18 2
|
8天前
|
数据处理 Python
Python编程-利用datetime模块生成当前年份之前指定的间隔所有年份的日期列表和csv文件
Python编程-利用datetime模块生成当前年份之前指定的间隔所有年份的日期列表和csv文件
11 1
|
8天前
|
数据处理 Python
Python内置时间模块:Datetime实例详解(一)
Python内置时间模块:Datetime实例详解(一)
17 1
|
1天前
|
Python
Python中tqdm模块的常用方法和示例
`tqdm` 是一个快速、可扩展的Python进度条库,适用于长循环中添加进度提示。通过封装迭代器 `tqdm(iterator)`,可以轻松实现进度显示。支持自定义描述、宽度及嵌套进度条,适用于多种迭代对象。在Jupyter notebook中,可自动调整显示效果。
7 0