|
| 1 | +#!/usr/bin/python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# |
| 4 | +# Copyright (c) 2024 |
| 5 | +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 | + |
| 7 | +from __future__ import absolute_import, division, print_function |
| 8 | +__metaclass__ = type |
| 9 | + |
| 10 | +DOCUMENTATION = ''' |
| 11 | +--- |
| 12 | +module: cs_configuration_info |
| 13 | +short_description: Gathering information about configurations from Apache CloudStack based clouds. |
| 14 | +description: |
| 15 | + - Gathering information from the API about configurations. |
| 16 | +author: Francisco Arencibia (@arencibiafrancisco) |
| 17 | +version_added: 0.1.0 |
| 18 | +options: |
| 19 | + name: |
| 20 | + description: |
| 21 | + - Name of the configuration. |
| 22 | + - If not specified, information about all configurations is gathered. |
| 23 | + type: str |
| 24 | +extends_documentation_fragment: |
| 25 | +- ngine_io.cloudstack.cloudstack |
| 26 | +''' |
| 27 | + |
| 28 | +EXAMPLES = ''' |
| 29 | +- name: Gather information about a specific configuration |
| 30 | + ngine_io.cloudstack.cs_configuration_info: |
| 31 | + name: consoleproxy.sslEnabled |
| 32 | + register: config |
| 33 | +
|
| 34 | +- name: Show the returned results of the registered variable |
| 35 | + debug: |
| 36 | + msg: "{{ config }}" |
| 37 | +
|
| 38 | +- name: Gather information about all configurations |
| 39 | + ngine_io.cloudstack.cs_configuration_info: |
| 40 | + register: configs |
| 41 | +
|
| 42 | +- name: Show information on all configurations |
| 43 | + debug: |
| 44 | + msg: "{{ configs }}" |
| 45 | +''' |
| 46 | + |
| 47 | +RETURN = ''' |
| 48 | +--- |
| 49 | +configurations: |
| 50 | + description: A list of matching configurations. |
| 51 | + type: list |
| 52 | + returned: success |
| 53 | + contains: |
| 54 | + name: |
| 55 | + description: Name of the configuration. |
| 56 | + returned: success |
| 57 | + type: str |
| 58 | + sample: consoleproxy.sslEnabled |
| 59 | + value: |
| 60 | + description: Value of the configuration. |
| 61 | + returned: success |
| 62 | + type: str |
| 63 | + sample: true |
| 64 | + description: |
| 65 | + description: Description of the configuration. |
| 66 | + returned: success |
| 67 | + type: str |
| 68 | + sample: "Enable SSL for console proxy" |
| 69 | +''' |
| 70 | + |
| 71 | +from ansible.module_utils.basic import AnsibleModule |
| 72 | +from ansible_collections.ngine_io.cloudstack.plugins.module_utils.cloudstack import ( |
| 73 | + AnsibleCloudStack, |
| 74 | + cs_argument_spec, |
| 75 | +) |
| 76 | + |
| 77 | + |
| 78 | +class AnsibleCloudStackConfigurationInfo(AnsibleCloudStack): |
| 79 | + |
| 80 | + def __init__(self, module): |
| 81 | + super(AnsibleCloudStackConfigurationInfo, self).__init__(module) |
| 82 | + self.returns = { |
| 83 | + 'name': 'name', |
| 84 | + 'value': 'value', |
| 85 | + 'description': 'description', |
| 86 | + } |
| 87 | + |
| 88 | + def get_configuration(self): |
| 89 | + args = {} |
| 90 | + if self.module.params['name']: |
| 91 | + args['name'] = self.module.params['name'] |
| 92 | + configurations = self.query_api('listConfigurations', **args) |
| 93 | + if configurations and 'configuration' in configurations: |
| 94 | + configurations = configurations['configuration'] |
| 95 | + else: |
| 96 | + configurations = [] |
| 97 | + else: |
| 98 | + configurations = self.query_api('listConfigurations') |
| 99 | + if configurations and 'configuration' in configurations: |
| 100 | + configurations = configurations['configuration'] |
| 101 | + else: |
| 102 | + configurations = [] |
| 103 | + |
| 104 | + return { |
| 105 | + 'configurations': [self.update_result(config) for config in configurations] |
| 106 | + } |
| 107 | + |
| 108 | + |
| 109 | +def main(): |
| 110 | + argument_spec = cs_argument_spec() |
| 111 | + argument_spec.update(dict( |
| 112 | + name=dict(type='str'), |
| 113 | + )) |
| 114 | + |
| 115 | + module = AnsibleModule( |
| 116 | + argument_spec=argument_spec, |
| 117 | + supports_check_mode=True, |
| 118 | + ) |
| 119 | + |
| 120 | + acs_configuration_info = AnsibleCloudStackConfigurationInfo(module=module) |
| 121 | + result = acs_configuration_info.get_configuration() |
| 122 | + module.exit_json(**result) |
| 123 | + |
| 124 | + |
| 125 | +if __name__ == '__main__': |
| 126 | + main() |
0 commit comments