Shell和命令之间的区别 [英] Difference between shell and command in ansible

查看:83
本文介绍了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.

参考: Ansible Shell Module教程-完整的入门指南

这篇关于Shell和命令之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆