diff --git a/ci/roles/nova_services/tasks/main.yml b/ci/roles/nova_services/tasks/main.yml new file mode 100644 index 00000000..fb37b41d --- /dev/null +++ b/ci/roles/nova_services/tasks/main.yml @@ -0,0 +1,15 @@ +--- + +- name: Get nova compute services info + openstack.cloud.compute_service_info: + cloud: "{{ cloud }}" + binary: "nova-compute" + register: result + failed_when: "result.openstack_compute_services | length <= 0" + +- name: Get nova conductor services info + openstack.cloud.compute_service_info: + cloud: "{{ cloud }}" + binary: "nova-conductor" + register: result + failed_when: "result.openstack_compute_services | length <= 0" diff --git a/ci/run-collection.yml b/ci/run-collection.yml index 064b24b0..d64c75a2 100644 --- a/ci/run-collection.yml +++ b/ci/run-collection.yml @@ -31,6 +31,9 @@ - { role: keystone_role, tags: keystone_role } - { role: network, tags: network } - { role: nova_flavor, tags: nova_flavor } + - role: nova_services + tags: nova_services + when: sdk_version is version(0.44, '>=') - { role: object, tags: object } - { role: port, tags: port } - { role: project, tags: project } diff --git a/meta/runtime.yml b/meta/runtime.yml index 109b81b8..821dc04d 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -19,6 +19,8 @@ action_groups: - compute_flavor - compute_flavor_info - compute_flavor_info + - compute_service_info + - compute_service_info - config - config - dns_zone diff --git a/plugins/modules/compute_service_info.py b/plugins/modules/compute_service_info.py new file mode 100644 index 00000000..bae4feb3 --- /dev/null +++ b/plugins/modules/compute_service_info.py @@ -0,0 +1,111 @@ +#!/usr/bin/python +# Copyright (c) 2016 Hewlett-Packard Enterprise Corporation +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +DOCUMENTATION = ''' +--- +module: compute_service_info +short_description: Retrieve information about one or more OpenStack compute services +author: OpenStack Ansible SIG +description: + - Retrieve information about nova compute services +options: + binary: + description: + - Filter by service binary type + type: str + host: + description: + - Filter by service host + type: str +requirements: + - "python >= 3.6" + - "openstacksdk" + +extends_documentation_fragment: +- openstack.cloud.openstack +''' + +EXAMPLES = ''' +# Gather information about compute services +- openstack.cloud.compute_service_info: + cloud: awesomecloud + binary: "nova-compute" + host: "localhost" + register: result +- openstack.cloud.compute_service_info: + cloud: awesomecloud + register: result +- debug: + msg: "{{ result.openstack_compute_services }}" +''' + + +RETURN = ''' +openstack_compute_services: + description: has all the OpenStack information about compute services + returned: always, but can be null + type: complex + contains: + id: + description: Unique UUID. + returned: success + type: str + binary: + description: The binary name of the service. + returned: success + type: str + host: + description: The name of the host. + returned: success + type: str + zone: + description: The availability zone name. + returned: success + type: str + status: + description: The status of the service. One of enabled or disabled. + returned: success + type: str + state: + description: The state of the service. One of up or down. + returned: success + type: str + update: + description: The date and time when the resource was updated + returned: success + type: str +''' + +from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule + + +class ComputeServiceInfoModule(OpenStackModule): + argument_spec = dict( + binary=dict(required=False, default=None), + host=dict(required=False, default=None), + ) + module_kwargs = dict( + supports_check_mode=True + ) + + def run(self): + binary = self.params['binary'] + host = self.params['host'] + filters = {} + if binary: + filters['binary'] = binary + if host: + filters['host'] = host + services = self.conn.compute.services(**filters) + services = list(services) + self.exit_json(changed=False, openstack_compute_services=services) + + +def main(): + module = ComputeServiceInfoModule() + module() + + +if __name__ == '__main__': + main()