Merge pull request #32 from xarses/multi-vm-deployment

Fix multi-node deployment
This commit is contained in:
Łukasz Oleś 2015-04-13 14:39:49 +02:00
commit 38a1cd4aa7
7 changed files with 28 additions and 17 deletions

1
Vagrantfile vendored
View File

@ -18,6 +18,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision "shell", inline: init_script, privileged: true
config.vm.define "solar-dev", primary: true do |guest1|
guest1.vm.provision "file", source: "~/.vagrant.d/insecure_private_key", destination: "/vagrant/tmp/keys/ssh_private"
guest1.vm.network "private_network", ip: "10.0.0.2"
guest1.vm.host_name = "solar-dev"

View File

@ -1,4 +1,9 @@
- id: 6176aaa2-d97f-11e4-8dbe-080027c2ffdb
ip: 127.0.0.1
ssh_port: 22
ssh_key: .vagrant/machines/default/virtualbox/private_key
ip: 10.0.0.2
ssh_user: vagrant
ssh_private_key_path: /vagrant/tmp/keys/ssh_private
- id: cc48cf72-df88-11e4-9f5b-080027c2ffdb
ip: 10.0.0.3
ssh_user: vagrant
ssh_private_key_path: /vagrant/tmp/keys/ssh_private

View File

@ -96,7 +96,7 @@ class Cmd(object):
profile_action=args.profile_action)
def discover(self, args):
Discovery({'id': 'discovery'}).execute()
Discovery({'id': 'discovery'}).discover()

View File

@ -11,7 +11,7 @@ from jinja2 import Template
ANSIBLE_INVENTORY = """
{% for node in nodes %}
{{node['name']}} ansible_ssh_host={{node['ssh_host']}} ansible_connection={{node['connection_type']}}
{{node.name}} ansible_ssh_host={{node.ip}} ansible_connection=ssh ansible_ssh_user={{node.ssh_user}} ansible_ssh_private_key_file={{node.ssh_private_key_path}}
{% endfor %}
{% for res in resources %}
@ -173,5 +173,6 @@ class AnsibleOrchestration(base.BaseExtension):
utils.yaml_dump_to(prepared, 'tmp/main.yml')
sub = subprocess.Popen(
['ansible-playbook', '-i', 'tmp/hosts', 'tmp/main.yml'])
['ansible-playbook', '-i', 'tmp/hosts', 'tmp/main.yml'],
env=dict(os.environ, ANSIBLE_HOST_KEY_CHECKING='False'))
out, err = sub.communicate()

View File

@ -19,16 +19,18 @@ class Discovery(base.BaseExtension):
os.path.dirname(__file__), '..', '..', '..', '..',
'examples', 'nodes_list.yaml')
def execute(self):
def discover(self):
nodes_to_store = []
with io.open(self.FILE_PATH) as f:
nodes = yaml.load(f)
for node in nodes:
node['tags'] = []
exist_node = self.db.get_record(self.COLLECTION_NAME, node['id'])
if not exist_node:
node['tags'] = ['node/{0}'.format(node['id'])]
nodes_to_store.append(node)
self.db.store_list(self.COLLECTION_NAME, nodes)
return nodes
self.db.store_list(self.COLLECTION_NAME, nodes_to_store)
def nodes_resources(self):
nodes_list = self.db.get_list(self.COLLECTION_NAME)
@ -43,9 +45,9 @@ class Discovery(base.BaseExtension):
node_resource['version'] = self.VERSION
node_resource['tags'] = node['tags']
node_resource['output'] = node
node_resource['ssh_host'] = node['ip']
# TODO replace it with ssh type
node_resource['connection_type'] = 'local'
node_resource['ip'] = node['ip']
node_resource['ssh_user'] = node['ssh_user']
node_resource['ssh_private_key_path'] = node['ssh_private_key_path']
nodes_resources.append(node_resource)

View File

@ -63,7 +63,11 @@ class FileSystemDB(DirDBM):
return map(lambda k: self[k], collection_keys)
def get_record(self, collection, _id):
return self[self._make_key(collection, _id)]
key = self._make_key(collection, _id)
if key not in self:
return None
return self[key]
def _make_key(self, collection, _id):
return '{0}-{1}'.format(collection, _id)

View File

@ -2,8 +2,6 @@ id: {{id}}
type: profile
extensions:
- id: profile
version: '1.0.0'
- id: file_discovery
version: '1.0.0'
- id: ansible