在哪里可以找到ansible注册变量的受支持属性列表?

时间:2016-04-15 10:01:58

标签: ansible

在Ansible上你可以使用register: some_var来保存有关已执行任务的信息,但似乎我无法找到任何地方记录的属性列表。

我知道其中一些,但我确实想要一份完整的清单,因为我真的很烦,没有文件。

  • changed - 如果发生了某些事情,则设置为布尔值true(用于告知任务何时在远程计算机上执行了某些操作)。
  • stderr - 包含来自stderr
  • 的字符串输出
  • stdout - 包含来自stdout
  • 的字符串输出
  • stdout_lines - 包含一个行列表(即\ n上的stdout拆分)。

示例,我如何知道上一个任务是否失败?

3 个答案:

答案 0 :(得分:3)

There is no comprehensive list as each module returns its own list of variables.

There are common return values, which describe what a module (should) return as a minimum.

Some modules such as shell, are kind enough to list out the return values they provide in the docs.

I agree it would be quite nice to have a comprehensive cheatsheet listing the modules and return values. As it is, we're stuck with trolling through the python code for each module.

As an example, in the case of shell (which uses command under the covers), the return values are:

module.exit_json(
    cmd      = args,
    stdout   = out.rstrip("\r\n"),
    stderr   = err.rstrip("\r\n"),
    rc       = rc,
    start    = str(startd),
    end      = str(endd),
    delta    = str(delta),
    changed  = True,
    warnings = warnings
)

答案 1 :(得分:0)

请参阅以下网址注册模块: http://docs.ansible.com/ansible/playbooks_variables.html#registered-variables

此外,如果任何任务失败,它将失败整个ansible剧本并退出。忽略这一点并继续我们需要在该任务下使用下面的步骤

ignore_errors:True

要调试我们正在执行的剧本,我们应该将“-v”传递给debug。

答案 2 :(得分:0)

我也找不到寄存器变量属性的正式列表。但是我注意到了一个事实。

请参阅the explanation of register variable in chapter Loop。你注意到我注意到了吗?

您是否在此页面的Json输出中看到“结果”部分? “结果”部分中存在的每个键都应该是寄存器变量的整个属性。

实际上,您可以自己显示寄存器变量的属性列表。

请参见the registered variable section in chapter Variable。有一句话说:
在执行剧本时使用.email-form { width: 75%; } @media only screen and (max-width: 768px) { .email-form { width: 35%; } } 将显示结果的可能值。