Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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: Media cleanup cronjob
  188. cron:
  189. name: "media cleanup"
  190. minute: "15"
  191. hour: "1"
  192. job: '/bin/bash -c ''export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd /home/mastodon/mastodon && RAILS_ENV=production ./bin/tootctl media remove'''
  193. become: true
  194. become_user: mastodon
  195. - name: Add mastodon postgres user
  196. postgresql_user:
  197. login_host=localhost
  198. login_user={{ db_admin_username }}
  199. login_password="{{ db_admin_password }}"
  200. name={{ mastodon_db_username }}
  201. password="{{ mastodon_db_password }}"
  202. role_attr_flags=CREATEDB
  203. encrypted=yes
  204. state=present
  205. - name: Create mastodon database
  206. postgresql_db:
  207. login_host=localhost
  208. login_user={{ db_admin_username }}
  209. login_password="{{ db_admin_password }}"
  210. name={{ mastodon_db_database }}
  211. state=present
  212. owner={{ mastodon_db_username }}
  213. - name: Create mastodon data directory
  214. file: state=directory path=/data/{{ item }} owner=mastodon group=www-data
  215. with_items:
  216. - mastodon
  217. - mastodon/public-system
  218. - name: Generate VAPID keys
  219. shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rake mastodon:webpush:generate_vapid_key > /home/mastodon/vapid_keys_generated"
  220. args:
  221. chdir: /home/mastodon/mastodon
  222. creates: /home/mastodon/vapid_keys_generated
  223. become: true
  224. become_user: mastodon
  225. - name: Remove previous mastodon config
  226. file: state=absent path=/home/mastodon/mastodon/.env.production
  227. - name: Install mastodon config
  228. template:
  229. src: home_mastodon_mastodon_env.j2
  230. dest: /home/mastodon/mastodon/.env.production
  231. owner: mastodon
  232. group: mastodon
  233. notify: restart mastodon
  234. - name: Append VAPID keys to new config
  235. shell: "cat /home/mastodon/vapid_keys_generated >> /home/mastodon/mastodon/.env.production"
  236. become: true
  237. become_user: mastodon
  238. - name: Set mastodon ownership
  239. action: file owner=mastodon group=www-data path=/home/mastodon/mastodon recurse=yes state=directory
  240. # This is a no-op in case nothing has to be upgraded
  241. - name: Migrate database
  242. shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails db:migrate"
  243. args:
  244. chdir: "/home/mastodon/mastodon"
  245. become: true
  246. become_user: mastodon
  247. # MAY be needed on upgrades, but takes a long time, so commented out for now. See:
  248. # https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Updating-Mastodon-Guide.md#pre-compiling-updated-assets
  249. #- name: Precompile assets
  250. # shell: "RAILS_ENV=production ~/.rbenv/shims/bundle exec rails assets:precompile"
  251. # args:
  252. # chdir: "/home/mastodon/mastodon"
  253. # become: true
  254. # become_user: mastodon
  255. - name: Register new Mastodon services
  256. systemd: name={{ item }} daemon_reload=yes enabled=yes
  257. with_items:
  258. - mastodon-web
  259. - mastodon-streaming
  260. - mastodon-sidekiq
  261. - name: Start new Mastodon services
  262. service: name={{ item }} state=restarted
  263. with_items:
  264. - mastodon-web
  265. - mastodon-streaming
  266. - mastodon-sidekiq
  267. - name: Add redirect to well-known
  268. template:
  269. src=var_www_well-known_host-meta.j2
  270. dest=/var/www/well-known/host-meta
  271. owner=www-data
  272. group=www-data
  273. - name: Enable Apache websockets proxy module
  274. command: a2enmod proxy_wstunnel creates=/etc/apache2/mods-enabled/proxy_wstunnel.load
  275. notify: restart apache
  276. - name: Enable Apache alias module
  277. command: a2enmod alias creates=/etc/apache2/mods-enabled/alias.load
  278. notify: restart apache
  279. - name: Create the Apache Matrix sites config files
  280. template:
  281. src=etc_apache2_sites-available_mastodon.j2
  282. dest=/etc/apache2/sites-available/mastodon_{{ item.name }}.conf
  283. owner=root
  284. group=root
  285. with_items: "{{ virtual_domains }}"
  286. notify: restart apache
  287. - name: Enable Apache sites (creates new sites-enabled symlinks)
  288. command: a2ensite mastodon_{{ item }}.conf creates=/etc/apache2/sites-enabled/mastodon_{{ item }}.conf
  289. notify: restart apache
  290. with_items: "{{ virtual_domains | json_query('[*].name') }}"