Molecule 7/7: ansible_remote_tmp fix
Test & Deploy Hugo Docker CMS / test-and-deploy (push) Has been cancelled
Test & Deploy Hugo Docker CMS / test-and-deploy (push) Has been cancelled
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
import log
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
def copy_files_scp(scr: str = "/home/jonnybravo/Dokumente/",
|
||||
dest: str = 'ras-dan-01:/home/jonnybravo/.docker/hugo/content/',
|
||||
container: str = "hugo"):
|
||||
dest_host = dest.split(":")[0]
|
||||
list_all_files_md = [os.path.join(scr, a) for a in os.listdir(scr) if a.endswith(".md")]
|
||||
for file in list_all_files_md:
|
||||
cmd = ["scp", "-o", "StrictHostKeyChecking=no", file, dest ]
|
||||
#print(cmd)
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
log.log(f"SCP FEHLER: {result.stderr.strip() or result.stdout.strip()}", status="ERROR")
|
||||
return False
|
||||
else:
|
||||
log.log(f"Datei {file} wurde kopiert !", status="SUCCESS")
|
||||
if container == "":
|
||||
log.log("Es wird kein Container neugestartet", status="INFO")
|
||||
else:
|
||||
log.log(f"Der {container} wird auf {dest_host} via SSH neugestartet !", status="INFO")
|
||||
docker_cmd = ["ssh", "-o", "StrictHostKeyChecking=no", dest_host,
|
||||
"docker", "compose", "-f", ".docker/hugo/docker-compose.yml", "restart", container]
|
||||
result_docker = subprocess.run(docker_cmd, capture_output=True, text=True)
|
||||
if result_docker.returncode != 0:
|
||||
log.log(f"Der {container} konnte nicht gestartet werden: {result_docker.stderr.strip() or result_docker.stdout.strip()}", status="ERROR")
|
||||
return False
|
||||
else:
|
||||
log.log(f"Der {container} konnte neu gestartet werden !", status="SUCCESS")
|
||||
|
||||
# Warten bis Hugo antwortet (max 15s)
|
||||
deadline = time.time() + 15
|
||||
while time.time() < deadline:
|
||||
check = subprocess.run(
|
||||
["ssh", "-o", "StrictHostKeyChecking=no", dest_host,
|
||||
"curl", "-sk", "--max-time", "2", "-o", "/dev/null", "-w", "%{http_code}",
|
||||
"https://localhost:5443/"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
if check.stdout.strip() == "200":
|
||||
log.log("Hugo ist bereit und antwortet mit 200", status="SUCCESS")
|
||||
break
|
||||
time.sleep(1)
|
||||
else:
|
||||
log.log("Warnung: Hugo antwortet nicht innerhalb von 15s", status="WARN")
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
copy_files_scp()
|
||||
|
||||
Reference in New Issue
Block a user