supports_check_mode 对于非 Python 模块

supports_check_mode for non-Python module

用Python编写的Ansible模块可以通过设置supports_check_mode=True:

support check mode
module = AnsibleModule(
    argument_spec = dict(...),
    supports_check_mode=True
)

现在我有一个 700 多行的 Ruby 脚本,我想将其变成一个模块,并希望避免将其转换为 Python。有没有办法支持非Python模块的检查模式?

Ansible 将向模块传递一个参数 _ansible_check_mode,如果您处于检查模式,则为真。

请记住,参数放在一个文件中,文件的路径是参数 #2。

这是一个 PHP 示例:

./library/test_module.php

#!/usr/bin/env php
<?php

// WANT_JSON Causes ansible to store args in JSON

$args = json_decode(file_get_contents($argv[1]), true);

$check_mode = !empty($args['_ansible_check_mode']);

$output = array(
    'changed' => false,
    'checking' => $check_mode
);

echo json_encode($output);

匹配的剧本:

./test_module.yml

---
- hosts: localhost
  gather_facts: no
  become: no
  tasks:
    - test_module:
        key: value