mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
DOCUMENTATION = '''
|
||||
DOCUMENTATION = """
|
||||
module: pacemaker_stonith
|
||||
short_description: Manage Pacemaker STONITH
|
||||
author:
|
||||
|
|
@ -95,9 +95,9 @@ options:
|
|||
- Timeout period for polling the STONITH creation.
|
||||
type: int
|
||||
default: 300
|
||||
'''
|
||||
"""
|
||||
|
||||
EXAMPLES = '''
|
||||
EXAMPLES = """
|
||||
- name: Create virtual-ip STONITH
|
||||
community.general.pacemaker_stonith:
|
||||
state: present
|
||||
|
|
@ -109,9 +109,9 @@ EXAMPLES = '''
|
|||
- operation_action: monitor
|
||||
operation_options:
|
||||
- "interval=30s"
|
||||
'''
|
||||
"""
|
||||
|
||||
RETURN = '''
|
||||
RETURN = """
|
||||
previous_value:
|
||||
description: The value of the STONITH before executing the module.
|
||||
type: str
|
||||
|
|
@ -122,7 +122,7 @@ value:
|
|||
type: str
|
||||
sample: " * virtual-stonith\t(stonith:fence_virt):\t Started"
|
||||
returned: on success
|
||||
'''
|
||||
"""
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.pacemaker import pacemaker_runner
|
||||
|
|
@ -131,48 +131,55 @@ from ansible_collections.community.general.plugins.module_utils.pacemaker import
|
|||
class PacemakerStonith(StateModuleHelper):
|
||||
module = dict(
|
||||
argument_spec=dict(
|
||||
state=dict(type='str', default='present', choices=['present', 'absent', 'enabled', 'disabled']),
|
||||
name=dict(type='str', required=True),
|
||||
stonith_type=dict(type='str'),
|
||||
stonith_options=dict(type='list', elements='str', default=[]),
|
||||
stonith_operations=dict(type='list', elements='dict', default=[], options=dict(
|
||||
operation_action=dict(type='str'),
|
||||
operation_options=dict(type='list', elements='str'),
|
||||
)),
|
||||
stonith_metas=dict(type='list', elements='str'),
|
||||
stonith_argument=dict(type='dict', options=dict(
|
||||
argument_action=dict(type='str', choices=['before', 'after', 'group']),
|
||||
argument_options=dict(type='list', elements='str'),
|
||||
)),
|
||||
agent_validation=dict(type='bool', default=False),
|
||||
wait=dict(type='int', default=300),
|
||||
state=dict(type="str", default="present", choices=["present", "absent", "enabled", "disabled"]),
|
||||
name=dict(type="str", required=True),
|
||||
stonith_type=dict(type="str"),
|
||||
stonith_options=dict(type="list", elements="str", default=[]),
|
||||
stonith_operations=dict(
|
||||
type="list",
|
||||
elements="dict",
|
||||
default=[],
|
||||
options=dict(
|
||||
operation_action=dict(type="str"),
|
||||
operation_options=dict(type="list", elements="str"),
|
||||
),
|
||||
),
|
||||
stonith_metas=dict(type="list", elements="str"),
|
||||
stonith_argument=dict(
|
||||
type="dict",
|
||||
options=dict(
|
||||
argument_action=dict(type="str", choices=["before", "after", "group"]),
|
||||
argument_options=dict(type="list", elements="str"),
|
||||
),
|
||||
),
|
||||
agent_validation=dict(type="bool", default=False),
|
||||
wait=dict(type="int", default=300),
|
||||
),
|
||||
required_if=[('state', 'present', ['stonith_type', 'stonith_options'])],
|
||||
supports_check_mode=True
|
||||
required_if=[("state", "present", ["stonith_type", "stonith_options"])],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
def __init_module__(self):
|
||||
self.runner = pacemaker_runner(self.module)
|
||||
self.vars.set('previous_value', self._get()['out'])
|
||||
self.vars.set('value', self.vars.previous_value, change=True, diff=True)
|
||||
self.vars.set("previous_value", self._get()["out"])
|
||||
self.vars.set("value", self.vars.previous_value, change=True, diff=True)
|
||||
|
||||
def __quit_module__(self):
|
||||
self.vars.set('value', self._get()['out'])
|
||||
self.vars.set("value", self._get()["out"])
|
||||
|
||||
def _process_command_output(self, fail_on_err, ignore_err_msg=""):
|
||||
def process(rc, out, err):
|
||||
if fail_on_err and rc != 0 and err and ignore_err_msg not in err:
|
||||
self.do_raise(f'pcs failed with error (rc={rc}): {err}')
|
||||
self.do_raise(f"pcs failed with error (rc={rc}): {err}")
|
||||
out = out.rstrip()
|
||||
return None if out == "" else out
|
||||
|
||||
return process
|
||||
|
||||
def _get(self):
|
||||
with self.runner('cli_action state name') as ctx:
|
||||
result = ctx.run(cli_action='stonith', state='status')
|
||||
return dict(rc=result[0],
|
||||
out=result[1] if result[1] != "" else None,
|
||||
err=result[2])
|
||||
with self.runner("cli_action state name") as ctx:
|
||||
result = ctx.run(cli_action="stonith", state="status")
|
||||
return dict(rc=result[0], out=result[1] if result[1] != "" else None, err=result[2])
|
||||
|
||||
def fmt_stonith_resource(self):
|
||||
return dict(resource_name=self.vars.stonith_type)
|
||||
|
|
@ -181,38 +188,53 @@ class PacemakerStonith(StateModuleHelper):
|
|||
def fmt_stonith_operations(self):
|
||||
modified_stonith_operations = []
|
||||
for stonith_operation in self.vars.stonith_operations:
|
||||
modified_stonith_operations.append(dict(operation_action=stonith_operation.get('operation_action'),
|
||||
operation_option=stonith_operation.get('operation_options')))
|
||||
modified_stonith_operations.append(
|
||||
dict(
|
||||
operation_action=stonith_operation.get("operation_action"),
|
||||
operation_option=stonith_operation.get("operation_options"),
|
||||
)
|
||||
)
|
||||
return modified_stonith_operations
|
||||
|
||||
def state_absent(self):
|
||||
with self.runner('cli_action state name', output_process=self._process_command_output(True, "does not exist"), check_mode_skip=True) as ctx:
|
||||
ctx.run(cli_action='stonith')
|
||||
with self.runner(
|
||||
"cli_action state name",
|
||||
output_process=self._process_command_output(True, "does not exist"),
|
||||
check_mode_skip=True,
|
||||
) as ctx:
|
||||
ctx.run(cli_action="stonith")
|
||||
|
||||
def state_present(self):
|
||||
with self.runner(
|
||||
'cli_action state name resource_type resource_option resource_operation resource_meta resource_argument agent_validation wait',
|
||||
output_process=self._process_command_output(True, "already exists"),
|
||||
check_mode_skip=True) as ctx:
|
||||
ctx.run(cli_action='stonith',
|
||||
resource_type=self.fmt_stonith_resource(),
|
||||
resource_option=self.vars.stonith_options,
|
||||
resource_operation=self.fmt_stonith_operations(),
|
||||
resource_meta=self.vars.stonith_metas,
|
||||
resource_argument=self.vars.stonith_argument)
|
||||
"cli_action state name resource_type resource_option resource_operation resource_meta resource_argument agent_validation wait",
|
||||
output_process=self._process_command_output(True, "already exists"),
|
||||
check_mode_skip=True,
|
||||
) as ctx:
|
||||
ctx.run(
|
||||
cli_action="stonith",
|
||||
resource_type=self.fmt_stonith_resource(),
|
||||
resource_option=self.vars.stonith_options,
|
||||
resource_operation=self.fmt_stonith_operations(),
|
||||
resource_meta=self.vars.stonith_metas,
|
||||
resource_argument=self.vars.stonith_argument,
|
||||
)
|
||||
|
||||
def state_enabled(self):
|
||||
with self.runner('cli_action state name', output_process=self._process_command_output(True, "Starting"), check_mode_skip=True) as ctx:
|
||||
ctx.run(cli_action='stonith')
|
||||
with self.runner(
|
||||
"cli_action state name", output_process=self._process_command_output(True, "Starting"), check_mode_skip=True
|
||||
) as ctx:
|
||||
ctx.run(cli_action="stonith")
|
||||
|
||||
def state_disabled(self):
|
||||
with self.runner('cli_action state name', output_process=self._process_command_output(True, "Stopped"), check_mode_skip=True) as ctx:
|
||||
ctx.run(cli_action='stonith')
|
||||
with self.runner(
|
||||
"cli_action state name", output_process=self._process_command_output(True, "Stopped"), check_mode_skip=True
|
||||
) as ctx:
|
||||
ctx.run(cli_action="stonith")
|
||||
|
||||
|
||||
def main():
|
||||
PacemakerStonith.execute()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue