Bootstrap resource added

- added example-bootstrap.py
- moved ansible tasks to separate dir
This commit is contained in:
Przemyslaw Kaminski 2015-08-07 09:10:39 +02:00
parent 0c3f3208b6
commit beb6b8536f
14 changed files with 182 additions and 23 deletions

18
Vagrantfile vendored
View File

@ -23,12 +23,12 @@ SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#config.vm.box = "deb/jessie-amd64"
#config.vm.box = "rustyrobot/deb-jessie-amd64"
#config.vm.box = "ubuntu/trusty64"
config.vm.box = "solar-master.box"
config.vm.define "solar-dev", primary: true do |config|
#config.vm.box = "deb/jessie-amd64"
#config.vm.box = "rustyrobot/deb-jessie-amd64"
#config.vm.box = "ubuntu/trusty64"
config.vm.box = "solar-master.box"
config.vm.provision "shell", inline: solar_script, privileged: true
config.vm.provision "shell", inline: master_celery, privileged: true
config.vm.provision "file", source: "~/.vagrant.d/insecure_private_key", destination: "/vagrant/tmp/keys/ssh_private"
@ -46,9 +46,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
index = i + 1
ip_index = i + 3
config.vm.define "solar-dev#{index}" do |config|
config.vm.provision "shell", inline: slave_script, privileged: true
config.vm.provision "shell", inline: solar_script, privileged: true
config.vm.provision "shell", inline: slave_celery, privileged: true
config.vm.box = "ubuntu/trusty64"
#config.vm.provision "shell", inline: slave_script, privileged: true
#config.vm.provision "shell", inline: solar_script, privileged: true
#config.vm.provision "shell", inline: slave_celery, privileged: true
config.vm.network "private_network", ip: "10.0.0.#{ip_index}"
config.vm.host_name = "solar-dev#{index}"

View File

@ -1,10 +1,11 @@
---
- hosts: all
- name: Main build script
hosts: all
sudo: yes
tasks:
- include: base.yml
- include: puppet.yml
- include: docker.yml
- include: tasks/base.yml
- include: tasks/puppet.yml
- include: tasks/docker.yml
#- include: celery.yml tags=['master'] celery_dir=/var/run/celery
- include: cinder.yml
- include: tasks/cinder.yml

View File

@ -1,6 +1,7 @@
---
- hosts: all
- name: Solar Celery config
hosts: all
sudo: yes
vars:
celery_dir: /var/run/celery

View File

@ -1,6 +1,7 @@
---
- hosts: all
- name: Custom Solar configs
hosts: all
sudo: yes
tasks:
- lineinfile: line='slaveof {{ master_ip }} 6379' dest=/etc/redis/redis.conf

View File

@ -1,7 +0,0 @@
---
- shell: docker --version
ignore_errors: true
register: docker_version
- shell: curl -sSL https://get.docker.com/ | sudo sh
when: docker_version | failed

View File

@ -1,5 +1,8 @@
#!/bin/sh
# TODO: maybe this is better:
# http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-apt-ubuntu
apt-get remove -f python-pip
sudo apt-get install -y python-setuptools
sudo easy_install pip

View File

@ -7,5 +7,9 @@
ignore_errors: True
- command: sudo losetup /dev/loop0 /root/cinder.img
when: loop_created|failed
# retries: 5
# delay: 1
- lvg: vg=cinder-volumes pvs=/dev/loop0
when: loop_created|failed
# retries: 5
# delay: 1

View File

@ -0,0 +1,17 @@
---
- shell: docker --version
ignore_errors: true
register: docker_version
# This script is completely broken, it has so many sleeps...
- shell: curl -sSL https://get.docker.com/ | sudo sh
when: docker_version | failed
# Here's a raw paste of what the above script really does for Ubuntu
#- shell: apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
#- shell: mkdir -p /etc/apt/sources.list.d
#- shell: echo deb https://apt.dockerproject.org/repo ubuntu-trusty main > /etc/apt/sources.list.d/docker.list
# args:
# creates: /etc/apt/sources.list.d/docker.list
#- shell: apt-get update
#- shell: apt-get install -y -q docker-engine

108
example-bootstrap.py Normal file
View File

@ -0,0 +1,108 @@
import click
import sys
import time
from solar.core import actions
from solar.core import resource
from solar.core import signals
from solar.core import validation
from solar.core.resource import virtual_resource as vr
from solar import errors
from solar.interfaces.db import get_db
GIT_PUPPET_LIBS_URL = 'https://github.com/CGenie/puppet-libs-resource'
# TODO
# Resource for repository OR puppet apt-module in run.pp
# add-apt-repository cloud-archive:juno
# To discuss: install stuff in Docker container
# NOTE
# No copy of manifests, pull from upstream (implemented in the puppet handler)
# Official puppet manifests, not fuel-library
db = get_db()
@click.group()
def main():
pass
def setup_resources():
db.clear()
signals.Connections.clear()
node1, node2 = vr.create('nodes', 'templates/nodes.yml', {})
solar_bootstrap1 = vr.create('solar_bootstrap1', 'resources/solar_bootstrap', {'master_ip': '10.0.0.2'})[0]
solar_bootstrap2 = vr.create('solar_bootstrap2', 'resources/solar_bootstrap', {'master_ip': '10.0.0.2'})[0]
signals.connect(node1, solar_bootstrap1)
signals.connect(node2, solar_bootstrap2)
has_errors = False
for r in locals().values():
if not isinstance(r, resource.Resource):
continue
print 'Validating {}'.format(r.name)
errors = validation.validate_resource(r)
if errors:
has_errors = True
print 'ERROR: %s: %s' % (r.name, errors)
if has_errors:
sys.exit(1)
resources_to_run = [
'solar_bootstrap1',
'solar_bootstrap2',
]
@click.command()
def deploy():
setup_resources()
# run
resources = map(resource.wrap_resource, db.get_list(collection=db.COLLECTIONS.resource))
resources = {r.name: r for r in resources}
for name in resources_to_run:
try:
actions.resource_action(resources[name], 'run')
except errors.SolarError as e:
print 'WARNING: %s' % str(e)
raise
time.sleep(10)
@click.command()
def undeploy():
resources = map(resource.wrap_resource, db.get_list(collection=db.COLLECTIONS.resource))
resources = {r.name: r for r in resources}
for name in reversed(resources_to_run):
try:
actions.resource_action(resources[name], 'remove')
except errors.SolarError as e:
print 'WARNING: %s' % str(e)
db.clear()
signals.Connections.clear()
main.add_command(deploy)
main.add_command(undeploy)
if __name__ == '__main__':
main()

View File

@ -548,7 +548,6 @@ resources_to_run = [
]
@click.command()
def deploy():
setup_resources()

View File

@ -0,0 +1,12 @@
---
# TODO: this shouldn't be outside of the resource directory
- hosts: all
sudo: yes
tasks:
- script: /vagrant/bootstrap/playbooks/files/ubuntu-ansible.sh
- include: /vagrant/bootstrap/playbooks/tasks/cinder.yml
#- include: celery.yml tags=['master'] celery_dir=/var/run/celery
- include: /vagrant/bootstrap/playbooks/build-main.yml
- include: /vagrant/bootstrap/playbooks/custom-configs.yml master_ip={{ master_ip }}
- include: /vagrant/bootstrap/playbooks/celery.yml tags=slave

View File

@ -0,0 +1,18 @@
handler: ansible
id: 'solar_bootstrap'
input:
ip:
schema: str!
value:
ssh_key:
schema: str!
value:
ssh_user:
schema: str!
value:
master_ip:
schema: str!
value:
tags: []
version: 1.0.0