mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 21:33:12 +00:00
modules a*: use f-strings (#10942)
* modules a*: use f-strings * add changelog frag * add changelog frag * rename chglof frag file
This commit is contained in:
@@ -71,7 +71,7 @@ from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def activate(module):
|
||||
cmd = "%s activate --force" % (AWALL_PATH)
|
||||
cmd = f"{AWALL_PATH} activate --force"
|
||||
rc, stdout, stderr = module.run_command(cmd)
|
||||
if rc == 0:
|
||||
return True
|
||||
@@ -80,9 +80,9 @@ def activate(module):
|
||||
|
||||
|
||||
def is_policy_enabled(module, name):
|
||||
cmd = "%s list" % (AWALL_PATH)
|
||||
cmd = f"{AWALL_PATH} list"
|
||||
rc, stdout, stderr = module.run_command(cmd)
|
||||
if re.search(r"^%s\s+enabled" % name, stdout, re.MULTILINE):
|
||||
if re.search(rf"^{name}\s+enabled", stdout, re.MULTILINE):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -96,15 +96,15 @@ def enable_policy(module, names, act):
|
||||
module.exit_json(changed=False, msg="policy(ies) already enabled")
|
||||
names = " ".join(policies)
|
||||
if module.check_mode:
|
||||
cmd = "%s list" % (AWALL_PATH)
|
||||
cmd = f"{AWALL_PATH} list"
|
||||
else:
|
||||
cmd = "%s enable %s" % (AWALL_PATH, names)
|
||||
cmd = f"{AWALL_PATH} enable {names}"
|
||||
rc, stdout, stderr = module.run_command(cmd)
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to enable %s" % names, stdout=stdout, stderr=stderr)
|
||||
module.fail_json(msg=f"failed to enable {names}", stdout=stdout, stderr=stderr)
|
||||
if act and not module.check_mode:
|
||||
activate(module)
|
||||
module.exit_json(changed=True, msg="enabled awall policy(ies): %s" % names)
|
||||
module.exit_json(changed=True, msg=f"enabled awall policy(ies): {names}")
|
||||
|
||||
|
||||
def disable_policy(module, names, act):
|
||||
@@ -116,15 +116,15 @@ def disable_policy(module, names, act):
|
||||
module.exit_json(changed=False, msg="policy(ies) already disabled")
|
||||
names = " ".join(policies)
|
||||
if module.check_mode:
|
||||
cmd = "%s list" % (AWALL_PATH)
|
||||
cmd = f"{AWALL_PATH} list"
|
||||
else:
|
||||
cmd = "%s disable %s" % (AWALL_PATH, names)
|
||||
cmd = f"{AWALL_PATH} disable {names}"
|
||||
rc, stdout, stderr = module.run_command(cmd)
|
||||
if rc != 0:
|
||||
module.fail_json(msg="failed to disable %s" % names, stdout=stdout, stderr=stderr)
|
||||
module.fail_json(msg=f"failed to disable {names}", stdout=stdout, stderr=stderr)
|
||||
if act and not module.check_mode:
|
||||
activate(module)
|
||||
module.exit_json(changed=True, msg="disabled awall policy(ies): %s" % names)
|
||||
module.exit_json(changed=True, msg=f"disabled awall policy(ies): {names}")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user