edit.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # pylint: skip-file
  2. def main():
  3. '''
  4. ansible oc module for services
  5. '''
  6. module = AnsibleModule(
  7. argument_spec=dict(
  8. kubeconfig=dict(default='/etc/origin/master/admin.kubeconfig', type='str'),
  9. state=dict(default='present', type='str',
  10. choices=['present']),
  11. debug=dict(default=False, type='bool'),
  12. namespace=dict(default='default', type='str'),
  13. name=dict(default=None, required=True, type='str'),
  14. kind=dict(required=True,
  15. type='str',
  16. choices=['dc', 'deploymentconfig',
  17. 'svc', 'service',
  18. 'scc', 'securitycontextconstraints',
  19. 'ns', 'namespace', 'project', 'projects',
  20. 'is', 'imagestream',
  21. 'istag', 'imagestreamtag',
  22. 'bc', 'buildconfig',
  23. 'routes',
  24. 'node',
  25. 'secret',
  26. ]),
  27. file_name=dict(default=None, type='str'),
  28. file_format=dict(default='yaml', type='str'),
  29. content=dict(default=None, required=True, type='dict'),
  30. force=dict(default=False, type='bool'),
  31. ),
  32. supports_check_mode=True,
  33. )
  34. ocedit = Edit(module.params['kind'],
  35. module.params['namespace'],
  36. module.params['name'],
  37. kubeconfig=module.params['kubeconfig'],
  38. verbose=module.params['debug'])
  39. state = module.params['state']
  40. api_rval = ocedit.get()
  41. ########
  42. # Create
  43. ########
  44. if not Utils.exists(api_rval['results'], module.params['name']):
  45. module.fail_json(msg=api_rval)
  46. ########
  47. # Update
  48. ########
  49. api_rval = ocedit.update(module.params['file_name'],
  50. module.params['content'],
  51. module.params['force'],
  52. module.params['file_format'])
  53. if api_rval['returncode'] != 0:
  54. module.fail_json(msg=api_rval)
  55. if api_rval.has_key('updated') and not api_rval['updated']:
  56. module.exit_json(changed=False, results=api_rval, state="present")
  57. # return the created object
  58. api_rval = ocedit.get()
  59. if api_rval['returncode'] != 0:
  60. module.fail_json(msg=api_rval)
  61. module.exit_json(changed=True, results=api_rval, state="present")
  62. module.exit_json(failed=True,
  63. changed=False,
  64. results='Unknown state passed. %s' % state,
  65. state="unknown")
  66. # pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import, locally-disabled
  67. # import module snippets. This are required
  68. from ansible.module_utils.basic import *
  69. main()