main.yml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. # TODO the certbot installation process probably needs fixing
  65. - name: Install pip
  66. apt:
  67. name: python-pip
  68. state: present
  69. - name: Install certbot's cloudflare plugin
  70. pip:
  71. name: certbot-dns-cloudflare
  72. extra_args: --user
  73. - name: Write example cloudflare secrets file
  74. copy:
  75. src: templates/web/cloudflare.ini.example
  76. dest: /root/cloudflare.ini.example
  77. mode: "0700"
  78. owner: root
  79. group: root
  80. - name: Run certbot
  81. shell: /root/.local/bin/certbot renew --dns-cloudflare --dns-cloudflare-credentials /root/cloudflare.ini -d jibby.org,\*.jibby.org --preferred-challenges dns-01
  82. ignore_errors: yes # This fails if the certs already exist
  83. - name: Schedule certbot renewal cronjob
  84. cron:
  85. name: "renew certs"
  86. special_time: weekly
  87. job: '/root/.local/bin/certbot renew'
  88. - name: Set outward facing nginx server
  89. copy:
  90. src: templates/web/docker.conf
  91. dest: /etc/nginx/conf.d/docker.conf
  92. mode: "0644"
  93. owner: root
  94. group: root
  95. - name: Remove default nginx site
  96. file:
  97. path: /etc/nginx/sites-enabled/default
  98. state: absent
  99. - name: Start and enable Nginx
  100. service:
  101. name: nginx
  102. state: started
  103. enabled: yes