用 Python 编写的 Ansible 模块可以通过设置支持检查模式supports_check_mode=True
:
module = AnsibleModule(
argument_spec = dict(...),
supports_check_mode=True
)
现在我有一个 700 多行的 Ruby 脚本,我想将其转换为一个模块,并希望避免将其转换为 Python。有没有办法支持非 Python 模块的检查模式?
用 Python 编写的 Ansible 模块可以通过设置支持检查模式supports_check_mode=True
:
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