2016-05-09 27 views
0

的Ansible模塊可以support check mode通過設置supports_check_mode=True用Python寫的:supports_check_mode非Python模塊

module = AnsibleModule(
    argument_spec = dict(...), 
    supports_check_mode=True 
) 

現在我有一個700+行Ruby腳本,我想變成一個模塊,並希望避免將其翻譯成Python。有沒有辦法如何支持非Python模塊的檢查模式?

+0

如果我沒有錯,你的模塊將被調用一組參數,其中一個將是'check'或'check_mode'。 'supports_check_mode'只用於打印'這個模塊不支持檢查模式'。 – shaps

回答

1

Ansible會將參數_ansible_check_mode傳遞給模塊,如果處於檢查模式,則爲true。

請記住,參數放在一個文件中,並且該文件的路徑是參數#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