Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.1 KiB

  1. #! /usr/bin/env python
  2. from ansible.module_utils.basic import AnsibleModule
  3. DOCUMENTATION = '''
  4. ---
  5. module: cert_request
  6. author: Edoardo Putti
  7. short_description: generate a host certificate request
  8. options:
  9. host:
  10. required: true
  11. description: FQDN for the host
  12. path:
  13. required: true
  14. description: path to key to be signed
  15. proto:
  16. required: true
  17. description:
  18. choices:
  19. - ssh
  20. - ssl
  21. '''
  22. EXAMPLES = '''
  23. - name: Generate ssl host request
  24. cert_request:
  25. host: "gandalf.lilik.it"
  26. path: "/etc/openvpn/openvpn.csr"
  27. proto: "ssl"
  28. - name: Generate ssh host request
  29. cert_request:
  30. host: ""
  31. path: "/etc/ssh/ssh_host_ed25519_key.pub"
  32. proto: "ssh"
  33. '''
  34. RETURN = '''
  35. type
  36. description: protocol used for the key
  37. returned: always
  38. sample: sign_request
  39. type: string
  40. keyType
  41. description: which type of key we are requesting
  42. returned: always
  43. sample:
  44. ssh_host
  45. ssl_host
  46. hostName
  47. description: FQDN of the host requesting a cert
  48. returned: always
  49. sample:
  50. example.lilik.it
  51. keyData:
  52. description: string representation of the key
  53. returned: always
  54. '''
  55. def main():
  56. module = AnsibleModule(
  57. argument_spec=dict(
  58. host=dict(
  59. required=True,
  60. type='str',
  61. ),
  62. path=dict(
  63. required=True,
  64. type='str',
  65. ),
  66. proto=dict(
  67. required=True,
  68. choices=['ssh', 'ssl'],
  69. ),
  70. ),
  71. supports_check_mode=False,
  72. )
  73. host = module.params.get('host')
  74. path = module.params.get('path')
  75. proto = module.params.get('proto')
  76. with open(path, 'r') as src:
  77. result = {
  78. 'type': 'sign_request',
  79. 'request': {
  80. 'keyType': '{}_host'.format(proto),
  81. 'hostName': host,
  82. 'keyData': src.read().replace('\n', ''),
  83. },
  84. }
  85. module.exit_json(**result)
  86. if __name__ == '__main__':
  87. main()