Created
September 3, 2020 19:12
-
-
Save tadeboro/f670939e8f24e204a42ab12fec701ca6 to your computer and use it in GitHub Desktop.
ansible-argspec-gen demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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