Ansible 命令执行模块(学习笔记九)

简介: 命令执行模块有四个:command、raw、shell、scriptcommand、raw1、command为系统默认模块,使用时可以直接省略:ansible all -a "pwd"image.

命令执行模块有四个:command、raw、shell、script

command、raw

1、command为系统默认模块,使用时可以直接省略:
ansible all -a "pwd"


img_9aceb74312ae5f20bc6be288cf54251b.png
image.png

2、转换到别的目录中,执行程序,chdir为command模块自带的参数:
ansible all -a "pwd chdir=/tmp"


img_a15cc1ef3d32f74ef29ee9dd1454d7a7.png
image.png

3、command不支持管道命令:


img_12025b6fba05d620249a79555086ded7.png
image.png

4、raw和command类似,两个模块都是调用远程主机的指令,但是raw支持管道命令:
ansible all -m raw -a "cd /tmp;pwd"


img_70b22d9e281cb2e64f23c045f503bf80.png
image.png

shell、script

5、shell模块调用远程主机的指令,支持shell特性,包括执行脚本、管道命令等:
ansible all -m shell -a "cd /tmp;pwd"


img_e9efa62863cddc56a6e1ac1fb0742a89.png
image.png

6、shell直接执行脚本,执行的脚本放在远程主机上:
ansible all -m shell -a "/root/test.sh"


img_6f93763b77f879428fa7c2c069a792ee.png
iamge.png

7、script只能执行脚本,不能调用其他指令,但是script执行的是存放在ansbile管理机上的脚本,并且script不支持管道命令:
ansible all -m script -a "/root/test.sh"

img_6779630f2dd223235c8f30f558fce4b4.png
image.png

8、几个模块中,command是默认模块,建议使用shell,功能较方便,script和shell的区别是一个执行控制端的脚本,一个执行远程端的脚本。

目录
相关文章
|
7月前
|
运维 Shell Linux
Ansible自动化运维工具之常用模块使用实战(5)
Ansible自动化运维工具之常用模块使用实战(5)
|
9月前
|
网络协议 网络安全
Ansible模块介绍——防火墙模块
Ansible模块介绍——防火墙模块
145 0
|
7月前
|
运维 Linux
Ansible自动化运维工具之常用模块使用实战(6)
Ansible自动化运维工具之常用模块使用实战(6)
|
6月前
|
网络安全 数据安全/隐私保护
ansible的get_url模块
ansible的get_url模块
|
6月前
|
存储 Linux Python
ansible手动添加模块
ansible手动添加模块
49 0
|
9月前
|
运维 监控
【运维知识进阶篇】Zabbix5.0稳定版详解10(Zabbix自动注册+Ansible自动部署,实现一条命令监控任意主机)
【运维知识进阶篇】Zabbix5.0稳定版详解10(Zabbix自动注册+Ansible自动部署,实现一条命令监控任意主机)
112 0
|
9月前
Ansible模块管理——磁盘管理模块、mount模块
Ansible模块管理——磁盘管理模块、mount模块
256 0
|
9月前
|
网络协议 网络安全 数据安全/隐私保护
Ansible模块介绍——配置网络模块、上传下载文件模块
Ansible模块介绍——配置网络模块、上传下载文件模块
275 0
|
9月前
|
应用服务中间件 nginx
Ansible模块——软件包管理模块
Ansible模块——软件包管理模块
|
9月前
|
数据安全/隐私保护 Python
Ansible模块介绍——用户管理模块
Ansible模块介绍——用户管理模块