0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ansible plugin のオレオレひな形

Posted at

だいたい _execute() をいじればなんとかなると思っている。

lib.py
# !/usr/bin/env python
# -*- coding: utf-8 -*-
DOCUMENTATION = '''
---
module: module_name
short_description: short desc
description:
  - desc
options:
  arg1:
    description:
      - arg1 desc
    default: None
    required: False
    type: str
rtype: str
'''

EXAMPLES = '''
- action: module_name arg1=arg1
'''


import json
import sys
import shlex
from ansible.module_utils.basic import *


ARGUMENT_SPEC = {
    'arg1': {
        'default': None,
        'required': False,
        'type': 'str',
    },
}
SEARCH_KEY = 'key'


def _execute(module):
    results = []
    _arg1 = module.params['arg1'].strip('[').strip(']').split(',')
    for _target in _arg1:
        _target = _target.strip(' ')
        if SEARCH_KEY in line:
            _result = line.split(':')[1].split('/')[-1]
            results.append(_result)
    return results



def main():
    module = AnsibleModule(
        ARGUMENT_SPEC,
        supports_check_mode=True,
    )

    result = _execute(module)
    module.exit_json(changed=True, value=result)


if __name__ == "__main__":
    main()

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?