share-image
ESC

Ansible 的 command 和 shell 模块

ansible 的 command 和 shell 模块都可以执行命令,例如:

➜  www ansible k8s-master -m command  -a 'pwd'
kubernetes-1 | SUCCESS | rc=0 >>
/root

➜ www ansible k8s-master -m shell -a 'pwd'
kubernetes-1 | SUCCESS | rc=0 >>
/root

但是如果你使用 command 运行一些包含特殊符号的命令,比如“|” “<” “>” 之类的命令就无法执行,原因我们通过

ansible-doc command    

查看

    Notes:
* If you want to run a command through the shell (say you are using `<', `>', `|', etc), you actually want the [shell]
module instead. The `command' module is much more secure as it's not affected by the user's environment.
* `creates', `removes', and `chdir' can be specified after the command. For instance, if you only want to run a
command if a certain file does not exist, use this.



因此在使用的时候需要注意了。

文章作者:阿文
文章链接: https://www.awen.me/post/51851.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿文的博客
本文于 2018-03-06 发布,已超过半年(2886天),请注意甄别内容是否已过期。