ansible-argspec-gen demo
# Installation | |
python3 -m venv venv | |
. venv/bin/activate | |
pip install ansible-argspec-gen[base] | |
# Dry run with diagnostics | |
ansible-argspec-gen --diff --dry-run sample.py | |
echo $? # Will report back 1 | |
# Perform changes | |
ansible-argspec-gen --diff sample.py | |
echo $? # Will report back 1 | |
# If the docs do not change, no update happens | |
ansible-argspec-gen --diff sample.py | |
echo $? # Will report back 0 | |
# Update docs and regenerate argspec | |
sed -r -i -e "s/default: present/default: absent/" sample.py | |
ansible-argspec-gen --diff sample.py | |
echo $? # Will report back 1 |
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# Copyright: (c) 2020, XLAB Steampunk <steampunk@xlab.si> | |
# | |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | |
from __future__ import absolute_import, division, print_function | |
__metaclass__ = type | |
DOCUMENTATION = """ | |
module: sample | |
short_description: Manage resources | |
options: | |
name: | |
description: | |
- Resource name. | |
type: str | |
required: true | |
state: | |
description: | |
- Resource's desired state. | |
type: str | |
choices: [ present, absent ] | |
default: present | |
""" | |
from ansible.module_utils.basic import AnsibleModule | |
def main(): | |
# AUTOMATIC MODULE ARGUMENTS | |
argument_spec = dict( | |
name=dict( | |
type="str", required=True, | |
), | |
state=dict( | |
type="str", default="present", choices=["present", "absent"], | |
), | |
) | |
# AUTOMATIC MODULE ARGUMENTS | |
module = AnsibleModule( | |
argument_spec=argument_spec, | |
) | |
module.exit_json(changed=True, params=module.params) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment