Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 1 | --- |
| 2 | # roles/juju-setup/main/tasks.yml |
| 3 | |
Zack Williams | c59b6b2 | 2016-04-11 12:49:10 -0700 | [diff] [blame] | 4 | - name: Get ubuntu image for uvtool |
| 5 | become: yes |
| 6 | command: uvt-simplestreams-libvirt sync --source http://cloud-images.ubuntu.com/daily \ |
| 7 | release={{ ansible_distribution_release }} arch=amd64 |
| 8 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 9 | - name: create Virtual Machines with uvt-kvm |
Zack Williams | ba883e3 | 2016-04-11 16:06:43 -0700 | [diff] [blame] | 10 | shell: uvt-kvm create {{ item.name }} --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 11 | creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 12 | with_items: "{{ head_vm_list }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 13 | |
Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 14 | - name: Have VMs autostart on reboot |
Zack Williams | ba883e3 | 2016-04-11 16:06:43 -0700 | [diff] [blame] | 15 | virt: |
| 16 | name={{ item.name }} |
| 17 | command=autostart |
| 18 | with_items: "{{ head_vm_list }}" |
| 19 | |
| 20 | - name: wait for VM's to come up |
| 21 | wait_for: |
| 22 | host={{ item.name }} |
| 23 | port=22 |
Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 24 | with_items: "{{ head_vm_list }}" |
| 25 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 26 | - name: Create /etc/ansible/hosts file |
| 27 | become: yes |
| 28 | template: |
| 29 | src=ansible_hosts.j2 |
| 30 | dest=/etc/ansible/hosts |
| 31 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 32 | - name: Verify that we can log into every VM |
| 33 | command: ansible services -m ping -u ubuntu |
| 34 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 35 | - name: Update software in all the VMs |
| 36 | command: ansible services -m apt -b -u ubuntu -a "upgrade=dist update_cache=yes cache_valid_time=3600" |
| 37 | |
| 38 | - name: Create VM's eth0 interface config file for DNS config via resolvconf program |
Zack Williams | 4bd2dbc | 2016-03-10 12:50:02 -0700 | [diff] [blame] | 39 | template: |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 40 | src=eth0.cfg.j2 |
| 41 | dest={{ ansible_user_dir }}/eth0.cfg |
| 42 | |
| 43 | - name: Copy eth0 interface config file to all VMs |
| 44 | command: ansible services -b -u ubuntu -m copy -a "src={{ ansible_user_dir }}/eth0.cfg dest=/etc/network/interfaces.d/eth0.cfg owner=root group=root mode=0644" |
| 45 | |
| 46 | - name: Restart eth0 interface on all VMs |
| 47 | command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0" |
Zack Williams | 4bd2dbc | 2016-03-10 12:50:02 -0700 | [diff] [blame] | 48 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 49 | - name: Initialize Juju |
| 50 | command: juju generate-config |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 51 | creates={{ ansible_user_dir }}/.juju/environments.yaml |
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 | - name: Create Juju config file from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 54 | template: |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 55 | src=environments.yaml.j2 |
| 56 | dest={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 57 | |
| 58 | - name: Bootstrap Juju |
| 59 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 60 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 61 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 62 | - name: Create openstack.cfg for Juju from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 63 | become: yes |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 64 | template: |
| 65 | src=openstack.cfg.j2 |
| 66 | dest={{ openstack_cfg_path }} |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 67 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 68 | # Code for this is in library/juju_facts.py |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 69 | - name: Obtain Juju Facts for creating machines |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 70 | juju_facts: |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 71 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 72 | # For setwise operations on desired vs Juju state: |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 73 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 74 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 75 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 76 | - name: Add machines to Juju |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 77 | command: "juju add-machine ssh:{{ item }}" |
Zack Williams | ba883e3 | 2016-04-11 16:06:43 -0700 | [diff] [blame] | 78 | with_items: "{{ head_vm_list | map(attribute='service') | list | reject('undefined') | difference( juju_machines.keys() ) }}" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 79 | |
| 80 | # run this again, so machines will be in the juju_machines list |
| 81 | - name: Obtain Juju Facts after machine creation |
| 82 | juju_facts: |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 83 | |
| 84 | - name: Deploy services that are hosted in their own VM |
| 85 | command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 86 | with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}" |
| 87 | |
| 88 | - name: Deploy mongodb to ceilometer VM |
| 89 | command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}" |
| 90 | when: juju_services['mongodb'] is undefined |
| 91 | |
| 92 | - name: Deploy services that don't have their own VM |
| 93 | command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}" |
| 94 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 95 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 96 | # FIXME: ignoring errors when creating relationships. |
| 97 | # Previous method wasn't idempotent either |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 98 | - name: Create relations between services |
| 99 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 100 | register: juju_relation |
| 101 | failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr" |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 102 | with_subelements: |
| 103 | - "{{ service_relations }}" |
| 104 | - relations |
| 105 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 106 | # run another time, so services will be in juju_services list |
| 107 | - name: Obtain Juju Facts after service creation |
| 108 | juju_facts: |
| 109 | |
Zack Williams | 7c35fac | 2016-04-11 23:52:43 -0700 | [diff] [blame] | 110 | # 900s = 15m. Usually takes 10-12m on cloudlab for relations to come up |
| 111 | # Only checks for first port in list. |
| 112 | - name: Wait for juju services on VM's to come up |
| 113 | wait_for: |
| 114 | host={{ item.name }} |
| 115 | port={{ item.forwarded_ports[0].int }} |
| 116 | timeout=900 |
| 117 | with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 118 | |
| 119 | - name: Create admin-openrc.sh credentials file |
| 120 | template: |
| 121 | src=admin-openrc.sh.j2 |
| 122 | dest={{ ansible_user_dir }}/admin-openrc.sh |
| 123 | |
| 124 | - name: Copy nova-cloud-controller CA certificate to head |
| 125 | command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }} |
| 126 | creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt |
| 127 | |
| 128 | - name: Move cert to system location |
| 129 | become: yes |
| 130 | command: mv {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates |
| 131 | creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt |
| 132 | notify: update-ca-certificates |
| 133 | |