merge: with remote

This commit is contained in:
ibuler
2022-11-11 15:11:10 +08:00
10 changed files with 445 additions and 322 deletions

View File

@@ -21,38 +21,40 @@ class DeployAppletHostManager:
@staticmethod
def get_run_dir():
base = os.path.join(settings.ANSIBLE_DIR, 'applet_host_deploy')
now = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
base = os.path.join(settings.ANSIBLE_DIR, "applet_host_deploy")
now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
return os.path.join(base, now)
def generate_playbook(self):
playbook_src = os.path.join(CURRENT_DIR, 'playbook.yml')
playbook_src = os.path.join(CURRENT_DIR, "playbook.yml")
base_site_url = settings.BASE_SITE_URL
bootstrap_token = settings.BOOTSTRAP_TOKEN
host_id = str(self.deployment.host.id)
if not base_site_url:
base_site_url = "localhost:8080"
base_site_url = "http://localhost:8080"
with open(playbook_src) as f:
plays = yaml.safe_load(f)
for play in plays:
play['vars'].update(self.deployment.host.deploy_options)
play['vars']['DownloadHost'] = base_site_url + '/download/'
play['vars']['CORE_HOST'] = base_site_url
play['vars']['BOOTSTRAP_TOKEN'] = bootstrap_token
play['vars']['HOST_ID'] = host_id
play['vars']['HOST_NAME'] = self.deployment.host.name
play["vars"].update(self.deployment.host.deploy_options)
play["vars"]["DownloadHost"] = base_site_url + "/download"
play["vars"]["CORE_HOST"] = base_site_url
play["vars"]["BOOTSTRAP_TOKEN"] = bootstrap_token
play["vars"]["HOST_ID"] = host_id
play["vars"]["HOST_NAME"] = self.deployment.host.name
playbook_dir = os.path.join(self.run_dir, 'playbook')
playbook_dst = os.path.join(playbook_dir, 'main.yml')
playbook_dir = os.path.join(self.run_dir, "playbook")
playbook_dst = os.path.join(playbook_dir, "main.yml")
os.makedirs(playbook_dir, exist_ok=True)
with open(playbook_dst, 'w') as f:
with open(playbook_dst, "w") as f:
yaml.safe_dump(plays, f)
return playbook_dst
def generate_inventory(self):
inventory = JMSInventory([self.deployment.host], account_policy='privileged_only')
inventory_dir = os.path.join(self.run_dir, 'inventory')
inventory_path = os.path.join(inventory_dir, 'hosts.yml')
inventory = JMSInventory(
[self.deployment.host], account_policy="privileged_only"
)
inventory_dir = os.path.join(self.run_dir, "inventory")
inventory_path = os.path.join(inventory_dir, "hosts.yml")
inventory.write_to_file(inventory_path)
return inventory_path
@@ -71,7 +73,7 @@ class DeployAppletHostManager:
self.deployment.status = cb.status
except Exception as e:
logger.error("Error: {}".format(e))
self.deployment.status = 'error'
self.deployment.status = "error"
finally:
self.deployment.date_finished = timezone.now()
with safe_db_connection():