Ansible自定义模块参考1 min read

  • A+
所属分类:Linux运维

 
 
参考:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

ANSIBLE_METADATA = {'metadata_version': '1.0',
                    'status': ['preview'],
                    'supported_by': 'xxx'}

DOCUMENTATION = '''

'''

EXAMPLES = '''

'''

RETURN = '''

'''

## 必要模块导入
from ansible.module_utils.basic import *

## 变量定义
module = AnsibleModule(
    argument_spec = dict(
        A=dict(required=True),
        B=dict(required=False, default='')
    )
)

A = module.params['A']
B = module.params['B']

## 自定义的一些判断处理逻辑
.......
   ......

## Ansible输出
result = dict(
    skipped=skipped,
    changed=changed,
    rc=retval,
    stdout=str(stdout)
)

module.exit_json(**result)

 
 
 

zhaoyulin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: