Ansible中有一个很重要的功能就是能够执行ad-hoc命令,可能有些人不懂ad-hoc这个词的意思,它表示即时的意思,或者说随意的意思。
与之相对的是ansible playbook功能,playbook适用于批量部署环境,通常不用常常改动。而ad-hoc命令适用于业务变动等操做场景,好比批量部署一个配置文件,重启某个服务,安装一些包等。
ad-hoc命令中有两个模块:command, shell。不少人不知道他们的区别是什么,其实很简单。html
MODULE_ARGS = 'rm -f /etc/yum.repos.d/CentOS* #USE_SHELL'python
例如:
[root@master tmp]# ansible slave -m command -a "rm -f /tmp/test*" -U root -s -f 50 -kK
SSH password:
SUDO password[defaults to SSH password]:
client02 | SUCCESS | rc=0 >>shell
client01 | SUCCESS | rc=0 >>安全
[root@client01 tmp]# ls
test0001 test.sh txt01 yum.logruby
[root@client02 tmp]# ls
test0001 test.sh txt01 yum.logide
[root@master tmp]# ansible slave -m shell -a "rm -f /tmp/test*" -U root -s -f 50 -kK
SSH password:
SUDO password[defaults to SSH password]:
client01 | SUCCESS | rc=0 >>函数
client02 | SUCCESS | rc=0 >>
[root@client01 tmp]# ls
txt01 yum.log
[root@client02 tmp]# ls
txt01 yum.log命令行
以上就是shell 和command的区别
看到这里,想必已经让你清晰不少了吧!htm
http://www.cnblogs.com/hemhem/archive/2011/03/14/2087482.htmlblog