forked from stdevel/ansible-collection-uyuni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reboot_host.py
109 lines (90 loc) · 3.07 KB
/
reboot_host.py
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
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
"""
Ansible Module for rebooting a managed host
2022 Christian Stankowic
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: reboot_host
short_description: Reboot a managed host
description:
- Reboot a managed host
author:
- "Christian Stankowic (@stdevel)"
extends_documentation_fragment:
- stdevel.uyuni.uyuni_auth
options:
name:
description: Name or profile ID of the managed host
required: True
type: str
'''
EXAMPLES = '''
- name: Reboot host
stdevel.uyuni.reboot_host:
uyuni_host: 192.168.1.1
uyuni_user: admin
uyuni_password: admin
name: server.localdomain.loc
'''
RETURN = '''
entity:
description: State whether reboot was scheduled successfully
returned: success
type: bool
'''
from ansible.module_utils.basic import AnsibleModule
from ..module_utils.exceptions import EmptySetException, SSLCertVerificationError
from ..module_utils.helper_functions import _configure_connection, get_host_id
def _reboot_host(module, api_instance):
"""
Reboots the host
"""
try:
action_id = api_instance.reboot_host(
get_host_id(
module.params.get('name'),
api_instance
)
)
module.exit_json(changed=True, action_id=action_id)
except SSLCertVerificationError:
module.fail_json(msg="Failed to verify SSL certificate")
except EmptySetException as err:
module.fail_json(msg=f"Exception when calling UyuniAPI->reboot_host: {err}")
def main():
argument_spec = dict(
uyuni_host=dict(required=True),
uyuni_user=dict(required=True),
uyuni_password=dict(required=True, no_log=True),
uyuni_port=dict(default=443, type='int'),
uyuni_verify_ssl=dict(default=True, type='bool'),
name=dict(required=True)
)
module = AnsibleModule(argument_spec=argument_spec)
connection_params = dict(
host=module.params.get('uyuni_host'),
username=module.params.get('uyuni_user'),
password=module.params.get('uyuni_password'),
port=module.params.get('uyuni_port'),
verify_ssl=module.params.get('uyuni_verify_ssl')
)
api_instance = _configure_connection(connection_params)
_reboot_host(module, api_instance)
if __name__ == '__main__':
main()