关于 Ansible 的模块 ⑦ - 命令模块
最编程
2024-04-19 07:16:46
...
ansible的默认模块是command,可以使用-m command指定使用command模块也可以直接省略。
command在远程节点上执行命令和shell模块类似,但不支持$HOME、"<"、">"、"|"、";"、"&"等操作。
1. 常用参数
参数 | 默认值 | 含义 |
cmd | null | 要运行的命令 |
chdir | null | 在运行命令之前,先进入该目录 |
creates | null | 如文件存在,则不运行此步骤 |
removes | null | 如文件存在,则运行此步骤 |
argv | null | 以list而非string模式传递命令 |
free_form | null | shell模块接受一个*形式的命令作为字符串来运行 |
stdin | null | 将命令的stdin直接设置为指定的值 |
stdin_add_newline | true | 是否向标准输入数据追加换行符 |
strip_empty_ends | true | 在结果中去除 stdout/stderr 末尾的空行。 |
warn | 是否启用任务告警 |
2. 使用示例
2.1 简单执行命令
ansible all -m command -a "free -h"
ansible all -a "free -h" #省略-m参数默认就使用command模块
2.2 command模块与shell模块一样支持执行命令前更换目录
ansible all -m command -a "chdir=/tmp cat shell.txt"
2.3 不支持">"等符号
ansible all -m command -a 'echo "this is command test">/tmp/cmd.txt'
上一篇: 29-51 微控制器-LCD1602 液晶显示器实验
下一篇: 伪造CSRF
推荐阅读
-
用于检测机器人的电力载波模块
-
在 "全信息 "智能电站中,电能表与终端传感模块和 Iconcentrator 之间的主要通信技术是什么?
-
用于物联网应用和设计的高性价比载波通信模块 ES1642-C
-
ZH-HPLC/RS485 传输模块在光伏逆变器发电数据采集器中的应用 + 宽带电力线载波 HPLC + 站式智能汇聚终端在分布式光伏并网数据采集与编程中的应用特点
-
基于 LWM2M 协议的 STM32F103 与 M5311NBiot 模块连接 onenet 平台的说明
-
用于 5G 预传输光纤传输的 25G 光模块晶体 SG2016CAN
-
最详细的 Excel 模块 Openpyxl 教程(三)--使用公式
-
Python] 自定义 pip 下载模块的默认安装路径
-
用于前端模块化的 ES 模块
-
西门子 PLC 中各组织模块 OB 的作用 (OB1, OB100 ......)