Shell和命令之间的区别
我对Ansible世界是陌生的,谁能帮助我了解Ansible中Shell和Command之间的区别.何时使用shell以及何时使用命令.我知道一个用例
I am new to ansible world can anyone help me in understanding the difference between shell and command in ansible. When to use shell and when to use command. I know one use case
命令模块更安全,因为它不受用户环境的影响.
command module is more safe, as it is not affected by the user’s environment.
Ansible Shell模块允许您在远程主机上运行任意命令,就像您登录到Shell一样. Shell和Command模块非常相似,主要区别在于Shell模块不会转义命令,从而允许您使用Shell运算符,例如重定向(大于",小于"),管道("|")和布尔值运算符(&&","||").这确实意味着Shell模块容易受到命令注入/shell注入的影响,但这在通过Shell模块使用变量时使用"quote"过滤器很容易克服.
The Ansible Shell Module allows you to run arbitrary commands on a remote host, just like you were logged into the shell. The Shell and Command modules are very similar, the major difference being that the shell module does not escape commands, allowing you to use shell operators like redirects ("greater than", "less than"), pipe ("|") and boolean operators ("&&", "||"). This does mean that the Shell module is susceptible to command injection/shell injection, but this is easy enough to overcome by using the "quote" filter when using variables with the Shell module.