Example #1
0
def importHost(host):
    sshConfigPath = str(Path.home()) + "/.ssh/config"
    config = ConfigParser(sshConfigPath)
    config.load()
    hostConfig = config.search_host(host)
    if (hostConfig == []):
        raise Exception("Host does not exists in %s" % sshConfigPath)
    return hostConfig
def parse_ssh_config(filename=TMP_SSH_CONF_FILE_NAME, verbose=False):
    """
    Parse the ssh config and return it as list of hosts (dict)
    :param verbose:
    :param filename:
    :return: the ssh conf parsed

    """
    parser = ConfigParser(ssh_config_file=filename)
    parser.load()
    return parser.config_data
Example #3
0
 def __init__(self, module):
     self.module = module
     self.params = module.params
     self.user = self.params.get('user')
     self.group = self.params.get('group') or self.user
     self.host = self.params.get('host')
     self.config_file = self.params.get('ssh_config_file')
     self.identity_file = self.params['identity_file']
     self.check_ssh_config_path()
     try:
         self.config = ConfigParser(self.config_file)
     except FileNotFoundError:
         self.module.fail_json(msg="Failed to find %s" % self.config_file)
     self.config.load()