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 |
Andy Bavier | d771006 | 2016-04-25 15:01:30 -0400 | [diff] [blame] | 10 | shell: uvt-kvm create {{ item.name }} release={{ ansible_distribution_release }} \ |
| 11 | --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 12 | creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 13 | with_items: "{{ head_vm_list }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 14 | |
Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 15 | - name: Have VMs autostart on reboot |
Zack Williams | 0db01a9 | 2016-05-01 06:54:24 -0700 | [diff] [blame] | 16 | become: yes |
Zack Williams | ba883e3 | 2016-04-11 16:06:43 -0700 | [diff] [blame] | 17 | virt: |
| 18 | name={{ item.name }} |
| 19 | command=autostart |
| 20 | with_items: "{{ head_vm_list }}" |
| 21 | |
| 22 | - name: wait for VM's to come up |
| 23 | wait_for: |
| 24 | host={{ item.name }} |
| 25 | port=22 |
Zack Williams | 3db3b96 | 2016-03-01 21:59:25 -0700 | [diff] [blame] | 26 | with_items: "{{ head_vm_list }}" |
| 27 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 28 | - name: Create /etc/ansible/hosts file |
| 29 | become: yes |
| 30 | template: |
| 31 | src=ansible_hosts.j2 |
| 32 | dest=/etc/ansible/hosts |
| 33 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 34 | - name: Verify that we can log into every VM |
| 35 | command: ansible services -m ping -u ubuntu |
| 36 | |
Zack Williams | 5f25f36 | 2016-05-02 09:18:41 -0700 | [diff] [blame] | 37 | - name: Have VM's use the apt-cache |
Zack Williams | 3eb5342 | 2016-05-02 09:59:23 -0700 | [diff] [blame] | 38 | command: ansible services -b -u ubuntu -m lineinfile -a "dest=/etc/apt/apt.conf.d/02apt-cacher-ng create=yes mode=0644 owner=root group=root regexp='^Acquire' line='Acquire::http { Proxy \"http://{{ apt_cacher_name }}:{{ apt_cacher_port | default('3142') }}\"; };'" |
Zack Williams | 5f25f36 | 2016-05-02 09:18:41 -0700 | [diff] [blame] | 39 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 40 | - name: Update software in all the VMs |
| 41 | command: ansible services -m apt -b -u ubuntu -a "upgrade=dist update_cache=yes cache_valid_time=3600" |
| 42 | |
| 43 | - 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] | 44 | template: |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 45 | src=eth0.cfg.j2 |
| 46 | dest={{ ansible_user_dir }}/eth0.cfg |
| 47 | |
| 48 | - name: Copy eth0 interface config file to all VMs |
| 49 | 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" |
| 50 | |
| 51 | - name: Restart eth0 interface on all VMs |
| 52 | 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] | 53 | |
Zack Williams | ca83c55 | 2016-04-28 09:45:38 -0700 | [diff] [blame] | 54 | - name: Verify that we can log into every VM after restarting network interfaces |
| 55 | command: ansible services -m ping -u ubuntu |
| 56 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 57 | - name: Initialize Juju |
| 58 | command: juju generate-config |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 59 | creates={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 60 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 61 | - name: Create Juju config file from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 62 | template: |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 63 | src=environments.yaml.j2 |
| 64 | dest={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 65 | |
| 66 | - name: Bootstrap Juju |
| 67 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 68 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 69 | |
Zack Williams | a627ae8 | 2016-04-13 12:37:10 -0700 | [diff] [blame] | 70 | - name: Copy over juju-config.yml for configuring Juju services |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 71 | become: yes |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 72 | template: |
Zack Williams | 684aa4c | 2016-04-14 07:04:38 -0700 | [diff] [blame] | 73 | src={{ juju_config_name }}_juju_config.yml.j2 |
Zack Williams | a627ae8 | 2016-04-13 12:37:10 -0700 | [diff] [blame] | 74 | dest={{ juju_config_path }} |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 75 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 76 | # Code for this is in library/juju_facts.py |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 77 | - name: Obtain Juju Facts for creating machines |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 78 | juju_facts: |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 79 | |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 80 | - name: Pause to let Juju settle before adding machines |
| 81 | pause: |
| 82 | prompt="Waiting for Juju..." |
| 83 | seconds=20 |
| 84 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 85 | # For setwise operations on desired vs Juju state: |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 86 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 87 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 88 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 89 | - name: Add machines to Juju |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 90 | command: "juju add-machine ssh:{{ item }}" |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 91 | with_items: "{{ head_vm_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 92 | |
| 93 | # run this again, so machines will be in the juju_machines list |
| 94 | - name: Obtain Juju Facts after machine creation |
| 95 | juju_facts: |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 96 | |
| 97 | - name: Deploy services that are hosted in their own VM |
Zack Williams | c2248c4 | 2016-04-30 13:19:42 -0700 | [diff] [blame] | 98 | command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item~'.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 99 | with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}" |
| 100 | |
| 101 | - name: Deploy mongodb to ceilometer VM |
Zack Williams | c2248c4 | 2016-04-30 13:19:42 -0700 | [diff] [blame] | 102 | command: "juju deploy {{ charm_versions['mongodb'] | default('mongodb') }} --to {{ juju_machines['ceilometer.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 103 | when: juju_services['mongodb'] is undefined |
| 104 | |
| 105 | - name: Deploy services that don't have their own VM |
Zack Williams | 9332a1c | 2016-04-13 15:14:47 -0700 | [diff] [blame] | 106 | command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 107 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 108 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 109 | - name: Create relations between services |
| 110 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 111 | register: juju_relation |
| 112 | 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] | 113 | with_subelements: |
| 114 | - "{{ service_relations }}" |
| 115 | - relations |
| 116 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 117 | # run another time, so services will be in juju_services list |
| 118 | - name: Obtain Juju Facts after service creation |
| 119 | juju_facts: |
| 120 | |
Zack Williams | 7c35fac | 2016-04-11 23:52:43 -0700 | [diff] [blame] | 121 | # 900s = 15m. Usually takes 10-12m on cloudlab for relations to come up |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 122 | # Only checks for first port in list |
Zack Williams | abd5d86 | 2016-04-26 15:26:47 -0700 | [diff] [blame] | 123 | - name: Wait for juju services on VM's have open ports |
Zack Williams | 7c35fac | 2016-04-11 23:52:43 -0700 | [diff] [blame] | 124 | wait_for: |
| 125 | host={{ item.name }} |
| 126 | port={{ item.forwarded_ports[0].int }} |
| 127 | timeout=900 |
| 128 | with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 129 | |
Zack Williams | abd5d86 | 2016-04-26 15:26:47 -0700 | [diff] [blame] | 130 | # secondary wait, as waiting on ports isn't enough. Probably only need one of these... |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 131 | # 40*15s = 600s = 10m max wait |
Zack Williams | abd5d86 | 2016-04-26 15:26:47 -0700 | [diff] [blame] | 132 | - name: Wait for juju services to start |
| 133 | action: command juju status --format=summary |
| 134 | register: juju_summary |
| 135 | until: juju_summary.stdout.find("pending:") == -1 |
| 136 | retries: 40 |
| 137 | delay: 15 |
| 138 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 139 | - name: Create admin-openrc.sh credentials file |
| 140 | template: |
| 141 | src=admin-openrc.sh.j2 |
| 142 | dest={{ ansible_user_dir }}/admin-openrc.sh |
| 143 | |
| 144 | - name: Copy nova-cloud-controller CA certificate to head |
| 145 | command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }} |
| 146 | creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt |
| 147 | |
Zack Williams | 008ce25 | 2016-04-30 14:39:15 -0700 | [diff] [blame] | 148 | - name: Copy cert to system location |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 149 | become: yes |
Zack Williams | 008ce25 | 2016-04-30 14:39:15 -0700 | [diff] [blame] | 150 | command: cp {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 151 | creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt |
| 152 | notify: update-ca-certificates |
| 153 | |
Zack Williams | 5a2b62d | 2016-04-28 07:55:18 -0700 | [diff] [blame] | 154 | - name: Move cert to xos vm |
Zack Williams | 008ce25 | 2016-04-30 14:39:15 -0700 | [diff] [blame] | 155 | command: ansible xos-1 -b -u ubuntu -m copy -a "src={{ ansible_user_dir }}/keystone_juju_ca_cert.crt dest=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt owner=root group=root mode=0644" |
Zack Williams | 5a2b62d | 2016-04-28 07:55:18 -0700 | [diff] [blame] | 156 | |
| 157 | - name: update-ca-certificates on xos vm |
Zack Williams | 008ce25 | 2016-04-30 14:39:15 -0700 | [diff] [blame] | 158 | command: ansible xos-1 -b -u ubuntu -m command -a "update-ca-certificates" |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 159 | |