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
|
|
@ -118,7 +118,7 @@ import re
|
|||
# import module snippets
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
_re_threaded = re.compile(r'threaded: *yes')
|
||||
_re_threaded = re.compile(r"threaded: *yes")
|
||||
|
||||
|
||||
def _run_threaded(module):
|
||||
|
|
@ -129,7 +129,7 @@ def _run_threaded(module):
|
|||
|
||||
|
||||
def _get_ctl_binary(module):
|
||||
for command in ['apache2ctl', 'apachectl']:
|
||||
for command in ["apache2ctl", "apachectl"]:
|
||||
ctl_binary = module.get_bin_path(command)
|
||||
if ctl_binary is not None:
|
||||
return ctl_binary
|
||||
|
|
@ -143,9 +143,9 @@ def _module_is_enabled(module):
|
|||
|
||||
if result != 0:
|
||||
error_msg = f"Error executing {control_binary}: {stderr}"
|
||||
if module.params['ignore_configcheck']:
|
||||
if 'AH00534' in stderr and 'mpm_' in module.params['name']:
|
||||
if module.params['warn_mpm_absent']:
|
||||
if module.params["ignore_configcheck"]:
|
||||
if "AH00534" in stderr and "mpm_" in module.params["name"]:
|
||||
if module.params["warn_mpm_absent"]:
|
||||
module.warn(
|
||||
"No MPM module loaded! apache2 reload AND other module actions"
|
||||
" will fail if no MPM module is loaded immediately."
|
||||
|
|
@ -169,15 +169,15 @@ def create_apache_identifier(name):
|
|||
|
||||
# a2enmod name replacement to apache2ctl -M names
|
||||
text_workarounds = [
|
||||
('shib', 'mod_shib'),
|
||||
('shib2', 'mod_shib'),
|
||||
('evasive', 'evasive20_module'),
|
||||
("shib", "mod_shib"),
|
||||
("shib2", "mod_shib"),
|
||||
("evasive", "evasive20_module"),
|
||||
]
|
||||
|
||||
# re expressions to extract subparts of names
|
||||
re_workarounds = [
|
||||
('php8', re.compile(r'^(php)[\d\.]+')),
|
||||
('php', re.compile(r'^(php\d)\.')),
|
||||
("php8", re.compile(r"^(php)[\d\.]+")),
|
||||
("php", re.compile(r"^(php\d)\.")),
|
||||
]
|
||||
|
||||
for a2enmod_spelling, module_name in text_workarounds:
|
||||
|
|
@ -196,12 +196,12 @@ def create_apache_identifier(name):
|
|||
|
||||
|
||||
def _set_state(module, state):
|
||||
name = module.params['name']
|
||||
force = module.params['force']
|
||||
name = module.params["name"]
|
||||
force = module.params["force"]
|
||||
|
||||
want_enabled = state == 'present'
|
||||
state_string = {'present': 'enabled', 'absent': 'disabled'}[state]
|
||||
a2mod_binary = {'present': 'a2enmod', 'absent': 'a2dismod'}[state]
|
||||
want_enabled = state == "present"
|
||||
state_string = {"present": "enabled", "absent": "disabled"}[state]
|
||||
a2mod_binary = {"present": "a2enmod", "absent": "a2dismod"}[state]
|
||||
success_msg = f"Module {name} {state_string}"
|
||||
|
||||
if _module_is_enabled(module) != want_enabled:
|
||||
|
|
@ -210,13 +210,15 @@ def _set_state(module, state):
|
|||
|
||||
a2mod_binary_path = module.get_bin_path(a2mod_binary)
|
||||
if a2mod_binary_path is None:
|
||||
module.fail_json(msg=f"{a2mod_binary} not found. Perhaps this system does not use {a2mod_binary} to manage apache")
|
||||
module.fail_json(
|
||||
msg=f"{a2mod_binary} not found. Perhaps this system does not use {a2mod_binary} to manage apache"
|
||||
)
|
||||
|
||||
a2mod_binary_cmd = [a2mod_binary_path]
|
||||
|
||||
if not want_enabled and force:
|
||||
# force exists only for a2dismod on debian
|
||||
a2mod_binary_cmd.append('-f')
|
||||
a2mod_binary_cmd.append("-f")
|
||||
|
||||
result, stdout, stderr = module.run_command(a2mod_binary_cmd + [name])
|
||||
|
||||
|
|
@ -224,15 +226,12 @@ def _set_state(module, state):
|
|||
module.exit_json(changed=True, result=success_msg)
|
||||
else:
|
||||
msg = (
|
||||
f'Failed to set module {name} to {state_string}:\n'
|
||||
f'{stdout}\n'
|
||||
f'Maybe the module identifier ({module.params["identifier"]}) was guessed incorrectly.'
|
||||
f"Failed to set module {name} to {state_string}:\n"
|
||||
f"{stdout}\n"
|
||||
f"Maybe the module identifier ({module.params['identifier']}) was guessed incorrectly."
|
||||
'Consider setting the "identifier" option.'
|
||||
)
|
||||
module.fail_json(msg=msg,
|
||||
rc=result,
|
||||
stdout=stdout,
|
||||
stderr=stderr)
|
||||
module.fail_json(msg=msg, rc=result, stdout=stdout, stderr=stderr)
|
||||
else:
|
||||
module.exit_json(changed=False, result=success_msg)
|
||||
|
||||
|
|
@ -241,25 +240,25 @@ def main():
|
|||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
name=dict(required=True),
|
||||
identifier=dict(type='str'),
|
||||
force=dict(type='bool', default=False),
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
ignore_configcheck=dict(type='bool', default=False),
|
||||
warn_mpm_absent=dict(type='bool', default=True),
|
||||
identifier=dict(type="str"),
|
||||
force=dict(type="bool", default=False),
|
||||
state=dict(default="present", choices=["absent", "present"]),
|
||||
ignore_configcheck=dict(type="bool", default=False),
|
||||
warn_mpm_absent=dict(type="bool", default=True),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
name = module.params['name']
|
||||
if name == 'cgi' and module.params['state'] == 'present' and _run_threaded(module):
|
||||
name = module.params["name"]
|
||||
if name == "cgi" and module.params["state"] == "present" and _run_threaded(module):
|
||||
module.fail_json(msg="Your MPM seems to be threaded, therefore enabling cgi module is not allowed.")
|
||||
|
||||
if not module.params['identifier']:
|
||||
module.params['identifier'] = create_apache_identifier(module.params['name'])
|
||||
if not module.params["identifier"]:
|
||||
module.params["identifier"] = create_apache_identifier(module.params["name"])
|
||||
|
||||
if module.params['state'] in ['present', 'absent']:
|
||||
_set_state(module, module.params['state'])
|
||||
if module.params["state"] in ["present", "absent"]:
|
||||
_set_state(module, module.params["state"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue