blob: 6b7c25e9ebb6f74a6560dc4f4180f713bb1015d8 [file] [log] [blame]
---
# roles/juju-setup/main/tasks.yml
- name: create Virtual Machines with uvt-kvm
shell: uvt-kvm create {{ item.name }} --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }}; \
uvt-kvm wait --insecure {{ item.name }}
creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow
with_items: "{{ head_vm_list }}"
- name: Have VMs autostart on reboot
command: virsh autostart {{ item.name }}
with_items: "{{ head_vm_list }}"
- name: Discover VM IP addresses
shell: "uvt-kvm ip {{ item.name }}"
with_items: "{{ head_vm_list }}"
register: vm_ip
- name: Create /etc/hosts with VM IP addresses
become: yes
template:
src=hosts.j2
dest=/etc/hosts
- name: Create /etc/ansible/hosts file
become: yes
template:
src=ansible_hosts.j2
dest=/etc/ansible/hosts
- name: Verify that we can log into every VM
command: ansible services -m ping -u ubuntu
- name: Initialize Juju
command: juju generate-config
creates={{ ansible_user_dir }}/.juju/environments.yaml
- name: Create Juju config file from template
template:
src=environments.yaml.j2
dest={{ ansible_user_dir }}/.juju/environments.yaml
- name: Bootstrap Juju
command: juju bootstrap
creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
- name: Create openstack.cfg for Juju from template
become: yes
template:
src=openstack.cfg.j2
dest={{ openstack_cfg_path }}
# Code for this is in library/juju_facts.py
- name: Obtain Juju Facts
juju_facts:
# For setwise operations on desired vs Juju state:
# list of VM names in head_vm_list dict: head_vm_list | map(attribute='name') | list
# list of active juju_machines names: juju_machines.keys()
# list of active juju_services names: juju_services.keys()
- name: Add machines to Juju
command: "juju add-machine ssh:{{ item }}"
with_items: "{{ head_vm_list | map(attribute='name') | list | difference( juju_machines.keys() ) }}"
- name: Deploy services that are hosted in their own VM
command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}"
with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
- name: Deploy mongodb to ceilometer VM
command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}"
when: juju_services['mongodb'] is undefined
- name: Deploy services that don't have their own VM
command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}"
with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
# FIXME: ignoring errors when creating relationships.
# Previous method wasn't idempotent either
- name: Create relations between services
command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
ignore_errors: True
with_subelements:
- "{{ service_relations }}"
- relations
# Need to wait for services to come up here
# Possibly do so by using wait_for and wating on forwarded ports after next step?
- name: Have libvirt enable port forwarding to VM's
become: yes
copy:
src={{ item }}
dest=/etc/libvirt/hooks/{{ item }}
mode=0755 owner=root
with_items:
- daemon
- qemu
notify:
- reload libvirt-bin
- run qemu hook