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 | |
| 10 | - name: discover VM IP addresses |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 11 | shell: "uvt-kvm ip {{ item.name }}" |
| 12 | with_items: "{{ head_vm_list }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 13 | register: vm_ip |
| 14 | |
| 15 | - name: Create /etc/hosts with VM IP addresses |
| 16 | become: yes |
| 17 | template: |
| 18 | src=hosts.j2 |
| 19 | dest=/etc/hosts |
| 20 | |
| 21 | - name: Create /etc/ansible/hosts file |
| 22 | become: yes |
| 23 | template: |
| 24 | src=ansible_hosts.j2 |
| 25 | dest=/etc/ansible/hosts |
| 26 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 27 | - name: Verify that we can log into every VM |
| 28 | command: ansible services -m ping -u ubuntu |
| 29 | |
| 30 | - name: Initialize Juju |
| 31 | command: juju generate-config |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 32 | creates={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 33 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 34 | - name: Create Juju config file from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 35 | template: |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 36 | src=environments.yaml.j2 |
| 37 | dest={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 38 | |
| 39 | - name: Bootstrap Juju |
| 40 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 41 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 42 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 43 | - name: Create openstack.cfg for Juju from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 44 | become: yes |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 45 | template: |
| 46 | src=openstack.cfg.j2 |
| 47 | dest={{ openstack_cfg_path }} |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 48 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 49 | # Code for this is in library/juju_facts.py |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 50 | - name: Obtain Juju Facts |
| 51 | juju_facts: |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 52 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 53 | # For setwise operations on desired vs Juju state: |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 54 | # 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] | 55 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 56 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 57 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 58 | - name: Add machines to Juju |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 59 | command: "juju add-machine ssh:{{ item }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 60 | with_items: "{{ head_vm_list | map(attribute='name') | list | difference( juju_machines.keys() ) }}" |
| 61 | |
| 62 | - name: Deploy services that are hosted in their own VM |
| 63 | command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 64 | with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}" |
| 65 | |
| 66 | - name: Deploy mongodb to ceilometer VM |
| 67 | command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 68 | when: juju_services['mongodb'] is undefined |
| 69 | |
| 70 | - name: Deploy services that don't have their own VM |
| 71 | command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}" |
| 72 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 73 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 74 | # FIXME: ignoring errors when creating relationships. |
| 75 | # Previous method wasn't idempotent either |
| 76 | |
| 77 | - name: Create relations between services |
| 78 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
| 79 | ignore_errors: True |
| 80 | with_subelements: |
| 81 | - "{{ service_relations }}" |
| 82 | - relations |
| 83 | |
| 84 | # Need to wait for services to come up here |