问题描述
我有一个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]
我不认为这是更改...它是在上次运行时安装的,并且在本次运行时仍安装了.是的,不是笨拙的,只是那些不整洁的OCD类型问题之一.
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: [test for nginx] ********************************************************changed: [vm1] => {"changed": true, "cmd": ["dpkg", "-s", "nginx-common"], "delta": "0:00:00.010231", "end": "2014-05-30 12:16:40.604405", "rc": 0, "start": "2014-05-30 12:16:40.594174", "stderr": "", "stdout": "Package: nginx-common\nStatus: install ok ...\nHomepage: http://nginx.net"}
TASK: [test for nginx] ********************************************************changed: [vm1] => {"changed": true, "cmd": ["dpkg", "-s", "nginx-common"], "delta": "0:00:00.010231", "end": "2014-05-30 12:16:40.604405", "rc": 0, "start": "2014-05-30 12:16:40.594174", "stderr": "", "stdout": "Package: nginx-common\nStatus: install ok ...\nHomepage: http://nginx.net"}
推荐答案
在官方文档中进行了描述这里.
tasks:
- name: test for nginx
command: dpkg -s nginx-common
register: nginx_installed
changed_when: false
这篇关于如何在“注册"变量时防止"changed"标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!