1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-27 05:58:50 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -78,7 +78,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
def sensu_subscription(module, path, name, state='present', backup=False):
def sensu_subscription(module, path, name, state="present", backup=False):
changed = False
reasons = []
@ -86,42 +86,42 @@ def sensu_subscription(module, path, name, state='present', backup=False):
config = json.load(open(path))
except IOError as e:
if e.errno == 2: # File not found, non-fatal
if state == 'absent':
if state == "absent":
reasons.append("file did not exist and state is 'absent'")
return changed, reasons
config = {}
else:
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
except ValueError:
msg = f'{path} contains invalid JSON'
msg = f"{path} contains invalid JSON"
module.fail_json(msg=msg)
if 'client' not in config:
if state == 'absent':
if "client" not in config:
if state == "absent":
reasons.append("'client' did not exist and state is 'absent'")
return changed, reasons
config['client'] = {}
config["client"] = {}
changed = True
reasons.append("'client' did not exist")
if 'subscriptions' not in config['client']:
if state == 'absent':
if "subscriptions" not in config["client"]:
if state == "absent":
reasons.append("'client.subscriptions' did not exist and state is 'absent'")
return changed, reasons
config['client']['subscriptions'] = []
config["client"]["subscriptions"] = []
changed = True
reasons.append("'client.subscriptions' did not exist")
if name not in config['client']['subscriptions']:
if state == 'absent':
if name not in config["client"]["subscriptions"]:
if state == "absent":
reasons.append("channel subscription was absent")
return changed, reasons
config['client']['subscriptions'].append(name)
config["client"]["subscriptions"].append(name)
changed = True
reasons.append("channel subscription was absent and state is 'present'")
else:
if state == 'absent':
config['client']['subscriptions'].remove(name)
if state == "absent":
config["client"]["subscriptions"].remove(name)
changed = True
reasons.append("channel subscription was present and state is 'absent'")
@ -129,33 +129,34 @@ def sensu_subscription(module, path, name, state='present', backup=False):
if backup:
module.backup_local(path)
try:
open(path, 'w').write(json.dumps(config, indent=2) + '\n')
open(path, "w").write(json.dumps(config, indent=2) + "\n")
except IOError as e:
module.fail_json(msg='Failed to write to file %s: %s' % (path, to_native(e)),
exception=traceback.format_exc())
module.fail_json(
msg="Failed to write to file %s: %s" % (path, to_native(e)), exception=traceback.format_exc()
)
return changed, reasons
def main():
arg_spec = {'name': {'type': 'str', 'required': True},
'path': {'type': 'str', 'default': '/etc/sensu/conf.d/subscriptions.json'},
'state': {'type': 'str', 'default': 'present', 'choices': ['present', 'absent']},
'backup': {'type': 'bool', 'default': False},
}
arg_spec = {
"name": {"type": "str", "required": True},
"path": {"type": "str", "default": "/etc/sensu/conf.d/subscriptions.json"},
"state": {"type": "str", "default": "present", "choices": ["present", "absent"]},
"backup": {"type": "bool", "default": False},
}
module = AnsibleModule(argument_spec=arg_spec,
supports_check_mode=True)
module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True)
path = module.params['path']
name = module.params['name']
state = module.params['state']
backup = module.params['backup']
path = module.params["path"]
name = module.params["name"]
state = module.params["state"]
backup = module.params["backup"]
changed, reasons = sensu_subscription(module, path, name, state, backup)
module.exit_json(path=path, name=name, changed=changed, msg='OK', reasons=reasons)
module.exit_json(path=path, name=name, changed=changed, msg="OK", reasons=reasons)
if __name__ == '__main__':
if __name__ == "__main__":
main()