guix_pull.py 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import json
  2. from ansible.module_utils.basic import AnsibleModule
  3. def main():
  4. module = AnsibleModule(
  5. argument_spec=dict(
  6. channels=dict(type="str", required=True),
  7. )
  8. )
  9. def describe():
  10. result = module.run_command("guix describe --format=json")
  11. try:
  12. return json.loads(result[1])
  13. except json.JSONDecodeError:
  14. return result[1]
  15. before = describe()
  16. result = module.run_command(
  17. " ".join(
  18. [
  19. "guix",
  20. "pull",
  21. "--allow-downgrades",
  22. f"--channels={module.params['channels']}",
  23. ]
  24. )
  25. )
  26. after = describe()
  27. result = {
  28. "msg": {"before": before, "after": after},
  29. "rc:": result if result[0] != 0 else after,
  30. "failed": result[0] != 0,
  31. "changed": before != after,
  32. }
  33. module.exit_json(**result)
  34. if __name__ == "__main__":
  35. main()