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.

105 lines
2.8 KiB

8 years ago
  1. - name: install openvpn-openssl package
  2. opkg:
  3. name: openvpn-openssl
  4. state: present
  5. - name: create openvpn KEY
  6. shell: 'openssl genrsa -out /etc/openvpn/openvpn.key 2048'
  7. args:
  8. creates: /etc/openvpn/openvpn.key
  9. notify: reload openvpn
  10. - name: create openvpn dh2048
  11. shell: 'openssl dhparam -out /etc/openvpn/dh2048.pem 2048'
  12. args:
  13. creates: /etc/openvpn/dh2048.pem
  14. notify: reload openvpn
  15. - name: create CSR
  16. 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'
  17. args:
  18. creates: /etc/openvpn/openvpn.csr
  19. notify: reload openvpn
  20. - name: check if openvpn cert key exist
  21. stat:
  22. path: /etc/openvpn/openvpn.cert
  23. register: openvpn_cert_key
  24. - block:
  25. - name: get pub key
  26. shell: "cat /etc/openvpn/openvpn.csr"
  27. register: pub_key
  28. - debug: var=pub_key verbosity=2
  29. - name: generate host request
  30. set_fact:
  31. cert_request:
  32. type: 'sign_request'
  33. request:
  34. keyType: 'ssl_host'
  35. hostName: '{{ inventory_hostname }}'
  36. keyData: '{{ pub_key.stdout }}'
  37. - debug: var=cert_request verbosity=2
  38. - name: start sign request
  39. raw: "{{ cert_request | to_json }}"
  40. delegate_to: "{{item}}"
  41. delegate_facts: True
  42. with_items: "{{groups['cas']}}"
  43. register: request_result
  44. - debug: var=request_result verbosity=2
  45. - set_fact:
  46. request_output: "{{ request_result.results[0].stdout|string|from_json }}"
  47. - debug: var=request_output
  48. - name: generate get request
  49. set_fact:
  50. get_request:
  51. type: 'get_certificate'
  52. requestID: '{{ request_output.requestID }}'
  53. - debug: var=get_request verbosity=2
  54. - debug: msg="Please manualy confirm sign request with id {{ request_output.requestID }}"
  55. - name: wait for cert
  56. raw: "{{ get_request | to_json }}"
  57. delegate_to: "{{item}}"
  58. delegate_facts: True
  59. with_items: "{{groups['cas']}}"
  60. register: cert_result
  61. - debug: var=cert_result verbosity=2
  62. - set_fact:
  63. cert_key: "{{ cert_result.results[0].stdout|string|from_json }}"
  64. - debug: var=request_output verbosity=2
  65. - name: set pub key
  66. shell: "echo '{{ cert_key.result }}' > /etc/openvpn/openvpn.cert"
  67. register: set_pub_key
  68. when: not openvpn_cert_key.stat.exists
  69. - name: copy vpn ca public key
  70. copy:
  71. src: test_vpn_ca.crt
  72. dest: /etc/openvpn/ca.crt
  73. - name: write openvpn configuration
  74. template:
  75. dest=/etc/config/openvpn
  76. src=openvpn.j2
  77. owner=root
  78. group=root
  79. mode=0400
  80. register: new_vpn_config
  81. notify: reload openvpn
  82. - name: commit openvpn configuration to uci
  83. shell: 'uci commit openvpn'
  84. notify: reload openvpn
  85. when: new_vpn_config.changed