supports_check_mode用于非Python模块

时间:2016-05-09 10:29:50

标签: ansible ansible-2.x

通过设置supports_check_mode=True

,可以support check mode用Python编写的Ansible模块
module = AnsibleModule(
    argument_spec = dict(...),
    supports_check_mode=True
)

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

1 个答案:

答案 0 :(得分:3)

Ansible会将参数_ansible_check_mode传递给模块,如果您处于检查模式,则为true。

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

这是一个PHP示例:

./库/ 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
相关问题