main.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. - name: install nginx
  2. apt:
  3. pkg: "{{ item }}"
  4. update_cache: no
  5. state: latest
  6. with_items:
  7. - nginx
  8. - name: create letsencrypt directory
  9. file: name=/var/www/letsencrypt state=directory
  10. - name: Install default nginx site for letsencrypt requests and https rewrite
  11. template:
  12. src: templates/default.j2
  13. dest: /etc/nginx/sites-available/default
  14. register: gendefconf
  15. - name: Activate default nginx site
  16. file: src=/etc/nginx/sites-available/default dest=/etc/nginx/sites-enabled/default state=link
  17. register: actdefconf
  18. - name: Reload nginx to activate letsencrypt site
  19. service: name=nginx state=restarted
  20. when: gendefconf.changed or actdefconf.changed
  21. - name: acme install
  22. shell: wget -O - https://get.acme.sh | sh
  23. args:
  24. creates: /root/.acme.sh/acme.sh
  25. - name: Create certificate
  26. shell: /root/.acme.sh/acme.sh --issue -d {{inventory_hostname_short}}.{{freifunk.domain}} -w /var/www/letsencrypt
  27. args:
  28. creates: /root/.acme.sh/{{inventory_hostname_short}}.{{freifunk.domain}}/ca.cer
  29. - name: install cert to Nginx
  30. shell: /root/.acme.sh/acme.sh --installcert -d {{inventory_hostname_short}}.{{freifunk.domain}} --keypath "/etc/ssl/key.pem" --fullchainpath "/etc/ssl/fullchain.pem" --reloadcmd "systemctl restart nginx"
  31. args:
  32. creates: /etc/ssl/certs/key.pem
  33. - name: Generate dhparams
  34. shell: openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
  35. args:
  36. creates: /etc/ssl/certs/dhparam.pem
  37. - name: Create nginx caching dir
  38. file:
  39. path: /opt/hopglass_nginx_cache
  40. state: directory
  41. - name: Create nginx caching dirs for tiles caching
  42. file:
  43. path: "{{item.path}}"
  44. state: directory
  45. with_items:
  46. - "{{nginx_tiles_cache.cache_locations}}"
  47. when: nginx_tiles_cache is defined and "cache_locations" in nginx_tiles_cache
  48. - name: Define cache in nginx.conf
  49. lineinfile:
  50. regexp: "^[\t ]*proxy_cache_path.*hopglass"
  51. line: "\tproxy_cache_path /opt/hopglass_nginx_cache levels=1:2 keys_zone=hopglass:10m inactive=1h max_size=1g;"
  52. insertafter: "^[\t ]*http[\t ]*\\{"
  53. dest: /etc/nginx/nginx.conf
  54. notify:
  55. - restart nginx
  56. - name: Define include for tiles cache in nginx.conf
  57. lineinfile:
  58. regexp: "^[\t ]*include /etc/nginx/tiles_cache.conf;"
  59. line: "\tinclude /etc/nginx/tiles_cache.conf;"
  60. insertafter: "^[\t ]*http[\t ]*\\{"
  61. dest: /etc/nginx/nginx.conf
  62. notify:
  63. - restart nginx
  64. when: nginx_tiles_cache is defined
  65. - name: Deploy tiles_cache.conf
  66. template:
  67. src: tiles_cache.conf.j2
  68. dest: /etc/nginx/tiles_cache.conf
  69. notify:
  70. - restart nginx
  71. when: nginx_tiles_cache is defined
  72. - name: Deploy default ssl nginx site
  73. template:
  74. src: default_ssl.j2
  75. dest: /etc/nginx/sites-available/default_ssl
  76. notify:
  77. - restart nginx
  78. - name: Aktivate default ssl nginx site
  79. file: src=/etc/nginx/sites-available/default_ssl dest=/etc/nginx/sites-enabled/default_ssl state=link
  80. register: actsslconf
  81. - name: Reload nginx to activate letsencrypt site
  82. service: name=nginx state=restarted
  83. when: actsslconf.changed
  84. - name: Create nginx caching dir
  85. file:
  86. path: /var/www/html/temp/
  87. state: directory
  88. - name: Clone bootstrap and css files
  89. git: repo=https://github.com/FreiFunkMuenster/nodesmap-page.git dest=/var/www/html/temp/ force=yes
  90. - name: Generate index.html
  91. template:
  92. src: index.html.j2
  93. dest: /var/www/html/index.html
  94. - name: link hopglass
  95. file:
  96. src: /opt/hopglass/client/build
  97. dest: /var/www/html/map
  98. state: link
  99. - name: link hwpics
  100. file:
  101. src: /opt/hopglass/hwpics/nodes
  102. dest: /var/www/html/hwpics
  103. state: link