diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..3347a36 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +**Description/Goals** +_Why did you make this PR?_ + +**Summary of Changes** +_Example_ +* I updated the metrics inventory to target the correct host. + +**Tasks Before Merging** +_Do you need to remember to do anything BEFORE merging?_ \ No newline at end of file diff --git a/inventories/nostr_sync/inventory.yml b/inventories/nostr_sync/inventory.yml new file mode 100644 index 0000000..87c05e8 --- /dev/null +++ b/inventories/nostr_sync/inventory.yml @@ -0,0 +1,9 @@ +--- +nostr_sync: + vars: + ansible_user: admin + ansible_become: true + admin_username: admin + venv_path: "/home/{{ admin_username }}/sync_venv" + hosts: + sync.nos.social: \ No newline at end of file diff --git a/playbooks/nostr_sync.yml b/playbooks/nostr_sync.yml new file mode 100644 index 0000000..54e2621 --- /dev/null +++ b/playbooks/nostr_sync.yml @@ -0,0 +1,4 @@ +- name: Configure the nostr-sync server + hosts: nostr_sync + roles: + - nostr_sync diff --git a/roles/nostr_sync/README.md b/roles/nostr_sync/README.md new file mode 100644 index 0000000..2d80475 --- /dev/null +++ b/roles/nostr_sync/README.md @@ -0,0 +1 @@ +# Nostr Sync \ No newline at end of file diff --git a/roles/nostr_sync/tasks/main.yml b/roles/nostr_sync/tasks/main.yml new file mode 100644 index 0000000..48af83e --- /dev/null +++ b/roles/nostr_sync/tasks/main.yml @@ -0,0 +1,73 @@ +--- +- name: Update cache + ansible.builtin.apt: + update_cache: true + +- name: Ensure required packages are installed + ansible.builtin.package: + name: + - python3 + - python3-pip + - python3-venv + - pkg-config + - util-linux # for flock + state: present + +- name: Create venv + ansible.builtin.shell: + cmd: "python3 -m venv {{ venv_path }}" + +- name: Make venv activate script executable + ansible.builtin.file: + path: "{{ venv_path }}/bin/activate" + mode: '0755' + +- name: Upgrade pip + ansible.builtin.command: + cmd: "{{ venv_path }}/bin/python -m pip install --upgrade pip" + creates: "{{ venv_path }}/bin/pip" + +- name: Clone our Repo + ansible.builtin.git: + repo: https://github.com/verse-pbc/nostr-sync-scripts + dest: /home/{{ admin_username }}/nostr-sync-scripts + version: 'main' + force: yes + +- name: Clean up old .pyc files and __pycache__ directories + ansible.builtin.file: + path: "{{ item }}" + state: absent + with_fileglob: + - "/home/{{ admin_username }}/nostr-sync-scripts/**/*.pyc" + - "/home/{{ admin_username }}/nostr-sync-scripts/**/__pycache__" + +- name: Create lock directory + ansible.builtin.file: + path: /var/lock/nostr-sync + state: directory + mode: '0755' + owner: "{{ admin_username }}" + group: "{{ admin_username }}" + +- name: Install requirements in the virtual environment + ansible.builtin.command: + cmd: "{{ venv_path }}/bin/pip install -r /home/{{ admin_username }}/nostr-sync-scripts/requirements.txt" + +- name: Add grow_fedi_nhex Sync to Crontab + ansible.builtin.cron: + name: "grow_fedi_nhex" + minute: 0 + job: "cd /home/{{ admin_username }}/nostr-sync-scripts && flock -n /var/lock/nostr-sync/grow_fedi_nhex.lock {{ venv_path }}/bin/python grow_fedi_nhex.py 2>&1 | logger -t grow_fedi_nhex" + +- name: Add fedi_sync to Crontab + ansible.builtin.cron: + name: "fedi_sync" + minute: 30 + job: "cd /home/{{ admin_username }}/nostr-sync-scripts && flock -n /var/lock/nostr-sync/fedi_sync.lock {{ venv_path }}/bin/python fedi_sync.py 2>&1 | logger -t fedi_sync" + +- name: Add news_sync to Crontab + ansible.builtin.cron: + name: "news_sync" + minute: 45 + job: "cd /home/{{ admin_username }}/nostr-sync-scripts && flock -n /var/lock/nostr-sync/news_sync.lock {{ venv_path }}/bin/python news_sync.py 2>&1 | logger -t news_sync" \ No newline at end of file