Created
December 15, 2020 22:58
-
-
Save don-rumata/f1c4be6025dcc722ac11f4f8aa48a2c2 to your computer and use it in GitHub Desktop.
Spaghetti code 4 install Rocket.Chat in intranet. 4 https://ru.stackoverflow.com/q/1217999/191416
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# Тут ставим не через snap, а классическим способам с настройками баз и т.д. | |
# https://rocket.chat/docs/installation/manual-installation/ubuntu/ | |
- name: Install Rocket.Chat server Classic | |
# hosts: all | |
hosts: rocketchat | |
strategy: free | |
serial: | |
- "100%" | |
roles: | |
- ansible-role-install-nodejs | |
environment: | |
HTTP_PROXY: 'proxy.cchgeu.ru:3128' | |
HTTPS_PROXY: 'proxy.cchgeu.ru:3128' | |
NO_PROXY: 10.10.11.8,localhost | |
vars: | |
rocketchat_admin_username: sysadmin | |
rocketchat_admin_password: qazwsxedc | |
rocketchat_admin_email: [email protected] | |
rocketchat_linux_service_user: rocketchat | |
rocketchat_linux_service_group: rocketchat | |
# rocketchat_local_ip: 10.10.14.50 | |
server_ip: 10.10.11.87 | |
default_gateway_ipv4: 10.10.11.1 | |
netmask: /24 | |
dns_ip: 10.10.11.41 | |
rocketchat_server_url: https://studchat.cchgeu.ru | |
rocketchat_server_port: 3000 | |
rocketchat_path_to_bin: /opt/Rocket.Chat | |
# curl --silent https://raw.githubusercontent.com/RocketChat/docs/master/installation/manual-installation/ubuntu/README.md | grep '^- Mongodb' | awk '{print $3}' | cut -d '.' -f 1,2 | |
mongodb_version: 4.0 | |
mongodb_server_port: 27017 | |
# mongodb_server_address: localhost | |
# mongodb_server_address: mongodb-01.sql.cchgeu.ru | |
mongodb_server_address: 10.10.11.88 | |
mongodb_replicaset_name: rs01 | |
# Т.к. На 09-04-2020 версия latest-lts, которую я принял за основную ветку и та, что в руководстве рокета - совпадают, то я решил не вводить переменную с версией ноды. Пока что. | |
# nodejs_version: | |
rocketchat_file_storage_type: webdav | |
rocketchat_webdav_backend: ngnix | |
rocketchat_webdav_local_path: /var/www/rocketchat-webdav | |
rocketchat_webdav_url_path: rocketchat-webdav | |
rocketchat_webdav_server_protocol: http | |
rocketchat_webdav_server_address: 127.0.0.1 | |
rocketchat_webdav_server_port: 8080 | |
rocketchat_webdav_server_user: "{{ rocketchat_linux_service_user }}" | |
rocketchat_webdav_server_password: T4m1997FG3PveyIUmmpuKY9e9kGXaCKA | |
tasks: | |
- name: Config linux host network settings | |
when: ansible_system == 'Linux' | |
become: yes | |
block: | |
- template: | |
src: templates/etc/netplan/work.yaml.j2 | |
dest: /etc/netplan/work.yaml | |
backup: yes | |
tags: | |
- linux | |
- network | |
- config | |
- netplan | |
- name: Set Rocket.Chat facts part 1 | |
block: | |
# https://rocket.chat/docs/installation/manual-installation/multiple-instances-to-improve-performance/ | |
# https://stackoverflow.com/a/44407657/5430535 | |
# https://stackoverflow.com/a/44726202/5430535 | |
- set_fact: | |
rocketchat_numbers_instances_fact: "{{ ansible_processor_vcpus | int - 1 | int }}" | |
- set_fact: | |
rocketchat_start_number_port_for_multiple_instances_fact: "{{ rocketchat_server_port | int + 1 | int }}" | |
- set_fact: | |
rocketchat_end_number_port_for_multiple_instances_fact: "{{ rocketchat_start_number_port_for_multiple_instances_fact | int + rocketchat_numbers_instances_fact | int - 1 | int }}" | |
tags: | |
- linux | |
- rocketchat | |
- version | |
- facts | |
- name: Get Rocket.Chat versions | |
when: ansible_system == 'Linux' | |
block: | |
- shell: ps aux | grep -i rocket | grep -v -i grep | |
register: check_run_rocketchat_process | |
ignore_errors: yes | |
- debug: | |
msg: "{{ check_run_rocketchat_process }}" | |
- stat: | |
path: "{{ rocketchat_path_to_bin }}/main.js" | |
register: rocketchat_mainjs_state | |
- uri: | |
url: http://localhost:{{ rocketchat_start_number_port_for_multiple_instances_fact }}/api/info | |
use_proxy: no | |
method: GET | |
return_content: yes | |
register: rocketchat_installed_version | |
when: | |
- rocketchat_mainjs_state.stat.exists == true | |
- check_run_rocketchat_process.rc == 0 | |
- uri: | |
url: http://10.10.11.8/soft/rocketchat/server/latest | |
use_proxy: no | |
method: GET | |
return_content: yes | |
register: rocketchat_available_version | |
tags: | |
- version | |
- name: Set Rocket.Chat facts part 2 | |
block: | |
- set_fact: | |
# rocketchat_update_force: yes | |
rocketchat_update_force: no | |
- set_fact: | |
rocketchat_available_version_fact: "{{ rocketchat_available_version.content }}" | |
when: rocketchat_available_version.status == 200 | |
- set_fact: | |
rocketchat_installed_version_fact: "{{ rocketchat_installed_version.json.version }}" | |
when: | |
- rocketchat_mainjs_state.stat.exists == true | |
- check_run_rocketchat_process.rc == 0 | |
- set_fact: | |
rocketchat_installed_version_fact: "0" | |
when: rocketchat_mainjs_state.stat.exists == false or check_run_rocketchat_process.rc == 1 | |
tags: | |
- linux | |
- rocketchat | |
- version | |
- facts | |
- name: Install Rocket.Chat dependences | |
when: | |
- ansible_system == 'Linux' | |
- rocketchat_installed_version_fact < rocketchat_available_version_fact or rocketchat_update_force == 'yes' | |
# Не надо раскаменчивать! Там всё и так прекрасно с become внутри. Иначе будет вываливать ошибку. | |
# become: yes | |
block: | |
- import_role: | |
name: ansible-role-install-mongodb | |
when: mongodb_server_address == 'localhost' | |
- import_tasks: tasks/install-sshpass.yml | |
tags: | |
- linux | |
- rocketchat | |
- dependences | |
- name: Install Rocket.Chat 4 Ubuntu | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- rocketchat_installed_version_fact < rocketchat_available_version_fact or rocketchat_update_force == 'yes' | |
become: yes | |
block: | |
- service: | |
name: rocketchat | |
state: stopped | |
register: rocketchat_stopped | |
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#controlling-what-defines-failure | |
failed_when: not ('Could not find the requested service' in rocketchat_stopped.msg) | |
ignore_errors: yes | |
# Не я такой злой. Великая Компьютера говорит так делать: https://rocket.chat/docs/installation/updating/ | |
- file: | |
path: "{{ item }}" | |
state: absent | |
force: yes | |
with_items: | |
- /tmp/bundle/ | |
- "{{ rocketchat_path_to_bin }}" | |
- apt: | |
name: | |
- build-essential | |
- nodejs | |
- graphicsmagick | |
state: latest | |
install_recommends: yes | |
- npm: | |
name: "{{ item }}" | |
global: yes | |
state: latest | |
with_items: | |
- inherits | |
- n | |
# Быдлокостыль, но я не знаю как это выразить через модуль npm. | |
# - command: n 12.14.0 | |
# Для теста взял значение отсюда: /data/soft/nodejs/latest-lts | |
- command: n {{ nodejs_latest_version.content }} | |
- get_url: | |
url: http://10.10.11.8/soft/rocketchat/server/rocket.chat.tgz | |
dest: /tmp/rocket.chat.tgz | |
- unarchive: | |
src: /tmp/rocket.chat.tgz | |
dest: /tmp/ | |
remote_src: yes | |
- command: npm install | |
args: | |
chdir: /tmp/bundle/programs/server | |
- synchronize: | |
src: /tmp/bundle/ | |
dest: "{{ rocketchat_path_to_bin }}/" | |
delegate_to: "{{ inventory_hostname }}" | |
- user: | |
name: rocketchat | |
create_home: no | |
password_lock: yes | |
comment: Rocket.Chat Service User | |
system: true | |
shell: /bin/false | |
- file: | |
path: "{{ rocketchat_path_to_bin }}" | |
owner: "{{ rocketchat_linux_service_user }}" | |
group: "{{ rocketchat_linux_service_group }}" | |
recurse: yes | |
- name: Config Rocket.Chat service | |
when: ansible_system == 'Linux' | |
become: yes | |
block: | |
- template: | |
src: templates/etc/systemd/system/rocketchat.service.j2 | |
dest: /lib/systemd/system/rocketchat@{{ item }}.service | |
with_sequence: start={{ rocketchat_start_number_port_for_multiple_instances_fact }} end={{ rocketchat_end_number_port_for_multiple_instances_fact }} | |
- service: | |
name: rocketchat@{{ item }} | |
state: started | |
enabled: yes | |
with_sequence: start={{ rocketchat_start_number_port_for_multiple_instances_fact }} end={{ rocketchat_end_number_port_for_multiple_instances_fact }} | |
- wait_for: | |
port: "{{ item }}" | |
host: localhost | |
state: started | |
with_sequence: start={{ rocketchat_start_number_port_for_multiple_instances_fact }} end={{ rocketchat_end_number_port_for_multiple_instances_fact }} | |
tags: | |
- linux | |
- ubuntu | |
- rocketchat | |
- chat | |
- install | |
- service | |
# - name: Install webdav support 4 Rocket.Chat | |
# when: | |
# - ansible_system == 'Linux' | |
# - rocketchat_file_storage_type == 'webdav' | |
# - rocketchat_webdav_server_address == '127.0.0.1' | |
# become: yes | |
# block: | |
# - package: | |
# name: nginx | |
# state: latest | |
# tags: | |
# - linux | |
# - rocketchat | |
# - webdav |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment