官网 https://suitable.readthedocs.io/en/latest/
安装方法
pip install suitable
举例 在主机'web.seantis.dev', 'db.seantis.dev',上创建denis用户,当然也可以直接写IP啦
from suitable import Api
hosts = Api(['web.seantis.dev', 'db.seantis.dev'])
hosts.user(name='denis')
Create the user ‘postgres’ on ‘db.seantis.dev’:
dbhost = Api('db.seantis.dev')
dbhost.user(name='postgres')
在 backup.seantis.dev上显示挂载的信息
backuphost = Api('backup.seantis.dev')
backuphost.setup(filter='ansible_mounts')
使用用户和密码连接机器
from getpass import getpass
username = 'admin'
password = getpass()
api = Api(
'web.seantis.dev',
remote_user=username,
remote_pass=password
)
print api.command('whoami').stdout() # prints 'admin'
在'a.example.org', 'b.example.org'上执行命令whoami,然后循环打印出结果
servers = ['a.example.org', 'b.example.org']
api = Api(servers)
result = api.command('whoami')
for server in servers:
print result.stdout(server)