Ansible:如何使用shell输出运行命令
创始人
2024-11-07 00:00:24
0

要在Ansible中使用shell模块输出运行命令的结果,可以使用Ansible的register功能来存储命令的输出结果,并使用debug模块将结果打印出来。以下是一个示例代码:

- name: Run shell command and display output
  hosts: localhost
  tasks:
    - name: Run command and store output
      shell: ls -l
      register: command_output

    - name: Display output
      debug:
        var: command_output.stdout_lines

在上面的代码中,我们使用shell模块执行了一个ls -l命令,并将输出结果存储在command_output变量中。然后使用debug模块打印出command_output的stdout_lines属性,即命令的输出结果。

运行以上代码,将会输出类似以下的结果:

TASK [Display output] *************************************************************************************************
ok: [localhost] => {
    "command_output.stdout_lines": [
        "total 0",
        "-rw-r--r--  1 user  staff   0 Oct  1 00:00 file1.txt",
        "-rw-r--r--  1 user  staff   0 Oct  1 00:00 file2.txt",
        "-rw-r--r--  1 user  staff   0 Oct  1 00:00 file3.txt"
    ]
}

这样就可以在Ansible中使用shell模块输出运行命令的结果了。

相关内容

热门资讯

教你透视!wepoker正确养... 教你透视!wepoker正确养号方法,微乐自建房辅助工具别人怎么看,指南教程(有挂辅助)-哔哩哔哩1...
曝光透视!德州hhpoker脚... 曝光透视!德州hhpoker脚本,微乐自建房脚本下载,总结教程(有挂方针)-哔哩哔哩1、用户打开应用...
必备透视!aapoker透视方... 必备透视!aapoker透视方法,微乐自建房免费黑科技有哪些,项目教程(新版有挂)-哔哩哔哩1、该软...
专业透视!wepoker有人用... 专业透视!wepoker有人用过吗,微乐游戏竞技团辅助,法门教程(新版有挂)-哔哩哔哩1、任何wep...
科普透视!hhpoker是内部... 科普透视!hhpoker是内部控制吗,微乐小程序多功能修改器,练习教程(有挂解惑)-哔哩哔哩所有人都...
关于透视!德州机器人代打脚本,... 关于透视!德州机器人代打脚本,微乐广西小程序开挂,秘籍教程(真是有挂)-哔哩哔哩1、起透看视 德州机...
科普透视!hhpoker辅助靠... 科普透视!hhpoker辅助靠谱吗,微乐广西麻辣,手册教程(有挂方法)-哔哩哔哩1、hhpoker辅...
分享透视!德州私人局怎么透视,... 分享透视!德州私人局怎么透视,手机微乐小程序破解器如何使用,手段教程(揭秘有挂)-哔哩哔哩1、金币登...
科普透视!pokemmo辅助工... 科普透视!pokemmo辅助工具,小程序微乐辅助器2.0,指南书教程(有挂方法)-哔哩哔哩1、每一步...
专业透视!wepoker有没有... 专业透视!wepoker有没有辅助,微乐自建房脚本免费下载,法门教程(真的有挂)-哔哩哔哩1、许多玩...