diff --git a/Vagrantfile b/Vagrantfile index bac27f72..060dd7e2 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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}" diff --git a/bootstrap/playbooks/build-main.yml b/bootstrap/playbooks/build-main.yml index f71615a1..d785a743 100644 --- a/bootstrap/playbooks/build-main.yml +++ b/bootstrap/playbooks/build-main.yml @@ -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 diff --git a/bootstrap/playbooks/celery.yml b/bootstrap/playbooks/celery.yml index 5bbf7651..10944246 100644 --- a/bootstrap/playbooks/celery.yml +++ b/bootstrap/playbooks/celery.yml @@ -1,6 +1,7 @@ --- -- hosts: all +- name: Solar Celery config + hosts: all sudo: yes vars: celery_dir: /var/run/celery diff --git a/bootstrap/playbooks/custom-configs.yml b/bootstrap/playbooks/custom-configs.yml index 76636a56..05bc1827 100644 --- a/bootstrap/playbooks/custom-configs.yml +++ b/bootstrap/playbooks/custom-configs.yml @@ -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 diff --git a/bootstrap/playbooks/docker.yml b/bootstrap/playbooks/docker.yml deleted file mode 100644 index e855cc53..00000000 --- a/bootstrap/playbooks/docker.yml +++ /dev/null @@ -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 diff --git a/bootstrap/playbooks/files/ubuntu-ansible.sh b/bootstrap/playbooks/files/ubuntu-ansible.sh index 4eb6b306..11c4a206 100644 --- a/bootstrap/playbooks/files/ubuntu-ansible.sh +++ b/bootstrap/playbooks/files/ubuntu-ansible.sh @@ -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 diff --git a/bootstrap/playbooks/base.yml b/bootstrap/playbooks/tasks/base.yml similarity index 100% rename from bootstrap/playbooks/base.yml rename to bootstrap/playbooks/tasks/base.yml diff --git a/bootstrap/playbooks/cinder.yml b/bootstrap/playbooks/tasks/cinder.yml similarity index 86% rename from bootstrap/playbooks/cinder.yml rename to bootstrap/playbooks/tasks/cinder.yml index 8d95d2f3..f34b1438 100644 --- a/bootstrap/playbooks/cinder.yml +++ b/bootstrap/playbooks/tasks/cinder.yml @@ -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 diff --git a/bootstrap/playbooks/tasks/docker.yml b/bootstrap/playbooks/tasks/docker.yml new file mode 100644 index 00000000..3203e643 --- /dev/null +++ b/bootstrap/playbooks/tasks/docker.yml @@ -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 diff --git a/bootstrap/playbooks/puppet.yml b/bootstrap/playbooks/tasks/puppet.yml similarity index 100% rename from bootstrap/playbooks/puppet.yml rename to bootstrap/playbooks/tasks/puppet.yml diff --git a/example-bootstrap.py b/example-bootstrap.py new file mode 100644 index 00000000..955601b4 --- /dev/null +++ b/example-bootstrap.py @@ -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() diff --git a/example-puppet.py b/example-puppet.py index 7c555748..fc883234 100644 --- a/example-puppet.py +++ b/example-puppet.py @@ -548,7 +548,6 @@ resources_to_run = [ ] - @click.command() def deploy(): setup_resources() diff --git a/resources/solar_bootstrap/actions/run.yaml b/resources/solar_bootstrap/actions/run.yaml new file mode 100644 index 00000000..24edaf65 --- /dev/null +++ b/resources/solar_bootstrap/actions/run.yaml @@ -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 diff --git a/resources/solar_bootstrap/meta.yaml b/resources/solar_bootstrap/meta.yaml new file mode 100644 index 00000000..d89f224f --- /dev/null +++ b/resources/solar_bootstrap/meta.yaml @@ -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