-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathstacki_appliance_info.py
More file actions
99 lines (79 loc) · 2.1 KB
/
stacki_appliance_info.py
File metadata and controls
99 lines (79 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# @copyright@
# Copyright (c) 2006 - 2020 Teradata
# All rights reserved. Stacki(r) v5.x stacki.com
# https://github.com/Teradata/stacki/blob/master/LICENSE.txt
# @copyright@
DOCUMENTATION = """
module: stacki_appliance_info
short_description: Return data about Stacki appliances
description:
- If name is supplied, returns data about a single appliance
- If name is not supplied, returns data about all appliances in the system
options:
name:
description:
- The name of the appliance to return data about
required: false
"""
EXAMPLES = """
- name: Get appliance backend
stacki_appliance_info:
name: backend
register: result
- name: Get all appliances
stacki_appliance_info:
register: result
"""
RETURN = """
appliances:
description:
- List of appliances
returned: on success
type: complex
contains:
name:
description:
- Name of the appliance
type: str
public:
description:
- True if the appliance is considered public
type: bool
"""
from stack.bool import str2bool
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.stacki import run_stack_command, StackCommandError
def main():
# Define the arguments for this module
argument_spec = dict(
name=dict(type="str", required=False, default=None)
)
# Create our module object
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True
)
# Initialize a blank result
result = {
"changed": False,
"appliances": []
}
# Bail if the user is just checking syntax of their playbook
if module.check_mode:
module.exit_json(**result)
# Fetch our appliance info from Stacki
args = []
if module.params["name"]:
args.append(module.params["name"])
try:
for appliance in run_stack_command("list.appliance", args):
# Public needs to be a bool
appliance["public"] = str2bool(appliance["public"])
result["appliances"].append(appliance)
except StackCommandError as e:
# Fetching the data failed
module.fail_json(msg=e.message, **result)
# Return our data
module.exit_json(**result)
if __name__ == "__main__":
main()