make lookup plugin compatible with ansible.tower namespace (#9)

This commit is contained in:
Alan Rominger
2020-07-02 12:11:16 -04:00
committed by John Westcott IV
parent 8239232d4d
commit 34c23caed3
5 changed files with 131 additions and 47 deletions

View File

@@ -6,36 +6,35 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = '''
name: tower
plugin_type: inventory
author:
- Matthew Jones (@matburt)
- Yunfan Zhang (@YunfanZhang42)
short_description: Ansible dynamic inventory plugin for Ansible Tower.
description:
- Reads inventories from Ansible Tower.
- Supports reading configuration from both YAML config file and environment variables.
- If reading from the YAML file, the file name must end with tower.(yml|yaml) or tower_inventory.(yml|yaml),
the path in the command would be /path/to/tower_inventory.(yml|yaml). If some arguments in the config file
are missing, this plugin will try to fill in missing arguments by reading from environment variables.
- If reading configurations from environment variables, the path in the command must be @tower_inventory.
extends_documentation_fragment:
- awx.awx.auth_plugin
options:
inventory_id:
description:
- The ID of the Ansible Tower inventory that you wish to import.
- This is allowed to be either the inventory primary key or its named URL slug.
- Primary key values will be accepted as strings or integers, and URL slugs must be strings.
- Named URL slugs follow the syntax of "inventory_name++organization_name".
type: raw
env:
- name: TOWER_INVENTORY
required: True
include_metadata:
description: Make extra requests to provide all group vars with metadata about the source Ansible Tower host.
type: bool
default: False
name: tower
plugin_type: inventory
author:
- Matthew Jones (@matburt)
- Yunfan Zhang (@YunfanZhang42)
short_description: Ansible dynamic inventory plugin for Ansible Tower.
description:
- Reads inventories from Ansible Tower.
- Supports reading configuration from both YAML config file and environment variables.
- If reading from the YAML file, the file name must end with tower.(yml|yaml) or tower_inventory.(yml|yaml),
the path in the command would be /path/to/tower_inventory.(yml|yaml). If some arguments in the config file
are missing, this plugin will try to fill in missing arguments by reading from environment variables.
- If reading configurations from environment variables, the path in the command must be @tower_inventory.
extends_documentation_fragment: awx.awx.auth_plugin
options:
inventory_id:
description:
- The ID of the Ansible Tower inventory that you wish to import.
- This is allowed to be either the inventory primary key or its named URL slug.
- Primary key values will be accepted as strings or integers, and URL slugs must be strings.
- Named URL slugs follow the syntax of "inventory_name++organization_name".
type: raw
env:
- name: TOWER_INVENTORY
required: True
include_metadata:
description: Make extra requests to provide all group vars with metadata about the source Ansible Tower host.
type: bool
default: False
'''
EXAMPLES = '''

View File

@@ -12,8 +12,9 @@ requirements:
description:
- Returns GET requests from the Ansible Tower API. See
U(https://docs.ansible.com/ansible-tower/latest/html/towerapi/index.html) for API usage.
extends_documentation_fragment:
- awx.awx.auth_plugin
- For use that is cross-compatible between the awx.awx and ansible.tower collection
see the tower_meta module
extends_documentation_fragment: awx.awx.auth_plugin
options:
_terms:
description:

View File

@@ -0,0 +1,78 @@
#!/usr/bin/python
# coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: tower_meta
author: "Alan Rominger (@alancoding)"
short_description: Returns metadata about the collection this module lives in.
description:
- Allows a user to find out what collection this module exists in.
- This takes common module parameters, but does nothing with them.
options: {}
extends_documentation_fragment: awx.awx.auth
'''
RETURN = '''
prefix:
description: Collection namespace and name in the namespace.name format
returned: success
sample: awx.awx
name:
description: Collection name
returned: success
sample: awx
namespace:
description: Collection namespace
returned: success
sample: awx
version:
description: Version of the collection
returned: success
sample: 0.0.1-devel
'''
EXAMPLES = '''
- tower_meta:
register: result
- name: Show details about the collection
debug: var=result
- name: Load the UI setting without hard-coding the collection name
debug:
msg: "{{ lookup(result.prefix + '.tower_api', 'settings/ui') }}"
'''
from ..module_utils.tower_api import TowerModule
def main():
module = TowerModule(argument_spec={})
namespace = {
'awx': 'awx',
'tower': 'ansible'
}.get(module._COLLECTION_TYPE, 'unknown')
namespace_name = '{0}.{1}'.format(namespace, module._COLLECTION_TYPE)
module.exit_json(
prefix=namespace_name,
name=module._COLLECTION_TYPE,
namespace=namespace,
version=module._COLLECTION_VERSION
)
if __name__ == '__main__':
main()