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 | |
Zack Williams | 4bd2dbc | 2016-03-10 12:50:02 -0700 | [diff] [blame] | 34 | - name: Have libvirt enable port forwarding to VM's |
| 35 | become: yes |
| 36 | template: |
| 37 | src={{ item }}.j2 |
| 38 | dest=/etc/libvirt/hooks/{{ item }} |
| 39 | mode=0755 owner=root |
| 40 | with_items: |
| 41 | - daemon |
| 42 | - qemu |
| 43 | notify: |
| 44 | - reload libvirt-bin |
| 45 | - run qemu hook |
| 46 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 47 | - name: Initialize Juju |
| 48 | command: juju generate-config |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 49 | creates={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 50 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 51 | - name: Create Juju config file from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 52 | template: |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 53 | src=environments.yaml.j2 |
| 54 | dest={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 55 | |
| 56 | - name: Bootstrap Juju |
| 57 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 58 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 59 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 60 | - name: Create openstack.cfg for Juju from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 61 | become: yes |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 62 | template: |
| 63 | src=openstack.cfg.j2 |
| 64 | dest={{ openstack_cfg_path }} |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 65 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 66 | # Code for this is in library/juju_facts.py |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 67 | - name: Obtain Juju Facts |
| 68 | juju_facts: |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 69 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 70 | # For setwise operations on desired vs Juju state: |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 71 | # 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] | 72 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 73 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 74 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 75 | - name: Add machines to Juju |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 76 | command: "juju add-machine ssh:{{ item }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 77 | with_items: "{{ head_vm_list | map(attribute='name') | list | difference( juju_machines.keys() ) }}" |
| 78 | |
| 79 | - name: Deploy services that are hosted in their own VM |
| 80 | command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 81 | with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}" |
| 82 | |
| 83 | - name: Deploy mongodb to ceilometer VM |
| 84 | command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 85 | when: juju_services['mongodb'] is undefined |
| 86 | |
| 87 | - name: Deploy services that don't have their own VM |
| 88 | command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}" |
| 89 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 90 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 91 | # FIXME: ignoring errors when creating relationships. |
| 92 | # Previous method wasn't idempotent either |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 93 | - name: Create relations between services |
| 94 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
| 95 | ignore_errors: True |
| 96 | with_subelements: |
| 97 | - "{{ service_relations }}" |
| 98 | - relations |
| 99 | |
Zack Williams | 4bd2dbc | 2016-03-10 12:50:02 -0700 | [diff] [blame] | 100 | # This should be able to test for the VM's coming up, but not working right now |
| 101 | #- name: Wait for juju services on VM's to come up |
| 102 | # wait_for: |
| 103 | # port={{ item.ext }} |
| 104 | # timeout=10 |
| 105 | # with_items: "{{ head_vm_list | map(attribute='forwarded_ports') | reject('undefined') | list }}" |
Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 106 | |