ansible shell模块 可以用来使用shell 命令 支持管道符 shell 模块和 command 模块的区别

说明

shell模块可以在远程主机上调用shell解释器运行命令,支持shell的各种功能,例如管道等

shell模块用法

ansible slave -m shell -a 'cat /etc/passwd | grep root'
# 可以使用管道符号

在这里插入图片描述

shell 模块和 command 模块的区别

1、参数形式不同:shell模块接受一个命令字符串作为参数,类似于在终端上直接输入命令;而command模块接受一个包含命令及其参数的列表作为参数。

2、执行环境不同:shell模块将会以/bin/sh -c的方式调用命令,而command模块会直接执行给定的命令,不会调用shell。

3、变量解析不同:shell模块会对命令字符串进行变量解析,而command模块不会对命令及其参数进行变量解析。

总的来说,shell模块适合执行涉及一些shell语法的命令,比如管道、重定向、通配符等;而command模块则更适合执行普通的命令。选择使用哪个模块取决于具体的需求和命令的特点。

相关推荐

  1. ansible使用shell模块环境变量问题

    2024-02-08 07:16:02       34 阅读
  2. Linux 命令解释程序(shell)模拟实现

    2024-02-08 07:16:02       49 阅读
  3. 命令模式Command

    2024-02-08 07:16:02       59 阅读
  4. [设计模式]命令模式Command

    2024-02-08 07:16:02       35 阅读
  5. 设计模式——命令模式Command

    2024-02-08 07:16:02       37 阅读
  6. 【golang】go执行shell命令方法( exec.Command

    2024-02-08 07:16:02       66 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-08 07:16:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-08 07:16:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-08 07:16:02       87 阅读
  4. Python语言-面向对象

    2024-02-08 07:16:02       96 阅读

热门阅读

  1. Cpp-3

    2024-02-08 07:16:02       56 阅读
  2. 贪心算法之找零钱

    2024-02-08 07:16:02       60 阅读
  3. 每天一个数据分析题(一百五十五)

    2024-02-08 07:16:02       60 阅读
  4. [缓存] - Redis

    2024-02-08 07:16:02       55 阅读
  5. SpringCache缓存快速实现注解

    2024-02-08 07:16:02       48 阅读
  6. Vscode SSH使用云服务器访问内网主机

    2024-02-08 07:16:02       52 阅读
  7. reactive 与 ref 的区别

    2024-02-08 07:16:02       55 阅读