from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver from libcloud.compute.deployment import ScriptDeployment from libcloud.compute.deployment import MultiStepDeployment from libcloud.compute.base import NodeAuthSSHKey
defdefault_offering(self): self.image = [i for i in self.driver.list_images() if i.name == 'Ubuntu Server 14.04 LTS 64-bit'][0] self.size = [s for s in self.driver.list_sizes() if s.name == 'light.S1'][0] self.keyname = [k for k in self.driver.list_key_pairs() if k.name == os.environ.get('IDCF_SSH_KEY_NAME')][0].name
master_bootstrap = '''#!/bin/bash curl -L http://bootstrap.saltstack.com | sh -s -- -M ''' minion_bootstrap = '''#!/bin/bash curl -L http://bootstrap.saltstack.com | sh ''' salt = Salt() salt.deploy('salt',master_bootstrap) for i inrange(1, 3): name = 'minion{0}'.format(i) salt.deploy(name,minion_bootstrap)
if __name__ == "__main__": main()
スクリプトの実行
master x 1, minion x 2の3台構成で、Saltクラスタを構築します。だいたい10分くらいかかります。
$ ./deploy.py start salt end salt, eplapsed: 195.698220968 start minion1 end minion1, eplapsed: 180.300945044 start minion2 end minion2, eplapsed: 165.452461958
salt-minionの承認
ここでは簡単にsalt-masterにSSH接続をして、minionの登録をしてみます。
$ ssh -i .ssh/my_key salt $ salt-key -L Accepted Keys: Unaccepted Keys: minion1.cs256idcfcloud.internal minion2.cs256idcfcloud.internal salt.cs256idcfcloud.internal Rejected Keys: $ salt-key -A The following keys are going to be accepted: Unaccepted Keys: minion1.cs256idcfcloud.internal minion2.cs256idcfcloud.internal salt.cs256idcfcloud.internal Proceed? [n/Y] Y Key for minion minion1.cs256idcfcloud.internal accepted. Key for minion minion2.cs256idcfcloud.internal accepted. Key for minion salt.cs256idcfcloud.internal accepted. $ salt-key -L Accepted Keys: minion1.cs256idcfcloud.internal minion2.cs256idcfcloud.internal salt.cs256idcfcloud.internal Unaccepted Keys: Rejected Keys: