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.

113 lines
2.6 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
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. - name: create openvpn KEY
  7. shell: 'openssl genrsa -out {{ openvpn_key }} 2047'
  8. args:
  9. creates: "{{ openvpn_key }}"
  10. notify: reload openvpn
  11. - name: create openvpn dh2048
  12. shell: 'openssl dhparam -out /etc/openvpn/dh2048.pem 2048'
  13. args:
  14. creates: /etc/openvpn/dh2048.pem
  15. notify: reload openvpn
  16. - name: create CSR
  17. shell: 'openssl req -new -sha256 -subj "/C=IT/ST=ITALY/L=TUSCANY/O=IT/CN={{ ansible_hostname }}.lilik.it" -key /etc/openvpn/openvpn.key -out /etc/openvpn/openvpn.csr'
  18. args:
  19. creates: "{{ openvpn_csr }}"
  20. notify: reload openvpn
  21. - name: check if openvpn cert key exist
  22. stat:
  23. path: "{{ openvpn_crt }}"
  24. register: openvpn_cert_key
  25. - block:
  26. - name: get pub key
  27. shell: "cat /etc/openvpn/openvpn.csr"
  28. register: pub_key
  29. - debug:
  30. var: pub_key
  31. verbosity: 2
  32. - name: generate host request
  33. set_fact:
  34. ca_request:
  35. type: 'sign_request'
  36. request:
  37. keyType: 'ssl_host'
  38. hostName: '{{ inventory_hostname }}.lilik.it'
  39. keyData: '{{ pub_key.stdout }}'
  40. - debug:
  41. var: cert_request
  42. verbosity: 2
  43. - name: start sign request
  44. include: ca-dialog.yaml
  45. - set_fact:
  46. request_output: "{{ request_result.stdout | string | from_json }}"
  47. - debug:
  48. var: request_output
  49. - name: generate get request
  50. set_fact:
  51. ca_request:
  52. type: 'get_certificate'
  53. requestID: '{{ request_output.requestID }}'
  54. - debug:
  55. msg: "Please manualy confirm sign request with id {{ request_output.requestID }}"
  56. - name: wait for cert
  57. include: ca-dialog.yaml
  58. - set_fact:
  59. cert_key: "{{ request_result.stdout | string | from_json }}"
  60. - debug:
  61. var: request_result
  62. verbosity: 2
  63. - name: set pub key
  64. copy:
  65. content: "{{ cert_key.result }}"
  66. dest: "{{ openvpn_crt }}"
  67. register: set_pub_key
  68. when: not openvpn_cert_key.stat.exists
  69. - set_fact:
  70. certificates:
  71. - files/lilik_ca_x1.pub
  72. - files/lilik_ca_v1.pub
  73. - name: create vpn fullchain
  74. template:
  75. src: fullchain.j2
  76. dest: /etc/openvpn/fullchain.crt
  77. notify: reload openvpn
  78. - name: write openvpn configuration
  79. template:
  80. dest: /etc/config/openvpn
  81. src: openvpn.j2
  82. owner: root
  83. group: root
  84. mode: 0400
  85. register: new_vpn_config
  86. notify: reload openvpn
  87. - name: commit openvpn configuration to uci
  88. shell: 'uci commit openvpn'
  89. notify: reload openvpn
  90. when: new_vpn_config.changed