Skip to content

Instantly share code, notes, and snippets.

@aman207
Created July 29, 2022 00:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aman207/61f7531e10f2f01672f81f71d86b8e9b to your computer and use it in GitHub Desktop.
Save aman207/61f7531e10f2f01672f81f71d86b8e9b to your computer and use it in GitHub Desktop.
#change-detection ansible playbook
---
- hosts: all
remote_user: onionadmin
become: true
gather_facts: no
tasks:
- name: install nodejs LTS (v16) repo
shell:
cmd: 'curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -'
creates: /etc/apt/sources.list.d/nodesource.list
warn: false
- name: add partner repo
apt_repository:
repo: deb http://archive.canonical.com/ubuntu focal partner
state: present
#not sure if this is really needed
- name: accept Microsoft EULA agreement for ttf-mscorefonts-installer using debconf
debconf:
name: ttf-mscorefonts-installer
question: msttcorefonts/accepted-mscorefonts-eula
vtype: select
value: true
- name: install dependencies
apt:
name:
- python3-dev
- python3-pip
- nodejs
- build-essential
- ca-certificates
- curl
- dumb-init
- ffmpeg
- fontconfig
- fonts-freefont-ttf
- fonts-gfs-neohellenic
- fonts-indic
- fonts-ipafont-gothic
- fonts-kacst
- fonts-liberation
- fonts-noto-cjk
- fonts-noto-color-emoji
- fonts-roboto
- fonts-thai-tlwg
- fonts-ubuntu
- fonts-wqy-zenhei
- gconf-service
- git
- libappindicator1
- libappindicator3-1
- libasound2
- libatk-bridge2.0-0
- libatk1.0-0
- libc6
- libcairo2
- libcups2
- libdbus-1-3
- libexpat1
- libfontconfig1
- libgbm-dev
- libgbm1
- libgcc1
- libgconf-2-4
- libgdk-pixbuf2.0-0
- libglib2.0-0
- libgtk-3-0
- libnspr4
- libnss3
- libpango-1.0-0
- libpangocairo-1.0-0
- libstdc++6
- libx11-6
- libx11-xcb1
- libxcb1
- libxcomposite1
- libxcursor1
- libxdamage1
- libxext6
- libxfixes3
- libxi6
- libxrandr2
- libxrender1
- libxss1
- libxtst6
- locales
- lsb-release
- msttcorefonts
- pdftk
- unzip
- wget
- xdg-utils
- xvfb
- name: upgrade pip
pip:
name: pip
state: latest
- name: install pip requirements
pip:
name:
- changedetection.io
- playwright
state: latest
- name: npm install puppeteer
npm:
name: puppeteer
state: latest
global: yes
- name: create folders in /opt
file:
name: /opt/{{ item }}
state: directory
owner: onionsystem
group: onionsystem
with_items:
- 'change-detection'
- browserless
- name: git clone browserless
git:
repo: https://github.com/browserless/chrome
dest: /opt/browserless
force: no
ignore_errors: yes
become_user: onionsystem
- name: npm install
command:
cmd: npm install
args:
chdir: /opt/browserless
become_user: onionsystem
- name: npm run build
command:
cmd: npm run build
args:
chdir: /opt/browserless
become_user: onionsystem
- name: npm prune production
command:
cmd: npm prune --production
args:
chdir: /opt/browserless
become_user: onionsystem
- name: copy systemd service files
copy:
src: templates/change-detection/etc/systemd/system
dest: /etc/systemd/system/
owner: root
group: root
mode: '0644'
[Unit]
Description=change-detection.io service
After=network.target browserless.service
Wants=browserless.service
[Service]
User=onionsystem
Group=onionsystem
WorkingDirectory=/opt/change-detection
Environment=PLAYWRIGHT_DRIVER_URL=ws://127.0.0.1:3000/?stealth=1&--disable-web-security=true
ExecStart=/usr/local/bin/changedetection.io -d /opt/change-detection -p 5000
SyslogIdentifier=change-detection
[Install]
WantedBy=default.target
[Unit]
Description=browserless service
After=network.target
[Service]
User=onionsystem
Group=onionsystem
#Better to use an environment file
#https://fedoraproject.org/wiki/Packaging:Systemd#EnvironmentFiles_and_support_for_.2Fetc.2Fsysconfig_files
Environment=APP_DIR=/opt/browserless
Environment=PLAYWRIGHT_BROWSERS_PATH=/opt/browserless
Environment=CONNECTION_TIMEOUT=60000
Environment=HOST=127.0.0.1
Environment=LANG="C.UTF-8"
Environment=NODE_ENV=production
Environment=PORT=3000
Environment=WORKSPACE_DIR=/opt/browserless/workspace
WorkingDirectory=/opt/browserless
ExecStart=/opt/browserless/start.sh
SyslogIdentifier=browserless
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment