Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 1 | --- |
| 2 | # roles/juju-setup/main/tasks.yml |
| 3 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 4 | - name: create Virtual Machines with uvt-kvm |
| 5 | shell: uvt-kvm create {{ item.name }} --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }}; \ |
| 6 | uvt-kvm wait --insecure {{ item.name }} |
| 7 | creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 8 | with_items: "{{ head_vm_list }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 9 | |
Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 10 | - name: Have VMs autostart on reboot |
| 11 | command: virsh autostart {{ item.name }} |
| 12 | with_items: "{{ head_vm_list }}" |
| 13 | |
| 14 | - name: Discover VM IP addresses |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 15 | shell: "uvt-kvm ip {{ item.name }}" |
| 16 | with_items: "{{ head_vm_list }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 17 | register: vm_ip |
| 18 | |
| 19 | - name: Create /etc/hosts with VM IP addresses |
| 20 | become: yes |
| 21 | template: |
| 22 | src=hosts.j2 |
| 23 | dest=/etc/hosts |
| 24 | |
| 25 | - name: Create /etc/ansible/hosts file |
| 26 | become: yes |
| 27 | template: |
| 28 | src=ansible_hosts.j2 |
| 29 | dest=/etc/ansible/hosts |
| 30 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 31 | - name: Verify that we can log into every VM |
| 32 | command: ansible services -m ping -u ubuntu |
| 33 | |
| 34 | - name: Initialize Juju |
| 35 | command: juju generate-config |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 36 | creates={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 37 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 38 | - name: Create Juju config file from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 39 | template: |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 40 | src=environments.yaml.j2 |
| 41 | dest={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 42 | |
| 43 | - name: Bootstrap Juju |
| 44 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 45 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 46 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 47 | - name: Create openstack.cfg for Juju from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 48 | become: yes |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 49 | template: |
| 50 | src=openstack.cfg.j2 |
| 51 | dest={{ openstack_cfg_path }} |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 52 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 53 | # Code for this is in library/juju_facts.py |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 54 | - name: Obtain Juju Facts |
| 55 | juju_facts: |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 56 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 57 | # For setwise operations on desired vs Juju state: |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 58 | # list of VM names in head_vm_list dict: head_vm_list | map(attribute='name') | list |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 59 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 60 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 61 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 62 | - name: Add machines to Juju |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 63 | command: "juju add-machine ssh:{{ item }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 64 | with_items: "{{ head_vm_list | map(attribute='name') | list | difference( juju_machines.keys() ) }}" |
| 65 | |
| 66 | - name: Deploy services that are hosted in their own VM |
| 67 | command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 68 | with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}" |
| 69 | |
| 70 | - name: Deploy mongodb to ceilometer VM |
| 71 | command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 72 | when: juju_services['mongodb'] is undefined |
| 73 | |
| 74 | - name: Deploy services that don't have their own VM |
| 75 | command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}" |
| 76 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 77 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 78 | # FIXME: ignoring errors when creating relationships. |
| 79 | # Previous method wasn't idempotent either |
| 80 | |
| 81 | - name: Create relations between services |
| 82 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
| 83 | ignore_errors: True |
| 84 | with_subelements: |
| 85 | - "{{ service_relations }}" |
| 86 | - relations |
| 87 | |
| 88 | # Need to wait for services to come up here |
Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 89 | # Possibly do so by using wait_for and wating on forwarded ports after next step? |
| 90 | |
| 91 | - name: Have libvirt enable port forwarding to VM's |
| 92 | become: yes |
| 93 | copy: |
| 94 | src={{ item }} |
| 95 | dest=/etc/libvirt/hooks/{{ item }} |
| 96 | mode=0755 owner=root |
| 97 | with_items: |
| 98 | - daemon |
| 99 | - qemu |
| 100 | notify: |
| 101 | - reload libvirt-bin |
| 102 | - run qemu hook |
| 103 | |