小编Joe*_*ggs的帖子

了解剧本中角色的可靠标记

对剧本中的角色标记是否正常工作感到困惑,如果是,那么背后的哲学。

剧本

- hosts: Test-c7-1
  roles:
    - role: test.tag
      tags: tag2
Run Code Online (Sandbox Code Playgroud)

角色/任务

---
- debug:
    msg: "task - tag1 set"
  tags: tag1

- debug:
    msg: "task - tag2 set"
  tags: tag2

- debug:
    msg: "task - always set"
  tags: always

- debug:
    msg: "task - NO TAG"
Run Code Online (Sandbox Code Playgroud)

当传入匹配的标签时,角色就会运行,任务列表中的所有内容都会执行,而不管标签如何。

匹配标签:

ansible-playbook playbook/tagtester.yml --tags "tag2"

PLAY [Test-c7-1] ********************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************************
ok: [Test-c7-1]

TASK [test.tag : debug] *************************************************************************************************************************************************************
ok: [Test-c7-1] => {
    "msg": "task - tag1 set"
}

TASK [test.tag : …
Run Code Online (Sandbox Code Playgroud)

ansible

4
推荐指数
1
解决办法
8355
查看次数

是否可以抑制 sh 模块的输出?

使用 python sh 模块时,模块本身有输出,例如正在运行的命令的状态等。是否可以抑制它?我不是指正在执行的命令的输出,而是指模块执行时打印的内容。

例如,如果脚本包含:

import pip
pip.main(['install', "sh"])

import sh

cmdArgs = ["-lrt","/tmp"]
sh.ls(cmdArgs)
Run Code Online (Sandbox Code Playgroud)

当脚本运行时,输出如下:

<Command '/bin/ls -lrt /tmp'>: starting process
<Command '/bin/ls -lrt /tmp', pid 22235>: process started
<Command '/bin/ls -lrt /tmp', pid 22235>: process completed

Run Code Online (Sandbox Code Playgroud)

我宁愿没有输出。我在http://amoffat.github.io/sh/中找不到任何内容

python

2
推荐指数
1
解决办法
686
查看次数

标签 统计

ansible ×1

python ×1