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.

87 lines
1.9 KiB

8 years ago
8 years ago
8 years ago
  1. ---
  2. - name: 'install openvpn-openssl package'
  3. opkg:
  4. name: 'openvpn-openssl'
  5. state: 'present'
  6. tags:
  7. - 'packages'
  8. - name: 'create openvpn private key'
  9. shell:
  10. cmd: >
  11. openssl genpkey
  12. -algorithm ed25519
  13. -out /etc/openvpn/openvpn.key
  14. args:
  15. creates: '/etc/openvpn/openvpn.key'
  16. notify: 'reload openvpn'
  17. tags:
  18. - 'tls_int'
  19. #- name: create openvpn dh2048
  20. # shell: 'openssl dhparam -out /etc/openvpn/dh2048.pem 2048'
  21. # args:
  22. # creates: /etc/openvpn/dh2048.pem
  23. # notify: reload openvpn
  24. - name: 'upload server ca'
  25. copy:
  26. content: '{{ tls_vpn_server_ca }}{{ tls_root_ca }}'
  27. dest: '/etc/openvpn/server_ca.crt'
  28. tags:
  29. - 'tls_int'
  30. - name: 'upload user ca'
  31. copy:
  32. content: '{{ tls_vpn_user_ca }}{{ tls_root_ca }}'
  33. dest: '/etc/openvpn/user_ca.crt'
  34. notify: 'reload openvpn'
  35. tags:
  36. - 'tls_int'
  37. - name: 'check openvpn cert status'
  38. command: >-
  39. openssl verify
  40. -CAfile /etc/openvpn/server_ca.crt
  41. /etc/openvpn/openvpn.crt
  42. register: openvpn_cert_is_valid
  43. changed_when: false
  44. failed_when: false
  45. tags:
  46. - 'tls_int'
  47. - name: 'create openvpn cert request'
  48. shell: >
  49. openssl req
  50. -new
  51. -subj "{{ x509_subject_prefix }}/OU=Server/CN={{ server_fqdn }}"
  52. -key /etc/openvpn/openvpn.key
  53. -out /etc/openvpn/openvpn.csr
  54. when: openvpn_cert_is_valid.rc != 0
  55. tags:
  56. - 'tls_int'
  57. - import_tasks: 'ca-signing-request.yaml'
  58. vars:
  59. host: '{{ server_fqdn }}'
  60. request_path: '/etc/openvpn/openvpn.csr'
  61. output_path: '/etc/openvpn/openvpn.crt'
  62. when: openvpn_cert_is_valid.rc != 0
  63. notify: 'reload openvpn'
  64. tags:
  65. - 'tls_int'
  66. - name: 'write openvpn configuration'
  67. template:
  68. dest: '/etc/config/openvpn'
  69. src: 'openvpn.j2'
  70. owner: 'root'
  71. group: 'root'
  72. mode: '0400'
  73. register: config_updated
  74. notify: 'reload openvpn'
  75. - name: 'commit openvpn configuration to uci'
  76. shell: 'uci commit openvpn'
  77. notify: 'reload openvpn'
  78. when: config_updated.changed