转载rul:https://www.jianshu.com/p/012ccdff93cc
注意:
1,测试连接的时候确定账户密码正确。
2,vim eauth.conf 文件如下编写,支持client参数对 whell,runner的支持。
external_auth:
pam:
saltapi:
- .*
- '@wheel'
- '@runner'
- '@local_async'
3,测试通过后,实际python脚本本身可能出现问题,如:有的调用脚本代码为:
class SaltAPI(object): __token_id = '' def __init__(self,url,username,password): self.__url = url.rstrip('/') self.__user = 'saltapi'#username self.__password = 'redhat'#password
实际调用不能通过。应修改为:
class SaltAPI(object):
def __init__(self,url,username,password):
self.__url = url.rstrip('/')
self.__user = username
self.__password = password
self.__token_id = self.salt_login()
def token_id(self):
''' user login and get token id '''
params = {'eauth': 'pam', 'username': self.__user, 'password': self.__password}
encode = urllib.urlencode(params)
obj = urllib.unquote(encode)
content = self.postRequest(obj,prefix='/login')
try:
self.__token_id = content['return'][0]['token']
except KeyError:
raise KeyError