From 48d83080498752a8c19e71e869eb93e5f89850ba Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 9 Dec 2019 21:53:14 +0100 Subject: [PATCH] Moved ansible config into this repo, manage passwords with ansible --- .gitignore | 4 +- ansible.cfg | 5 +++ cron-sample.sh | 11 ----- requirements.txt => files/requirements.txt | 0 tootbot.py => files/tootbot.py | 0 inventory.example | 5 +++ templates/run-bot.sh | 34 +++++++++++++++ tootbot.yml | 51 ++++++++++++++++++++++ 8 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 ansible.cfg delete mode 100644 cron-sample.sh rename requirements.txt => files/requirements.txt (100%) rename tootbot.py => files/tootbot.py (100%) create mode 100755 inventory.example create mode 100755 templates/run-bot.sh create mode 100644 tootbot.yml diff --git a/.gitignore b/.gitignore index 3c983b1..e845c18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -*.secret -cron.sh - +inventory diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..960a7c4 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +inventory=inventory + +[ssh_connection] +pipelining = True diff --git a/cron-sample.sh b/cron-sample.sh deleted file mode 100644 index a5f7d26..0000000 --- a/cron-sample.sh +++ /dev/null @@ -1,11 +0,0 @@ -# activate virtualenv if necessary -# source /home/cquest/.virtualenvs/tootbot/bin/activate - -# parameters: -# 1- twitter account to clone -# 2- mastodon login -# 3- mastodon password -# 4- instance domain (https:// is automatically added) - -python tootbot.py geonym_fr geonym@amicale.net **password** test.amicale.net -python tootbot.py cq94 cquest@amicale.net **password** test.amicale.net diff --git a/requirements.txt b/files/requirements.txt similarity index 100% rename from requirements.txt rename to files/requirements.txt diff --git a/tootbot.py b/files/tootbot.py similarity index 100% rename from tootbot.py rename to files/tootbot.py diff --git a/inventory.example b/inventory.example new file mode 100755 index 0000000..a8bb48e --- /dev/null +++ b/inventory.example @@ -0,0 +1,5 @@ +[tootbot] +user@host newsbots_password=my_password + +[all:vars] +ansible_connection=ssh diff --git a/templates/run-bot.sh b/templates/run-bot.sh new file mode 100755 index 0000000..aa18c82 --- /dev/null +++ b/templates/run-bot.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -e + +# parameters: +# 1- twitter account to clone +# 2- mastodon login +# 3- mastodon password +# 4- instance domain (https:// is automatically added) + +PATH="/app/tootbot" + +cd "$PATH/telesur_en" +../source/tootbot.py telesurenglish me+telesur_en@nutomic.com {{ newsbots_password }} newsbots.eu &>> bot.log & +/bin/sleep 60 + +cd "$PATH/telesur_es" +../source/tootbot.py teleSURtv me+telesur_es@nutomic.com {{ newsbots_password }} newsbots.eu &>> bot.log & +/bin/sleep 60 + +cd "$PATH/itsgoingdown" +../source/tootbot.py IGD_News me+itsgoingdown@nutomic.com {{ newsbots_password }} newsbots.eu &>> bot.log & +/bin/sleep 60 + +cd "$PATH/postillon" +../source/tootbot.py Der_Postillon me+postillon@nutomic.com {{ newsbots_password }} newsbots.eu &>> bot.log & +/bin/sleep 60 + +cd "$PATH/telepolis" +../source/tootbot.py telepolis_news me+telepolis@nutomic.com {{ newsbots_password }} newsbots.eu &>> bot.log & +/bin/sleep 60 + +cd "$PATH/granma" +../source/tootbot.py Granma_English me+granma@nutomic.com {{ newsbots_password }} newsbots.eu &>> bot.log & +/bin/sleep 60 diff --git a/tootbot.yml b/tootbot.yml new file mode 100644 index 0000000..243bdac --- /dev/null +++ b/tootbot.yml @@ -0,0 +1,51 @@ +--- +- hosts: all + become: yes + + tasks: + - name: add tootbot user + user: + name: tootbot + create_home: yes + system: yes + + - name: create tootbot folder + file: + path: /tootbot/ + owner: tootbot + group: tootbot + mode: '0755' + state: directory + + - name: add all template files + template: src=templates/run-bot.sh dest=/tootbot/run-bot.sh + + - name: install dependencies + apt: + pkg: ['python3', 'python3-pip', 'python3-setuptools'] + + - name: clone/update git repo + git: + repo: 'https://github.com/Nutomic/tootbot.git' + dest: /tootbot/source/ + + - name: install python requirements + raw: cd /tootbot/source/ && sudo -H -u tootbot pip3 install -r requirements.txt + args: + executable: /bin/bash + + - name: chown tootbot folder + file: + path: /tootbot/ + owner: tootbot + group: tootbot + state: directory + recurse: yes + + - name: create tootbot crontab + cron: + name: "tootbot" + minute: "*/10" + user: tootbot + job: "/tootbot/run-bot.sh >> /tootbot/bot.log 2>&1" + disabled: no