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.

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