ansible中shell和command的区别 [英] Difference between shell and command in ansible

查看:35
本文介绍了ansible中shell和command的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ansible 世界的新手,任何人都可以帮助我理解 ansible 中 shell 和命令之间的区别.何时使用 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 模块中使用变量时使用引用"过滤器很容易克服这一点.

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 模块教程 - 完整的初学者指南

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

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