main.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ---
  2. - name: Install apt-add-repository
  3. apt:
  4. name: '{{ packages }}'
  5. state: present
  6. update_cache: yes
  7. vars:
  8. packages:
  9. - apt-transport-https
  10. - ca-certificates
  11. - curl
  12. - gnupg2
  13. - software-properties-common
  14. - name: Add Docker's GPG key
  15. shell: curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
  16. args:
  17. warn: False # Piping
  18. - name: Add Docker's apt repository
  19. shell: add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
  20. - name: Install Docker
  21. apt:
  22. name: '{{ packages }}'
  23. state: present
  24. update_cache: yes
  25. vars:
  26. packages:
  27. - docker-ce
  28. - docker-ce-cli
  29. - containerd.io
  30. - name: Add '{{ user }}' to docker group
  31. user:
  32. name: '{{ user }}'
  33. groups: docker
  34. append: yes
  35. - name: Install docker-compose
  36. shell: curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
  37. args:
  38. warn: False # Calls to uname
  39. - name: Copy compose config
  40. copy:
  41. src: templates/web/compose
  42. dest: '/home/{{ user }}'
  43. owner: '{{ user }}'
  44. group: '{{ user }}'
  45. mode: "600"
  46. - name: Install NFS common
  47. apt:
  48. name: nfs-common
  49. state: present
  50. update_cache: yes
  51. - name: Create mountable dir
  52. file:
  53. path: /nfs
  54. state: directory
  55. mode: u=rwx,g=r,o=r
  56. owner: '{{ user }}'
  57. group: '{{ user }}'
  58. - name: set mountpoints
  59. mount:
  60. name: /nfs
  61. src: 172.20.69.1:/nfs
  62. fstype: nfs
  63. state: mounted
  64. - name: Install certbot
  65. get_url:
  66. url: https://dl.eff.org/certbot-auto
  67. dest: /usr/local/bin/certbot-auto
  68. mode: u=rwx,g=r,o=r
  69. owner: root
  70. group: root
  71. - name: Install pip
  72. apt:
  73. name: python-pip
  74. state: present
  75. - name: Install certbot's cloudflare plugin
  76. pip:
  77. name: certbot-dns-cloudflare
  78. extra_args: --user
  79. - name: Write example cloudflare secrets file
  80. copy:
  81. src: templates/web/cloudflare.ini.example
  82. dest: /root/cloudflare.ini.example
  83. mode: "0700"
  84. owner: root
  85. group: root
  86. - name: Run certbot
  87. shell: certbot renew --dns-cloudflare --dns-cloudflare-credentials /root/cloudflare.ini -d jibby.org,\*.jibby.org --preferred-challenges dns-01
  88. - name: Schedule certbot renewal cronjobs and copying of static cert files (for sharing with Docker)
  89. cron:
  90. name: "renew certs and copy"
  91. special_time: weekly
  92. job: '/root/.local/bin/certbot renew --post-hook "mkdir -p /static_certs && cp -L /etc/letsencrypt/live/jibby.org/cert.pem /static_certs/jibby.org.crt && cp -L /etc/letsencrypt/live/jibby.org/privkey.pem /static_certs/jibby.org.key && cp -L /etc/letsencrypt/live/jibby.org-0001/cert.pem /static_certs/shared.crt && cp -L /etc/letsencrypt/live/jibby.org-0001/privkey.pem /static_certs/shared.key && docker restart compose_nginx_proxy_1"'