mirror of https://github.com/ansible/ansible.git
fix a-doc listing plugins and add tests (#68600)
* add docs listing tests * added collection module docs test * always safe_load * force 'type consistency' for uniquing paths * bytified * use our json encoder Co-Authored-By: Matt Clay <matt@mystile.com>pull/69032/head
parent
a67d5dbcb7
commit
23ab8f37df
@ -0,0 +1,30 @@
|
||||
{
|
||||
"collection_info": {
|
||||
"description": null,
|
||||
"repository": "",
|
||||
"tags": [],
|
||||
"dependencies": {},
|
||||
"authors": [
|
||||
"Ansible (https://ansible.com)"
|
||||
],
|
||||
"issues": "",
|
||||
"name": "testcol",
|
||||
"license": [
|
||||
"GPL-3.0-or-later"
|
||||
],
|
||||
"documentation": "",
|
||||
"namespace": "testns",
|
||||
"version": "0.1.1231",
|
||||
"readme": "README.md",
|
||||
"license_file": "COPYING",
|
||||
"homepage": "",
|
||||
},
|
||||
"file_manifest_file": {
|
||||
"format": 1,
|
||||
"ftype": "file",
|
||||
"chksum_sha256": "4c15a867ceba8ba1eaf2f4a58844bb5dbb82fec00645fc7eb74a3d31964900f6",
|
||||
"name": "FILES.json",
|
||||
"chksum_type": "sha256"
|
||||
},
|
||||
"format": 1
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
# (c) 2020 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = '''
|
||||
cache: testns.testcol.notjsonfile
|
||||
short_description: JSON formatted files.
|
||||
description:
|
||||
- This cache uses JSON formatted, per host, files saved to the filesystem.
|
||||
author: Ansible Core (@ansible-core)
|
||||
options:
|
||||
_uri:
|
||||
required: True
|
||||
description:
|
||||
- Path in which the cache plugin will save the JSON files
|
||||
env:
|
||||
- name: ANSIBLE_CACHE_PLUGIN_CONNECTION
|
||||
ini:
|
||||
- key: fact_caching_connection
|
||||
section: defaults
|
||||
_prefix:
|
||||
description: User defined prefix to use when creating the JSON files
|
||||
env:
|
||||
- name: ANSIBLE_CACHE_PLUGIN_PREFIX
|
||||
ini:
|
||||
- key: fact_caching_prefix
|
||||
section: defaults
|
||||
_timeout:
|
||||
default: 86400
|
||||
description: Expiration timeout for the cache plugin data
|
||||
env:
|
||||
- name: ANSIBLE_CACHE_PLUGIN_TIMEOUT
|
||||
ini:
|
||||
- key: fact_caching_timeout
|
||||
section: defaults
|
||||
type: integer
|
||||
'''
|
||||
|
||||
from ansible.plugins.cache import BaseFileCacheModule
|
||||
|
||||
|
||||
class CacheModule(BaseFileCacheModule):
|
||||
"""
|
||||
A caching module backed by json files.
|
||||
"""
|
||||
pass
|
@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2018 Ansible Project
|
||||
# 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 = '''
|
||||
inventory: testns.testcol.statichost
|
||||
short_description: Add a single host
|
||||
description: Add a single host
|
||||
extends_documentation_fragment:
|
||||
- inventory_cache
|
||||
options:
|
||||
plugin:
|
||||
description: plugin name (must be statichost)
|
||||
required: true
|
||||
hostname:
|
||||
description: Toggle display of stderr even when script was successful
|
||||
required: True
|
||||
'''
|
||||
|
||||
from ansible.errors import AnsibleParserError
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||
|
||||
NAME = 'testns.content_adj.statichost'
|
||||
|
||||
def verify_file(self, path):
|
||||
pass
|
||||
|
||||
def parse(self, inventory, loader, path, cache=None):
|
||||
|
||||
pass
|
@ -0,0 +1,37 @@
|
||||
# (c) 2020 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
lookup: testns.testcol.noop
|
||||
author: Ansible core team
|
||||
short_description: returns input
|
||||
description:
|
||||
- this is a noop
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: do nothing
|
||||
debug: msg="{{ lookup('testns.testcol.noop', [1,2,3,4] }}"
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
_list:
|
||||
description: input given
|
||||
"""
|
||||
|
||||
from ansible.module_utils.common._collections_compat import Sequence
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if not isinstance(terms, Sequence):
|
||||
raise AnsibleError("testns.testcol.noop expects a list")
|
||||
return terms
|
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = """
|
||||
module: fakemodule
|
||||
short_desciptoin: fake module
|
||||
description:
|
||||
- this is a fake module
|
||||
options:
|
||||
_notreal:
|
||||
description: really not a real option
|
||||
author:
|
||||
- me
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
|
||||
def main():
|
||||
print(json.dumps(dict(changed=False, source='testns.testcol.fakemodule')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
|
||||
|
||||
def main():
|
||||
print(json.dumps(dict(changed=False, source='testns.testcol.notrealmodule')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,27 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = '''
|
||||
vars: noop_vars_plugin
|
||||
short_description: Do NOT load host and group vars
|
||||
description: don't test loading host and group vars from a collection
|
||||
options:
|
||||
stage:
|
||||
default: all
|
||||
choices: ['all', 'inventory', 'task']
|
||||
type: str
|
||||
ini:
|
||||
- key: stage
|
||||
section: testns.testcol.noop_vars_plugin
|
||||
env:
|
||||
- name: ANSIBLE_VARS_PLUGIN_STAGE
|
||||
'''
|
||||
|
||||
from ansible.plugins.vars import BaseVarsPlugin
|
||||
|
||||
|
||||
class VarsModule(BaseVarsPlugin):
|
||||
|
||||
def get_vars(self, loader, path, entities, cache=True):
|
||||
super(VarsModule, self).get_vars(loader, path, entities)
|
||||
return {'collection': 'yes', 'notreal': 'value'}
|
@ -0,0 +1,20 @@
|
||||
> FAKEMODULE (./collections/ansible_collections/testns/testcol/plugins/modules/fakemodule.py)
|
||||
|
||||
this is a fake module
|
||||
|
||||
* This module is maintained by The Ansible Community
|
||||
OPTIONS (= is mandatory):
|
||||
|
||||
- _notreal
|
||||
really not a real option
|
||||
[Default: (null)]
|
||||
|
||||
|
||||
AUTHOR: me
|
||||
METADATA:
|
||||
status:
|
||||
- preview
|
||||
supported_by: community
|
||||
|
||||
SHORT_DESCIPTOIN: fake module
|
||||
|
Loading…
Reference in New Issue