“注册"变量时如何防止“更改"标志? [英] How to prevent 'changed' flag when 'register'-ing a variable?

查看:24
本文介绍了“注册"变量时如何防止“更改"标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 register 任务来测试包的安装:

I have a register task to test for the installation of a package:

tasks:
  - name: test for nginx
    command: dpkg -s nginx-common
    register: nginx_installed

每次运行都会报告为更改":

Every run it gets reported as a "change":

TASK: [test for nginx] ********************************************************
changed: [vm1]

我不认为这是一个变化……它是上次运行时安装的,这次运行时仍然安装.是的,没什么大不了的,只是那些凌乱的强迫症类型的问题之一.

I don't regard this as a change... it was installed last run and is still installed this run. Yeah, not a biggy, just one of those untidy OCD type issues.

那我做错了吗?有没有什么方法可以使用 register 而不会总是被视为更改?

So am I doing it wrong? Is there some way to use register without it always being regarded as a change?

[详细] 输出不整洁,但我发现这是获得正确返回码的唯一方法.

The [verbose] output is untidy, but the only way I've found to get the correct return code.

TASK: [测试nginx] ************************************************************更改:[vm1] =>{"changed": true, "cmd": ["dpkg", "-s", "nginx-common"], "delta": "0:00:00.010231", "end": "2014-05-3012:16:40.604405", "rc": 0, "start": "2014-05-30 12:16:40.594174", "stderr": "", "stdout": "Package: nginx-common\nStatus:安装好...\n主页:http://nginx.net"}

推荐答案

官方文档中有描述 这里.

tasks:
  - name: test for nginx
    command: dpkg -s nginx-common
    register: nginx_installed
    changed_when: false

这篇关于“注册"变量时如何防止“更改"标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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