美文网首页Ansible
Ansible 命令执行模块(学习笔记九)

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

作者: SkTj | 来源:发表于2018-03-26 10:13 被阅读108次

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

command、raw

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


image.png

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


image.png

3、command不支持管道命令:


image.png

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


image.png

shell、script

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


image.png

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


iamge.png

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

image.png

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

相关文章

网友评论

    本文标题:Ansible 命令执行模块(学习笔记九)

    本文链接:https://www.haomeiwen.com/subject/gumlcftx.html