NewsBlur/ansible/roles/node/tasks/main.yml

152 lines
3.9 KiB
YAML
Raw Normal View History

2021-02-02 23:40:09 -05:00
---
- name: Copy node secrets
copy:
src: /srv/secrets-newsblur/settings/node_settings.env
dest: /srv/newsblur/node/.env
register: app_changed
2021-03-17 09:31:19 -04:00
notify: restart node
with_items:
- node-socket
- node-page
- node-text
- node-favicons
- staging
when: item in inventory_hostname
- name: Add SERVER_NAME to app secrets
lineinfile:
path: /srv/newsblur/node/.env
line: 'SERVER_NAME = "{{ inventory_hostname }}"'
2021-07-22 21:16:33 -04:00
- name: Get the volume name
shell: ls /dev/disk/by-id/ | grep -v part
register: volume_name_raw
when: '"node-page" in inventory_hostname'
- set_fact:
volume_name: "{{ volume_name_raw.stdout }}"
when: '"node-page" in inventory_hostname'
- debug:
msg: "{{ volume_name }}"
when: '"node-page" in inventory_hostname'
- name: Create the mount point
become: yes
file:
path: "/mnt/{{ inventory_hostname | regex_replace('-', '') }}"
state: directory
when: '"node-page" in inventory_hostname'
- name: Mount volume read-write
become: yes
mount:
path: "/mnt/{{ inventory_hostname | regex_replace('-', '') }}"
src: "/dev/disk/by-id/{{ volume_name }}"
fstype: xfs
opts: defaults,discard
state: mounted
when: '"node-page" in inventory_hostname'
- name: Symlink node-page volume from /srv/originals
become: yes
file:
dest: /srv/originals
src: "/mnt/{{ inventory_hostname | regex_replace('-', '') }}"
state: link
when: '"node-page" in inventory_hostname'
- name: Make docker network for newsblurnet
become: yes
docker_network:
name: newsblurnet
notify: restart docker
2021-02-02 23:40:09 -05:00
- name: Start node docker containers
become: yes
2021-02-10 17:11:28 -05:00
docker_container:
name: node
2021-02-10 17:11:28 -05:00
image: newsblur/newsblur_node
state: started
command: node /srv/node/newsblur.js
container_default_behavior: no_defaults
2021-02-10 17:11:28 -05:00
pull: true
networks_cli_compatible: yes
network_mode: default
networks:
- name: newsblurnet
ports:
- "8008:8008"
2021-02-10 17:11:28 -05:00
env:
NODE_ENV: "production"
2021-02-10 17:11:28 -05:00
restart_policy: unless-stopped
volumes:
- /srv/newsblur/node:/srv/node
2021-07-22 21:16:33 -04:00
- /srv/originals:/srv/originals
2021-07-22 22:26:44 -04:00
- "/mnt/{{ inventory_hostname | regex_replace('-', '') }}:/mnt/{{ inventory_hostname | regex_replace('-', '') }}"
2021-02-02 23:40:09 -05:00
with_items:
- node-socket
- node-page
- node-text
- node-favicons
- staging
when: item in inventory_hostname
2021-02-15 19:16:08 -05:00
- name: Start non-newsblur node docker containers
become: yes
docker_container:
name: "{{ item.container_name }}"
image: "{{ item.image }}"
state: started
container_default_behavior: no_defaults
pull: true
2021-03-17 08:22:23 -04:00
ports:
- "{{ item.ports }}"
env:
NODE_ENV: "production"
restart_policy: unless-stopped
volumes:
- /srv/newsblur/node:/srv/node
with_items:
- container_name: imageproxy
image: willnorris/imageproxy
2021-03-17 08:22:23 -04:00
ports: 8088:8080
target_host: node-images
when: item.target_host in inventory_hostname
2021-02-15 19:16:08 -05:00
- name: Register nodes in consul
tags: consul
2021-02-15 19:16:08 -05:00
become: yes
template:
src: consul_service.json
2021-03-17 08:22:23 -04:00
dest: /etc/consul.d/{{item.target_host}}.json
2021-02-15 19:16:08 -05:00
with_items:
2021-03-17 08:22:23 -04:00
- target_host: node-socket
port: 8008
- target_host: node-page
port: 8008
- target_host: node-text
port: 8008
- target_host: node-favicons
port: 8008
- target_host: node-images
port: 8088
2021-02-15 19:16:08 -05:00
notify:
- reload consul
when: item.target_host in inventory_hostname and disable_consul_services_ie_staging is not defined
2021-06-07 15:44:59 -04:00
- name: Add sanity checkers cronjob for disk usage
2021-06-07 15:44:59 -04:00
become: yes
cron:
name: disk_usage_sanity_checker
user: root
cron_file: /etc/cron.hourly/disk_usage_sanity_checker
job: >-
docker pull newsblur/newsblur_python3:latest;
docker run --rm -it
OUTPUT=$(eval sudo df / | head -n 2 | tail -1);
-v /srv/newsblur:/srv/newsblur
--network=newsblurnet
--hostname {{ ansible_hostname }}
newsblur/newsblur_python3 /srv/newsblur/utils/monitor_disk_usage.py $OUTPUT