Debian Codegraph @

ansible_collections/community/hrobot/plugins/modules/failover_ip_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2019 Felix Fontein <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
6 # SPDX-License-Identifier: GPL-3.0-or-later
7
8 from __future__ import absolute_import, division, print_function
9 __metaclass__ = type
10
11
12 DOCUMENTATION = r"""
13 module: failover_ip_info
14 short_description: Retrieve information on Hetzner's failover IPs
15 author:
16 - Felix Fontein (@felixfontein)
17 description:
18 - Retrieve information on Hetzner's failover IPs.
19 seealso:
20 - name: Failover IP documentation
21 description: Hetzner's documentation on failover IPs.
22 link: https://docs.hetzner.com/robot/dedicated-server/ip/failover/
23 - module: community.hrobot.failover_ip
24 description: Manage failover IPs.
25 extends_documentation_fragment:
26 - community.hrobot.robot
27 - community.hrobot.attributes
28 - community.hrobot.attributes.actiongroup_robot
29 - community.hrobot.attributes.idempotent_not_modify_state
30 - community.hrobot.attributes.info_module
31
32 attributes:
33 action_group:
34 version_added: 1.6.0
35
36 options:
37 failover_ip:
38 description: The failover IP address.
39 type: str
40 required: true
41 """
42
43 EXAMPLES = r"""
44 ---
45 - name: Get value of failover IP 1.2.3.4
46 community.hrobot.failover_ip_info:
47 hetzner_user: foo
48 hetzner_password: bar
49 failover_ip: 1.2.3.4
50 value: 5.6.7.8
51 register: result
52
53 - name: Print value of failover IP 1.2.3.4 in case it is routed
54 ansible.builtin.debug:
55 msg: "1.2.3.4 routes to {{ result.value }}"
56 when: result.state == 'routed'
57 """
58
59 RETURN = r"""
60 value:
61 description:
62 - The value of the failover IP.
63 - Will be V(none) if the IP is unrouted.
64 returned: success
65 type: str
66 state:
67 description:
68 - Will be V(routed) or V(unrouted).
69 returned: success
70 type: str
71 failover_ip:
72 description:
73 - The failover IP.
74 returned: success
75 type: str
76 sample: '1.2.3.4'
77 failover_netmask:
78 description:
79 - The netmask for the failover IP.
80 returned: success
81 type: str
82 sample: '255.255.255.255'
83 server_ip:
84 description:
85 - The main IP of the server this failover IP is associated to.
86 - This is I(not) the server the failover IP is routed to.
87 returned: success
88 type: str
89 server_number:
90 description:
91 - The number of the server this failover IP is associated to.
92 - This is I(not) the server the failover IP is routed to.
93 returned: success
94 type: int
95 """
96
97 from ansible.module_utils.basic import AnsibleModule
98 from ansible_collections.community.hrobot.plugins.module_utils.robot import (
99 ROBOT_DEFAULT_ARGUMENT_SPEC,
100 )
101 from ansible_collections.community.hrobot.plugins.module_utils.failover import (
102 get_failover_record,
103 get_failover_state,
104 )
105
106
107 def main():
108 argument_spec = dict(
109 failover_ip=dict(type='str', required=True),
110 )
111 argument_spec.update(ROBOT_DEFAULT_ARGUMENT_SPEC)
112 module = AnsibleModule(
113 argument_spec=argument_spec,
114 supports_check_mode=True,
115 )
116
117 failover = get_failover_record(module, module.params['failover_ip'])
118 result = get_failover_state(failover['active_server_ip'])
119 result['failover_ip'] = failover['ip']
120 result['failover_netmask'] = failover['netmask']
121 result['server_ip'] = failover['server_ip']
122 result['server_number'] = failover['server_number']
123 result['changed'] = False
124 module.exit_json(**result)
125
126
127 if __name__ == '__main__': # pragma: no cover
128 main() # pragma: no cover