Commit eeeaa49a authored by Ioannis Tsafaras's avatar Ioannis Tsafaras
Browse files

Added custom exception messages, when public/private key files are not found

parent dd44385d
......@@ -9,9 +9,14 @@ class Manager:
def __init__(self, host, group, private_key_path=None):
if private_key_path is None:
private_key_path = os.path.expanduser('~/.ssh/id_rsa')
ansible.constants.DEFAULT_TIMEOUT = 30
if not os.path.exists(private_key_path):
message = "The private key file was not found in the default location, " \
"or the location specified (if any). Please re-run, specifying a " \
"valid private key file."
raise IOError(message)
ansible.constants.DEFAULT_PRIVATE_KEY_FILE = private_key_path
ansible.constants.HOST_KEY_CHECKING = False
ansible.constants.DEFAULT_TIMEOUT = 30
self.ansible_inventory = ansible.inventory.Inventory(host_list=[host])
all_group = self.ansible_inventory.get_group('all')
......
......@@ -40,6 +40,11 @@ class VM_Manager(ProvisionerBase):
if public_key_path is None:
public_key_path = os.path.expanduser('~/.ssh/id_rsa.pub')
if not os.path.exists(public_key_path):
message = "The public key file was not found in the default location, " \
"or the location specified (if any). Please re-run, specifying a " \
"valid public key file."
raise IOError(message)
with open(public_key_path, 'r') as public_key_file:
public_key = public_key_file.read()
authorized = {'contents': b64encode(public_key),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment