Allow os_server_facts to filter results based on provided filters dictionary (#23638)

* add filters variable to allow servers to be selected based on arbitrary nova properties

* update docs to fix yaml

* add required info for filters variable in the docs

* bump version number

* clean up documentation
This commit is contained in:
Dave Buckley 2018-10-30 18:34:58 +00:00 committed by ansibot
parent 40e5d2c951
commit 2bdab94b0b

View file

@ -37,6 +37,11 @@ options:
of additional API calls. of additional API calls.
type: bool type: bool
default: 'no' default: 'no'
filters:
description:
- restrict results to servers matching a dictionary of
filters
version_added: "2.8"
availability_zone: availability_zone:
description: description:
- Ignored. Present for backwards compatibility - Ignored. Present for backwards compatibility
@ -44,10 +49,12 @@ extends_documentation_fragment: openstack
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Gather facts about all servers named <web*>: # Gather facts about all servers named <web*> that are in an active state:
- os_server_facts: - os_server_facts:
cloud: rax-dfw cloud: rax-dfw
server: web* server: web*
filters:
vm_state: active
- debug: - debug:
var: openstack_servers var: openstack_servers
''' '''
@ -63,6 +70,7 @@ def main():
argument_spec = openstack_full_argument_spec( argument_spec = openstack_full_argument_spec(
server=dict(required=False), server=dict(required=False),
detailed=dict(required=False, type='bool'), detailed=dict(required=False, type='bool'),
filters=dict(required=False, type='dict', default=None)
) )
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
@ -71,6 +79,8 @@ def main():
try: try:
openstack_servers = cloud.list_servers( openstack_servers = cloud.list_servers(
detailed=module.params['detailed']) detailed=module.params['detailed'])
openstack_servers = cloud.search_servers(
detailed=module.params['detailed'], filters=module.params['filters'])
if module.params['server']: if module.params['server']:
# filter servers by name # filter servers by name