mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-25 21:22:44 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -75,33 +75,33 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
name=dict(required=True, aliases=['publisher']),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
sticky=dict(type='bool'),
|
||||
enabled=dict(type='bool'),
|
||||
name=dict(required=True, aliases=["publisher"]),
|
||||
state=dict(default="present", choices=["present", "absent"]),
|
||||
sticky=dict(type="bool"),
|
||||
enabled=dict(type="bool"),
|
||||
# search_after=dict(),
|
||||
# search_before=dict(),
|
||||
origin=dict(type='list', elements='str'),
|
||||
mirror=dict(type='list', elements='str'),
|
||||
origin=dict(type="list", elements="str"),
|
||||
mirror=dict(type="list", elements="str"),
|
||||
)
|
||||
)
|
||||
|
||||
for option in ['origin', 'mirror']:
|
||||
if module.params[option] == ['']:
|
||||
for option in ["origin", "mirror"]:
|
||||
if module.params[option] == [""]:
|
||||
module.params[option] = []
|
||||
|
||||
if module.params['state'] == 'present':
|
||||
if module.params["state"] == "present":
|
||||
modify_publisher(module, module.params)
|
||||
else:
|
||||
unset_publisher(module, module.params['name'])
|
||||
unset_publisher(module, module.params["name"])
|
||||
|
||||
|
||||
def modify_publisher(module, params):
|
||||
name = params['name']
|
||||
name = params["name"]
|
||||
existing = get_publishers(module)
|
||||
|
||||
if name in existing:
|
||||
for option in ['origin', 'mirror', 'sticky', 'enabled']:
|
||||
for option in ["origin", "mirror", "sticky", "enabled"]:
|
||||
if params[option] is not None:
|
||||
if params[option] != existing[name][option]:
|
||||
return set_publisher(module, params)
|
||||
|
|
@ -112,35 +112,32 @@ def modify_publisher(module, params):
|
|||
|
||||
|
||||
def set_publisher(module, params):
|
||||
name = params['name']
|
||||
name = params["name"]
|
||||
args = []
|
||||
|
||||
if params['origin'] is not None:
|
||||
args.append('--remove-origin=*')
|
||||
args.extend([f"--add-origin={u}" for u in params['origin']])
|
||||
if params['mirror'] is not None:
|
||||
args.append('--remove-mirror=*')
|
||||
args.extend([f"--add-mirror={u}" for u in params['mirror']])
|
||||
if params["origin"] is not None:
|
||||
args.append("--remove-origin=*")
|
||||
args.extend([f"--add-origin={u}" for u in params["origin"]])
|
||||
if params["mirror"] is not None:
|
||||
args.append("--remove-mirror=*")
|
||||
args.extend([f"--add-mirror={u}" for u in params["mirror"]])
|
||||
|
||||
if params['sticky'] is not None and params['sticky']:
|
||||
args.append('--sticky')
|
||||
elif params['sticky'] is not None:
|
||||
args.append('--non-sticky')
|
||||
if params["sticky"] is not None and params["sticky"]:
|
||||
args.append("--sticky")
|
||||
elif params["sticky"] is not None:
|
||||
args.append("--non-sticky")
|
||||
|
||||
if params['enabled'] is not None and params['enabled']:
|
||||
args.append('--enable')
|
||||
elif params['enabled'] is not None:
|
||||
args.append('--disable')
|
||||
if params["enabled"] is not None and params["enabled"]:
|
||||
args.append("--enable")
|
||||
elif params["enabled"] is not None:
|
||||
args.append("--disable")
|
||||
|
||||
rc, out, err = module.run_command(
|
||||
["pkg", "set-publisher"] + args + [name],
|
||||
check_rc=True
|
||||
)
|
||||
rc, out, err = module.run_command(["pkg", "set-publisher"] + args + [name], check_rc=True)
|
||||
response = {
|
||||
'rc': rc,
|
||||
'results': [out],
|
||||
'msg': err,
|
||||
'changed': True,
|
||||
"rc": rc,
|
||||
"results": [out],
|
||||
"msg": err,
|
||||
"changed": True,
|
||||
}
|
||||
if rc != 0:
|
||||
module.fail_json(**response)
|
||||
|
|
@ -151,15 +148,12 @@ def unset_publisher(module, publisher):
|
|||
if publisher not in get_publishers(module):
|
||||
module.exit_json()
|
||||
|
||||
rc, out, err = module.run_command(
|
||||
["pkg", "unset-publisher", publisher],
|
||||
check_rc=True
|
||||
)
|
||||
rc, out, err = module.run_command(["pkg", "unset-publisher", publisher], check_rc=True)
|
||||
response = {
|
||||
'rc': rc,
|
||||
'results': [out],
|
||||
'msg': err,
|
||||
'changed': True,
|
||||
"rc": rc,
|
||||
"results": [out],
|
||||
"msg": err,
|
||||
"changed": True,
|
||||
}
|
||||
if rc != 0:
|
||||
module.fail_json(**response)
|
||||
|
|
@ -175,21 +169,21 @@ def get_publishers(module):
|
|||
publishers = {}
|
||||
for line in lines:
|
||||
values = dict(zip(keys, map(unstringify, line.split("\t"))))
|
||||
name = values['publisher']
|
||||
name = values["publisher"]
|
||||
|
||||
if name not in publishers:
|
||||
publishers[name] = {k: values[k] for k in ['sticky', 'enabled']}
|
||||
publishers[name]['origin'] = []
|
||||
publishers[name]['mirror'] = []
|
||||
publishers[name] = {k: values[k] for k in ["sticky", "enabled"]}
|
||||
publishers[name]["origin"] = []
|
||||
publishers[name]["mirror"] = []
|
||||
|
||||
if values['type'] is not None:
|
||||
publishers[name][values['type']].append(values['uri'])
|
||||
if values["type"] is not None:
|
||||
publishers[name][values["type"]].append(values["uri"])
|
||||
|
||||
return publishers
|
||||
|
||||
|
||||
def unstringify(val):
|
||||
if val == "-" or val == '':
|
||||
if val == "-" or val == "":
|
||||
return None
|
||||
elif val == "true":
|
||||
return True
|
||||
|
|
@ -199,5 +193,5 @@ def unstringify(val):
|
|||
return val
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue