Standardize names and lock config
This commit is contained in:
		@@ -66,7 +66,7 @@ pvc:
 | 
				
			|||||||
    path: "/var/home/joshua/pvc"
 | 
					    path: "/var/home/joshua/pvc"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Path to the deploy key (if applicable) used to clone and pull the repository
 | 
					    # Path to the deploy key (if applicable) used to clone and pull the repository
 | 
				
			||||||
    keyfile: "/var/home/joshua/id_ed25519.joshua.key"
 | 
					    key_file: "/var/home/joshua/id_ed25519.joshua.key"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Git remote URI for the repository
 | 
					    # Git remote URI for the repository
 | 
				
			||||||
    remote: "ssh://git@git.bonifacelabs.ca:2222/bonifacelabs/pvc.git"
 | 
					    remote: "ssh://git@git.bonifacelabs.ca:2222/bonifacelabs/pvc.git"
 | 
				
			||||||
@@ -77,6 +77,9 @@ pvc:
 | 
				
			|||||||
    # Clusters configuration file
 | 
					    # Clusters configuration file
 | 
				
			||||||
    clusters_file: "clusters.yml"
 | 
					    clusters_file: "clusters.yml"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Lock file to use for Git interaction
 | 
				
			||||||
 | 
					    lock_file: "/run/pvcbootstrapd.lock"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Filenames of the various group_vars components of a cluster
 | 
					    # Filenames of the various group_vars components of a cluster
 | 
				
			||||||
    # Generally with pvc-ansible this will contain 2 files: "base.yml", and "pvc.yml"; refer to the
 | 
					    # Generally with pvc-ansible this will contain 2 files: "base.yml", and "pvc.yml"; refer to the
 | 
				
			||||||
    # pvc-ansible documentation and examples for details on these files.
 | 
					    # pvc-ansible documentation and examples for details on these files.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -179,7 +179,7 @@ def read_config():
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Get the Ansible configuration
 | 
					    # Get the Ansible configuration
 | 
				
			||||||
    for key in ["path", "keyfile", "remote", "branch", "clusters_file"]:
 | 
					    for key in ["path", "key_file", "remote", "branch", "clusters_file", "lock_file"]:
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            config[f"ansible_{key}"] = o_ansible[key]
 | 
					            config[f"ansible_{key}"] = o_ansible[key]
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,7 +66,7 @@ def run_bootstrap(config, cspec, cluster, nodes):
 | 
				
			|||||||
                limit=f"{cluster.name}",
 | 
					                limit=f"{cluster.name}",
 | 
				
			||||||
                playbook=f"{config['ansible_path']}/pvc.yml",
 | 
					                playbook=f"{config['ansible_path']}/pvc.yml",
 | 
				
			||||||
                extravars={
 | 
					                extravars={
 | 
				
			||||||
                    "ansible_ssh_private_key_file": config["ansible_keyfile"],
 | 
					                    "ansible_ssh_private_key_file": config["ansible_key_file"],
 | 
				
			||||||
                    "bootstrap": "yes",
 | 
					                    "bootstrap": "yes",
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                forks=len(nodes),
 | 
					                forks=len(nodes),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,7 @@ def init_repository(config):
 | 
				
			|||||||
    Clone the Ansible git repository
 | 
					    Clone the Ansible git repository
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        git_ssh_cmd = f"ssh -i {config['ansible_keyfile']} -o StrictHostKeyChecking=no"
 | 
					        git_ssh_cmd = f"ssh -i {config['ansible_key_file']} -o StrictHostKeyChecking=no"
 | 
				
			||||||
        if not os.path.exists(config["ansible_path"]):
 | 
					        if not os.path.exists(config["ansible_path"]):
 | 
				
			||||||
            print(
 | 
					            print(
 | 
				
			||||||
                f"First run: cloning repository {config['ansible_remote']} branch {config['ansible_branch']} to {config['ansible_path']}"
 | 
					                f"First run: cloning repository {config['ansible_remote']} branch {config['ansible_branch']} to {config['ansible_path']}"
 | 
				
			||||||
@@ -61,12 +61,10 @@ def pull_repository(config):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    Pull (with rebase) the Ansible git repository
 | 
					    Pull (with rebase) the Ansible git repository
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    lockfile = "/tmp/pvcbootstrapd-git.lock"
 | 
					    with FileLock(config['ansible_lock_file']):
 | 
				
			||||||
    lock = FileLock(lockfile)
 | 
					 | 
				
			||||||
    with lock:
 | 
					 | 
				
			||||||
        logger.info(f"Updating local configuration repository {config['ansible_path']}")
 | 
					        logger.info(f"Updating local configuration repository {config['ansible_path']}")
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            git_ssh_cmd = f"ssh -i {config['ansible_keyfile']} -o StrictHostKeyChecking=no"
 | 
					            git_ssh_cmd = f"ssh -i {config['ansible_key_file']} -o StrictHostKeyChecking=no"
 | 
				
			||||||
            g = git.cmd.Git(f"{config['ansible_path']}")
 | 
					            g = git.cmd.Git(f"{config['ansible_path']}")
 | 
				
			||||||
            logger.debug("Performing git pull")
 | 
					            logger.debug("Performing git pull")
 | 
				
			||||||
            g.pull(rebase=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
 | 
					            g.pull(rebase=True, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
 | 
				
			||||||
@@ -82,9 +80,7 @@ def commit_repository(config):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    Commit uncommitted changes to the Ansible git repository
 | 
					    Commit uncommitted changes to the Ansible git repository
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    lockfile = "/tmp/pvcbootstrapd-git.lock"
 | 
					    with FileLock(config['ansible_lock_file']):
 | 
				
			||||||
    lock = FileLock(lockfile)
 | 
					 | 
				
			||||||
    with lock:
 | 
					 | 
				
			||||||
        logger.info(
 | 
					        logger.info(
 | 
				
			||||||
            f"Committing changes to local configuration repository {config['ansible_path']}"
 | 
					            f"Committing changes to local configuration repository {config['ansible_path']}"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
@@ -111,14 +107,12 @@ def push_repository(config):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    Push changes to the default remote
 | 
					    Push changes to the default remote
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    lockfile = "/tmp/pvcbootstrapd-git.lock"
 | 
					    with FileLock(config['ansible_lock_file']):
 | 
				
			||||||
    lock = FileLock(lockfile)
 | 
					 | 
				
			||||||
    with lock:
 | 
					 | 
				
			||||||
        logger.info(
 | 
					        logger.info(
 | 
				
			||||||
            f"Pushing changes from local configuration repository {config['ansible_path']}"
 | 
					            f"Pushing changes from local configuration repository {config['ansible_path']}"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            git_ssh_cmd = f"ssh -i {config['ansible_keyfile']} -o StrictHostKeyChecking=no"
 | 
					            git_ssh_cmd = f"ssh -i {config['ansible_key_file']} -o StrictHostKeyChecking=no"
 | 
				
			||||||
            g = git.Repo(f"{config['ansible_path']}")
 | 
					            g = git.Repo(f"{config['ansible_path']}")
 | 
				
			||||||
            origin = g.remote(name="origin")
 | 
					            origin = g.remote(name="origin")
 | 
				
			||||||
            origin.push(env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
 | 
					            origin.push(env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,7 @@ def run_paramiko(config, node_address):
 | 
				
			|||||||
    ssh_client.connect(
 | 
					    ssh_client.connect(
 | 
				
			||||||
        hostname=node_address,
 | 
					        hostname=node_address,
 | 
				
			||||||
        username=config["deploy_username"],
 | 
					        username=config["deploy_username"],
 | 
				
			||||||
        key_filename=config["ansible_keyfile"],
 | 
					        key_filename=config["ansible_key_file"],
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    yield ssh_client
 | 
					    yield ssh_client
 | 
				
			||||||
    ssh_client.close()
 | 
					    ssh_client.close()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,7 @@ def init_tftp(config):
 | 
				
			|||||||
        os.makedirs(config["tftp_root_path"])
 | 
					        os.makedirs(config["tftp_root_path"])
 | 
				
			||||||
        os.makedirs(config["tftp_host_path"])
 | 
					        os.makedirs(config["tftp_host_path"])
 | 
				
			||||||
        shutil.copyfile(
 | 
					        shutil.copyfile(
 | 
				
			||||||
            f"{config['ansible_keyfile']}.pub", f"{config['tftp_root_path']}/keys.txt"
 | 
					            f"{config['ansible_key_file']}.pub", f"{config['tftp_root_path']}/keys.txt"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        build_tftp_repository(config)
 | 
					        build_tftp_repository(config)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user