Bez popisu
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.

mastodon.yml 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. - name: Install Mastodon dependency repository keys
  2. apt_key: url={{ item }} state=present
  3. with_items:
  4. - "https://dl.yarnpkg.com/debian/pubkey.gpg"
  5. - "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
  6. tags:
  7. - dependencies
  8. - name: Install Mastodon dependency repositories
  9. apt_repository: repo={{ item }} state=present
  10. become: yes
  11. with_items:
  12. - "deb https://dl.yarnpkg.com/debian/ stable main"
  13. - "deb https://deb.nodesource.com/node_8.x {{ ansible_distribution_release }} main"
  14. tags:
  15. - dependencies
  16. - name: Install Mastodon dependencies from official repositories
  17. apt:
  18. name: "{{ packages }}"
  19. state: present
  20. update_cache: yes
  21. vars:
  22. packages:
  23. - autoconf
  24. - bison
  25. - build-essential
  26. - curl
  27. - cron
  28. - ffmpeg
  29. - file
  30. - g++
  31. - gcc
  32. - git
  33. - python
  34. - imagemagick
  35. - libffi-dev
  36. - libgdbm-dev
  37. - libicu-dev
  38. - libidn11-dev
  39. - libncurses5-dev
  40. - libpq-dev
  41. - libprotobuf-dev
  42. - libreadline-dev
  43. - libssl-dev
  44. - libxml2-dev
  45. - libxslt1-dev
  46. - libyaml-dev
  47. - nodejs
  48. - pkg-config
  49. - protobuf-compiler
  50. - yarn
  51. - zlib1g-dev
  52. - python-psycopg2
  53. - redis-server
  54. - redis-tools
  55. tags:
  56. - dependencies
  57. - name: nodejs alternative
  58. alternatives:
  59. name: node
  60. link: /usr/bin/node
  61. path: /usr/bin/nodejs
  62. tags:
  63. - dependencies
  64. - name: Create Mastodon user
  65. user:
  66. name: mastodon
  67. createhome: true
  68. shell: /bin/bash
  69. home: /home/mastodon
  70. - name: Stop old mastodon services
  71. service: name={{ item }} state=stopped
  72. with_items:
  73. - mastodon-web
  74. - mastodon-streaming
  75. - mastodon-sidekiq
  76. ignore_errors: True
  77. - name: Clone rbenv
  78. git:
  79. repo: "https://github.com/rbenv/rbenv.git"
  80. dest: "~/.rbenv"
  81. clone: true
  82. version: "{{ rbenv_version }}"
  83. become: true
  84. become_user: mastodon
  85. - name: Clone ruby-build
  86. git:
  87. repo: "https://github.com/rbenv/ruby-build.git"
  88. dest: "~/.rbenv/plugins/ruby-build"
  89. clone: true
  90. version: "{{ ruby_build_version }}"
  91. register: ruby_build
  92. become: true
  93. become_user: mastodon
  94. - name: Configure rbenv
  95. command: ./configure
  96. args:
  97. chdir: "~/.rbenv/src"
  98. register: rbenv_configure
  99. become: true
  100. become_user: mastodon
  101. - name: Build rbenv
  102. command: make
  103. args:
  104. chdir: "~/.rbenv/src"
  105. when: rbenv_configure is succeeded
  106. become: true
  107. become_user: mastodon
  108. - name: Update profile settings
  109. copy:
  110. dest: "~/.bashrc"
  111. content: |
  112. export PATH="~/.rbenv/bin:${PATH}"
  113. eval "$(rbenv init -)"
  114. become: true
  115. become_user: mastodon
  116. - name: Check if the Ruby version is already installed
  117. shell: "~/.rbenv/bin/rbenv versions | grep -q {{ ruby_version }}"
  118. register: ruby_installed
  119. ignore_errors: yes
  120. check_mode: no
  121. become: true
  122. become_user: mastodon
  123. - name: Install Ruby {{ ruby_version }}
  124. shell: "~/.rbenv/bin/rbenv install {{ ruby_version }}"
  125. args:
  126. executable: /bin/bash
  127. when: ruby_installed is failed
  128. become: true
  129. become_user: mastodon
  130. - name: Set the default Ruby version to {{ ruby_version }}
  131. shell: "~/.rbenv/bin/rbenv global {{ ruby_version }}"
  132. args:
  133. executable: /bin/bash
  134. register: default_ruby_version
  135. become: true
  136. become_user: mastodon
  137. - name: Install bundler
  138. shell: 'export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; gem install bundler'
  139. args:
  140. executable: /bin/bash
  141. when: default_ruby_version is succeeded
  142. become: true
  143. become_user: mastodon
  144. - name: Clone mastodon
  145. git:
  146. repo: "https://github.com/tootsuite/mastodon.git"
  147. dest: "/home/mastodon/mastodon"
  148. clone: true
  149. become: true
  150. become_user: mastodon
  151. - name: Update to latest version
  152. shell: "git fetch; git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
  153. args:
  154. chdir: "/home/mastodon/mastodon"
  155. become: true
  156. become_user: mastodon
  157. - name: Bundle install
  158. shell: "~/.rbenv/shims/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --with development --without test"
  159. args:
  160. chdir: "/home/mastodon/mastodon"
  161. become: true
  162. become_user: mastodon
  163. - name: Yarn install
  164. command: yarn install --pure-lockfile
  165. args:
  166. chdir: "/home/mastodon/mastodon"
  167. become: true
  168. become_user: mastodon
  169. - name: Install systemd sidekiq Service Files
  170. copy:
  171. src: etc_systemd_system_mastodon-sidekiq.service
  172. dest: /etc/systemd/system/mastodon-sidekiq.service
  173. owner: root
  174. group: root
  175. - name: Install systemd web Service Files
  176. copy:
  177. src: etc_systemd_system_mastodon-web.service
  178. dest: /etc/systemd/system/mastodon-web.service
  179. owner: root
  180. group: root
  181. - name: Install systemd streaming Service Files
  182. copy:
  183. src: etc_systemd_system_mastodon-streaming.service
  184. dest: /etc/systemd/system/mastodon-streaming.service
  185. owner: root
  186. group: root
  187. - name: Set mastodon cron mail target
  188. cron:
  189. name: MAILTO
  190. env: yes
  191. value: "{{ admin_email }}"
  192. user: mastodon
  193. - name: Media cleanup cronjob
  194. cron:
  195. name: "media cleanup"
  196. minute: "15"
  197. hour: "1"
  198. job: '/bin/bash -c ''export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd /home/mastodon/mastodon && RAILS_ENV=production ./bin/tootctl media remove > /dev/null'''
  199. become: true
  200. become_user: mastodon
  201. - name: Add mastodon postgres user
  202. postgresql_user:
  203. login_host=localhost
  204. login_user={{ db_admin_username }}
  205. login_password="{{ db_admin_password }}"
  206. name={{ mastodon_db_username }}
  207. password="{{ mastodon_db_password }}"
  208. role_attr_flags=CREATEDB
  209. encrypted=yes
  210. state=present
  211. - name: Create mastodon database
  212. postgresql_db:
  213. login_host=localhost
  214. login_user={{ db_admin_username }}
  215. login_password="{{ db_admin_password }}"
  216. name={{ mastodon_db_database }}
  217. state=present
  218. owner={{ mastodon_db_username }}
  219. - name: Create mastodon data directory
  220. file: state=directory path=/data/{{ item }} owner=mastodon group=www-data
  221. with_items:
  222. - mastodon
  223. - mastodon/public-system
  224. - name: Generate VAPID keys
  225. shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rake mastodon:webpush:generate_vapid_key > /home/mastodon/vapid_keys_generated"
  226. args:
  227. chdir: /home/mastodon/mastodon
  228. creates: /home/mastodon/vapid_keys_generated
  229. become: true
  230. become_user: mastodon
  231. - name: Remove previous mastodon config
  232. file: state=absent path=/home/mastodon/mastodon/.env.production
  233. - name: Install mastodon config
  234. template:
  235. src: home_mastodon_mastodon_env.j2
  236. dest: /home/mastodon/mastodon/.env.production
  237. owner: mastodon
  238. group: mastodon
  239. notify: restart mastodon
  240. - name: Append VAPID keys to new config
  241. shell: "cat /home/mastodon/vapid_keys_generated >> /home/mastodon/mastodon/.env.production"
  242. become: true
  243. become_user: mastodon
  244. - name: Set mastodon ownership
  245. action: file owner=mastodon group=www-data path=/home/mastodon/mastodon recurse=yes state=directory
  246. # This is a no-op in case nothing has to be upgraded
  247. - name: Migrate database
  248. shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails db:migrate"
  249. args:
  250. chdir: "/home/mastodon/mastodon"
  251. become: true
  252. become_user: mastodon
  253. # MAY be needed on upgrades, but takes a long time, so commented out for now. See:
  254. # https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Updating-Mastodon-Guide.md#pre-compiling-updated-assets
  255. #- name: Precompile assets
  256. # shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails assets:precompile"
  257. # args:
  258. # chdir: "/home/mastodon/mastodon"
  259. # become: true
  260. # become_user: mastodon
  261. - name: Register new Mastodon services
  262. systemd: name={{ item }} daemon_reload=yes enabled=yes
  263. with_items:
  264. - mastodon-web
  265. - mastodon-streaming
  266. - mastodon-sidekiq
  267. - name: Start new Mastodon services
  268. service: name={{ item }} state=restarted
  269. with_items:
  270. - mastodon-web
  271. - mastodon-streaming
  272. - mastodon-sidekiq
  273. - name: Add redirect to well-known
  274. template:
  275. src=var_www_well-known_host-meta.j2
  276. dest=/var/www/well-known/host-meta
  277. owner=www-data
  278. group=www-data
  279. - name: Enable Apache websockets proxy module
  280. command: a2enmod proxy_wstunnel creates=/etc/apache2/mods-enabled/proxy_wstunnel.load
  281. notify: restart apache
  282. - name: Enable Apache alias module
  283. command: a2enmod alias creates=/etc/apache2/mods-enabled/alias.load
  284. notify: restart apache
  285. - name: Create the Apache Matrix sites config files
  286. template:
  287. src=etc_apache2_sites-available_mastodon.j2
  288. dest=/etc/apache2/sites-available/mastodon_{{ item.name }}.conf
  289. owner=root
  290. group=root
  291. with_items: "{{ virtual_domains }}"
  292. notify: restart apache
  293. - name: Enable Apache sites (creates new sites-enabled symlinks)
  294. command: a2ensite mastodon_{{ item }}.conf creates=/etc/apache2/sites-enabled/mastodon_{{ item }}.conf
  295. notify: restart apache
  296. with_items: "{{ virtual_domains | json_query('[*].name') }}"