From a5ffe6c7b9076b4aabc5872fb39bef21f885fc09 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 11 Oct 2026 20:13:48 +0000 Subject: [PATCH] Update porygon-management.sh --- porygon-management.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/porygon-management.sh b/porygon-management.sh index c01c755..f1dc50f 100644 --- a/porygon-management.sh +++ b/porygon-management.sh @@ -5,12 +5,15 @@ ROOT=(-e 'ansible_become=false') HOSTS_FILE="/root/templates/root.ini" PASSWORD=(-k) PLAYBOOK=/root/playbooks/master.yml +COLLECTOR_PLAYBOOK=/root/playbooks/update_collector.yml PORT=22 ANSIBLE_PORT=() SERVERS_JSON="/root/servers.json" LXC_JSON="/root/porygon_lxc_servers.json" +PORYGON_KEY=/path/2/key PORYGON_LXC_IP="1.2.3.4" PORYGON_LXC_KEY="/path/2/key" +ALL_SERVERS_INI="/root/all_servers.ini" ###########FUNCTIONS############# @@ -49,6 +52,8 @@ web_handling echo "running scraper.py" /root/scraper.py +sed -i "/^\[servers:vars\]/i ${IP} ansible_port=${PORT}" "$ALL_SERVERS_INI" + echo -e "\nall done, all successful\n\\(^0^)/" TO_ADD=$(sed 's/\$HOSTNAME/'"$HOSTNAME"'/g' /root/templates/main-page-paste.html) echo -e "place the following into /var/www/porygon/index.html\n\n$TO_ADD" @@ -167,6 +172,20 @@ exit 0 } +update_collector() { + +ansible-playbook -i "$ALL_SERVERS_INI" "$COLLECTOR_PLAYBOOK" --private-key "$PORYGON_KEY" "${APPEND[@]}" || { +echo "failed to run ansible playbook" +exit 1 +} + +echo -e "\npushed out new collector.py successfully to all servers\n +\\(^0^)/" +exit 0 +} + + + ######RUNNING INTRO########### intro @@ -183,6 +202,11 @@ while getopts "udkph" flag; do SUDO=(--become --ask-become-pass) ;; + c) + echo "pushing out the modified collector.py to all servers" + update_collector + ;; + d) echo -e "ansible debug mode chosen\n" APPEND=(-vvv) @@ -203,7 +227,8 @@ while getopts "udkph" flag; do ;; h) - echo -e "Options:\n-d - DEBUG - runs ansible with verbose (-vvv) flags\n\ + echo -e "Options:\n-c - COPY - push out the latest collector.py to all servers\n\ +-d - DEBUG - runs ansible with verbose (-vvv) flags\n\ -h - HELP - displays this help page\n-k - KEY - specifies connecting over ssh with a private key\n\ -p - PORT - specifies which port to connect over ssh with\n\ -r - REMOVE - specifies which server to remove from porygon monitoring\n\ @@ -220,4 +245,4 @@ while getopts "udkph" flag; do done ########RUNNING MAIN########## -main +main \ No newline at end of file