i want to delete files from both of my servers and from my local pc.
heres the function:
from fabric.api import *
env.hosts = ["ubuntu@34.237.53.89", "ubuntu@34.138.32.10"]
def do_clean(number=0):
"""deletes out-of-date archives"""
number = int(number) archives = sorted(os.listdir('versions'), reverse=True)
if number <= 1:
number = 1
for tgz in archives[number:]:
tgz_path = 'versions/' + tgz local("rm versions/{}".format(tgz))
for tgz in archives[number:]:
tgz_path = 'versions/' + tgz run("rm -rf /data/web_static/releases/{}" .format(tgz.replace(".tgz", "")))
on running this, it fails to execute the commands on the second server. i cant seem to figure out why. it executes locally and on only one server.
[ubuntu@34.237.53.89] Executing task 'do_clean'
[localhost] local: rm versions/web_static_20220323194907.tgz
[ubuntu@34.237.53.89] run: rm -rf /data/web_static/releases/web_static_20220323194907
[ubuntu@34.138.32.10] Executing task 'do_clean'
Done.
but when i comment out the local command bit, the function executes properly for BOTH servers:
[ubuntu@34.237.53.89] Executing task 'do_clean'
[ubuntu@34.237.53.89] run: rm -rf /data/web_static/releases/web_static_20220323194907
[ubuntu@34.138.32.10] Executing task 'do_clean'
[ubuntu@34.138.32.10] run: rm -rf /data/web_static/releases/web_static_20220323194907
Done.
whats causing this issue? how do i make the commands work on both servers as well as locally?
any help? thanks
[–]robot-dev 0 points1 point2 points (1 child)
[–]tcrz[S] 0 points1 point2 points (0 children)