mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-18 18:01:31 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -82,48 +82,48 @@ from ansible.module_utils.common.text.converters import to_native
|
|||
|
||||
|
||||
def do_upgrade(module, image):
|
||||
atomic_bin = module.get_bin_path('atomic')
|
||||
args = [atomic_bin, 'update', '--force', image]
|
||||
atomic_bin = module.get_bin_path("atomic")
|
||||
args = [atomic_bin, "update", "--force", image]
|
||||
rc, out, err = module.run_command(args, check_rc=False)
|
||||
if rc != 0: # something went wrong emit the msg
|
||||
module.fail_json(rc=rc, msg=err)
|
||||
elif 'Image is up to date' in out:
|
||||
elif "Image is up to date" in out:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def core(module):
|
||||
image = module.params['name']
|
||||
state = module.params['state']
|
||||
started = module.params['started']
|
||||
backend = module.params['backend']
|
||||
image = module.params["name"]
|
||||
state = module.params["state"]
|
||||
started = module.params["started"]
|
||||
backend = module.params["backend"]
|
||||
is_upgraded = False
|
||||
|
||||
module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
|
||||
atomic_bin = module.get_bin_path('atomic')
|
||||
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C")
|
||||
atomic_bin = module.get_bin_path("atomic")
|
||||
out = {}
|
||||
err = {}
|
||||
rc = 0
|
||||
|
||||
if backend:
|
||||
if state == 'present' or state == 'latest':
|
||||
args = [atomic_bin, 'pull', "--storage=%s" % backend, image]
|
||||
if state == "present" or state == "latest":
|
||||
args = [atomic_bin, "pull", "--storage=%s" % backend, image]
|
||||
rc, out, err = module.run_command(args, check_rc=False)
|
||||
if rc < 0:
|
||||
module.fail_json(rc=rc, msg=err)
|
||||
else:
|
||||
out_run = ""
|
||||
if started:
|
||||
args = [atomic_bin, 'run', "--storage=%s" % backend, image]
|
||||
args = [atomic_bin, "run", "--storage=%s" % backend, image]
|
||||
rc, out_run, err = module.run_command(args, check_rc=False)
|
||||
if rc < 0:
|
||||
module.fail_json(rc=rc, msg=err)
|
||||
|
||||
changed = "Extracting" in out or "Copying blob" in out
|
||||
module.exit_json(msg=(out + out_run), changed=changed)
|
||||
elif state == 'absent':
|
||||
args = [atomic_bin, 'images', 'delete', "--storage=%s" % backend, image]
|
||||
elif state == "absent":
|
||||
args = [atomic_bin, "images", "delete", "--storage=%s" % backend, image]
|
||||
rc, out, err = module.run_command(args, check_rc=False)
|
||||
if rc < 0:
|
||||
module.fail_json(rc=rc, msg=err)
|
||||
|
|
@ -132,24 +132,24 @@ def core(module):
|
|||
module.exit_json(msg=out, changed=changed)
|
||||
return
|
||||
|
||||
if state == 'present' or state == 'latest':
|
||||
if state == 'latest':
|
||||
if state == "present" or state == "latest":
|
||||
if state == "latest":
|
||||
is_upgraded = do_upgrade(module, image)
|
||||
|
||||
if started:
|
||||
args = [atomic_bin, 'run', image]
|
||||
args = [atomic_bin, "run", image]
|
||||
else:
|
||||
args = [atomic_bin, 'install', image]
|
||||
elif state == 'absent':
|
||||
args = [atomic_bin, 'uninstall', image]
|
||||
args = [atomic_bin, "install", image]
|
||||
elif state == "absent":
|
||||
args = [atomic_bin, "uninstall", image]
|
||||
|
||||
rc, out, err = module.run_command(args, check_rc=False)
|
||||
|
||||
if rc < 0:
|
||||
module.fail_json(rc=rc, msg=err)
|
||||
elif rc == 1 and 'already present' in err:
|
||||
elif rc == 1 and "already present" in err:
|
||||
module.exit_json(restult=err, changed=is_upgraded)
|
||||
elif started and 'Container is running' in out:
|
||||
elif started and "Container is running" in out:
|
||||
module.exit_json(result=out, changed=is_upgraded)
|
||||
else:
|
||||
module.exit_json(msg=out, changed=True)
|
||||
|
|
@ -158,15 +158,15 @@ def core(module):
|
|||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
backend=dict(type='str', choices=['docker', 'ostree']),
|
||||
name=dict(type='str', required=True),
|
||||
state=dict(type='str', default='latest', choices=['absent', 'latest', 'present']),
|
||||
started=dict(type='bool', default=True),
|
||||
backend=dict(type="str", choices=["docker", "ostree"]),
|
||||
name=dict(type="str", required=True),
|
||||
state=dict(type="str", default="latest", choices=["absent", "latest", "present"]),
|
||||
started=dict(type="bool", default=True),
|
||||
),
|
||||
)
|
||||
|
||||
# Verify that the platform supports atomic command
|
||||
dummy = module.get_bin_path('atomic', required=True)
|
||||
dummy = module.get_bin_path("atomic", required=True)
|
||||
|
||||
try:
|
||||
core(module)
|
||||
|
|
@ -174,5 +174,5 @@ def main():
|
|||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue