ssl.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. - name: 'Create ssl certificates directory for in /etc/ssl'
  2. file:
  3. path: '/etc/ssl/local/certs/{{ item }}'
  4. state: 'directory'
  5. owner: 'root'
  6. group: 'root'
  7. mode: '0755'
  8. with_items: '{{ ssl_certs }}'
  9. when: ssl_certs
  10. - name: 'Install ssl certificates (certificate)'
  11. copy:
  12. content: "{{lookup('file', 'data/ssl/' + item + '/' + item + '.crt')}}"
  13. dest: '/etc/ssl/local/certs/{{ item }}/cert.pem'
  14. owner: 'root'
  15. group: 'root'
  16. mode: '0640'
  17. register: ssl_cert_result
  18. with_items: '{{ ssl_certs }}'
  19. when: ssl_certs
  20. - name: 'Install ssl certificates (private key)'
  21. copy:
  22. content: "{{lookup('file', 'data/ssl/' + item + '/' + item + '.key')}}"
  23. dest: '/etc/ssl/local/certs/{{ item }}/privkey.pem'
  24. owner: 'root'
  25. group: 'root'
  26. mode: '0640'
  27. register: ssl_key_result
  28. with_items: '{{ ssl_certs }}'
  29. when: ssl_certs
  30. - name: 'Install ssl certificates (chain)'
  31. copy:
  32. content: "{{lookup('file', 'data/ssl/' + item + '/bundle.crt')}}"
  33. dest: '/etc/ssl/local/certs/{{ item }}/chain.pem'
  34. owner: 'root'
  35. group: 'root'
  36. mode: '0644'
  37. register: ssl_chain_result
  38. with_items: '{{ ssl_certs }}'
  39. when: ssl_certs
  40. - name: 'Gathering info about ssl full chain (certificate + chain)'
  41. stat:
  42. path: '/etc/ssl/local/certs/{{ item }}/fullchain.pem'
  43. with_items: '{{ ssl_certs }}'
  44. register: ssl_fullchain_stats
  45. when: ssl_certs
  46. - name: 'Gathering info about ssl bundle (key + fullchain)'
  47. stat:
  48. path: '/etc/ssl/local/certs/{{ item }}/bundle.pem'
  49. with_items: '{{ ssl_certs }}'
  50. register: ssl_bundle_stats
  51. when: ssl_certs
  52. - name: 'Create ssl certificates full chain (certificate + chain)'
  53. shell: sed '/^\s*$/d' '/etc/ssl/local/certs/{{ item.item }}/cert.pem' '/etc/ssl/local/certs/{{ item.item }}/chain.pem' > '/etc/ssl/local/certs/{{ item.item }}/fullchain.pem'
  54. with_items: '{{ ssl_fullchain_stats.results }}'
  55. when: ssl_certs and (not item.stat.exists or ssl_cert_result|changed or ssl_chain_result|changed)
  56. - name: 'Create ssl certificates bundle (key + certificate + bundle)'
  57. shell: sed '/^\s*$/d' '/etc/ssl/local/certs/{{ item.item }}/privkey.pem' '/etc/ssl/local/certs/{{ item.item }}/cert.pem' '/etc/ssl/local/certs/{{ item.item }}/chain.pem' > '/etc/ssl/local/certs/{{ item.item }}/bundle.pem'
  58. with_items: '{{ ssl_bundle_stats.results }}'
  59. when: ssl_certs and (not item.stat.exists or ssl_key_result|changed or ssl_cert_result|changed or ssl_chain_result|changed)
  60. - name: 'Install Lets Encrypt client'
  61. apt:
  62. pkg: 'dehydrated'
  63. state: 'installed'
  64. when: ssl_certs_auto
  65. - name: 'Install Lets Encrypt domains configuration'
  66. template:
  67. src: 'ssl/letsencrypt_domains.j2'
  68. dest: '/etc/dehydrated/domains.txt'
  69. owner: 'root'
  70. group: 'root'
  71. mode: '0644'
  72. when: ssl_certs_auto
  73. - name: 'List Lets Encrypt SSL installed certificates'
  74. shell: find /var/lib/dehydrated/certs -iname privkey.pem | cut -d / -f6
  75. register: ssl_certs_auto_installed
  76. changed_when: False
  77. ignore_errors: True
  78. when: ssl_certs_auto
  79. - name: 'List Lets Encrypt SSL certificates to be generated'
  80. shell: egrep -v '^#' /etc/dehydrated/domains.txt | while read c ; do test -f "/var/lib/dehydrated/certs/${c}/privkey.pem" || echo "${c}" ; done
  81. register: ssl_certs_auto_missing
  82. ignore_errors: True
  83. changed_when: ssl_certs_auto_missing.stdout_lines != []
  84. notify:
  85. - 'Generate Lets Encrypt SSL certificates'
  86. when: ssl_certs_auto
  87. - name: 'Install Lets Encrypt cron job'
  88. template:
  89. src: 'cron/letsencrypt.j2'
  90. dest: '/etc/cron.d/letsencrypt-local'
  91. owner: 'root'
  92. group: 'root'
  93. mode: '0644'
  94. when: ssl_certs_auto