5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
21 from shade import meta
28 module: os_node_provision_check
29 short_description: Retrieve facts about ironic nodes list provided,
30 Returns a list of nodes which are not in deploying and failed states
33 - Retrieve facts about ironic nodes list provided,
34 Returns a list of nodes which are not in deploying and failed states
41 - List of dicts [{id: <ironic_node_id>, name: <ironic_node_name>},....], containing ironic node ids and names.
42 This modules runs through all the ironic nodes and returns list of nodes in deploying and failed state.
46 provision_pending_list
48 extends_documentation_fragment: openstack
52 # Gather facts about all nodes named C<web*>:
53 - os_node_provision_check:
65 argument_spec = openstack_full_argument_spec(
66 nodes_details=dict(type='list', required=True),
67 ironic_url=dict(required=False),
69 module_kwargs = openstack_module_kwargs()
70 module = AnsibleModule(argument_spec, **module_kwargs)
73 module.fail_json(msg='shade is required for this module')
74 if (module.params['auth_type'] in [None, 'None'] and
75 module.params['ironic_url'] is None):
76 module.fail_json(msg="Authentication appears to be disabled, "
77 "Please define an ironic_url parameter")
79 if (module.params['ironic_url'] and
80 module.params['auth_type'] in [None, 'None']):
81 module.params['auth'] = dict(
82 endpoint=module.params['ironic_url']
86 cloud = shade.operator_cloud(**module.params)
88 nodes_details = module.params['nodes_details']
89 provision_pending_list = []
90 provision_failed_list = []
92 for node in nodes_details:
93 node_name = node['name']
94 node_details = cloud.get_machine(node_name)
96 if node_details['provision_state'] in ['deploying', 'wait call-back']:
97 provision_pending_list.append(node_name)
99 if node_details['provision_state'] in ['deploy failed']:
100 node_provision_state = {}
101 node_provision_state['name'] = node_name
102 node_provision_state['provision_state'] = node_details['provision_state']
103 provision_failed_list.append(node_provision_state)
105 module.exit_json(changed=False, ansible_facts=dict(provision_pending_list=provision_pending_list, provision_failed_list=provision_failed_list))
107 except shade.OpenStackCloudException as e:
108 module.fail_json(msg=str(e))
110 # this is magic, see lib/ansible/module_common.py
111 from ansible.module_utils.basic import *
112 from ansible.module_utils.openstack import *
113 if __name__ == '__main__':