Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 1 | --- |
| 2 | # roles/juju-setup/main/tasks.yml |
| 3 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 4 | - name: Initialize Juju |
| 5 | command: juju generate-config |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 6 | creates={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 7 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 8 | - name: Create Juju config file from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 9 | template: |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 10 | src=environments.yaml.j2 |
| 11 | dest={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 12 | |
| 13 | - name: Bootstrap Juju |
| 14 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 15 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 16 | |
Zack Williams | a627ae8 | 2016-04-13 12:37:10 -0700 | [diff] [blame] | 17 | - name: Copy over juju-config.yml for configuring Juju services |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 18 | become: yes |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 19 | template: |
Zack Williams | 684aa4c | 2016-04-14 07:04:38 -0700 | [diff] [blame] | 20 | src={{ juju_config_name }}_juju_config.yml.j2 |
Zack Williams | a627ae8 | 2016-04-13 12:37:10 -0700 | [diff] [blame] | 21 | dest={{ juju_config_path }} |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 22 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 23 | # Code for this is in library/juju_facts.py |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 24 | - name: Obtain Juju Facts for creating machines |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 25 | juju_facts: |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 26 | |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 27 | - name: Pause to let Juju settle before adding machines |
| 28 | pause: |
| 29 | prompt="Waiting for Juju..." |
| 30 | seconds=20 |
| 31 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 32 | # For setwise operations on desired vs Juju state: |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 33 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 34 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 35 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 36 | - name: Add machines to Juju |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 37 | command: "juju add-machine ssh:{{ item }}" |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 38 | 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] | 39 | |
| 40 | # run this again, so machines will be in the juju_machines list |
| 41 | - name: Obtain Juju Facts after machine creation |
| 42 | juju_facts: |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 43 | |
| 44 | - name: Deploy services that are hosted in their own VM |
Zack Williams | c2248c4 | 2016-04-30 13:19:42 -0700 | [diff] [blame] | 45 | 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] | 46 | with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}" |
| 47 | |
| 48 | - name: Deploy mongodb to ceilometer VM |
Zack Williams | c2248c4 | 2016-04-30 13:19:42 -0700 | [diff] [blame] | 49 | 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] | 50 | when: juju_services['mongodb'] is undefined |
| 51 | |
| 52 | - name: Deploy services that don't have their own VM |
Zack Williams | 9332a1c | 2016-04-13 15:14:47 -0700 | [diff] [blame] | 53 | command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 54 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 55 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 56 | - name: Create relations between services |
| 57 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 58 | register: juju_relation |
| 59 | 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] | 60 | with_subelements: |
| 61 | - "{{ service_relations }}" |
| 62 | - relations |
| 63 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 64 | # run another time, so services will be in juju_services list |
| 65 | - name: Obtain Juju Facts after service creation |
| 66 | juju_facts: |
| 67 | |
Zack Williams | d13af16 | 2016-06-02 14:53:00 -0700 | [diff] [blame] | 68 | # 1800s = 30m. Usually takes 10-12m on cloudlab for relations to come up |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 69 | # Only checks for first port in list |
Zack Williams | 70d512c | 2016-06-02 12:33:14 -0700 | [diff] [blame] | 70 | - name: Wait for juju services on VM's to have open ports |
Zack Williams | 7c35fac | 2016-04-11 23:52:43 -0700 | [diff] [blame] | 71 | wait_for: |
| 72 | host={{ item.name }} |
| 73 | port={{ item.forwarded_ports[0].int }} |
Zack Williams | d13af16 | 2016-06-02 14:53:00 -0700 | [diff] [blame] | 74 | timeout=1800 |
Zack Williams | 7c35fac | 2016-04-11 23:52:43 -0700 | [diff] [blame] | 75 | with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 76 | |
Zack Williams | abd5d86 | 2016-04-26 15:26:47 -0700 | [diff] [blame] | 77 | # secondary wait, as waiting on ports isn't enough. Probably only need one of these... |
Zack Williams | 70d512c | 2016-06-02 12:33:14 -0700 | [diff] [blame] | 78 | # 160*15s = 2400s = 40m max wait |
Zack Williams | abd5d86 | 2016-04-26 15:26:47 -0700 | [diff] [blame] | 79 | - name: Wait for juju services to start |
| 80 | action: command juju status --format=summary |
| 81 | register: juju_summary |
| 82 | until: juju_summary.stdout.find("pending:") == -1 |
Zack Williams | 70d512c | 2016-06-02 12:33:14 -0700 | [diff] [blame] | 83 | retries: 160 |
Zack Williams | abd5d86 | 2016-04-26 15:26:47 -0700 | [diff] [blame] | 84 | delay: 15 |
| 85 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 86 | - name: Create admin-openrc.sh credentials file |
| 87 | template: |
| 88 | src=admin-openrc.sh.j2 |
| 89 | dest={{ ansible_user_dir }}/admin-openrc.sh |
| 90 | |
Zack Williams | 17508be | 2016-05-31 21:52:35 -0700 | [diff] [blame] | 91 | |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 92 | - name: Copy nova-cloud-controller CA certificate to head |
| 93 | command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }} |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 94 | |
Zack Williams | 008ce25 | 2016-04-30 14:39:15 -0700 | [diff] [blame] | 95 | - name: Copy cert to system location |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 96 | become: yes |
Zack Williams | 008ce25 | 2016-04-30 14:39:15 -0700 | [diff] [blame] | 97 | command: cp {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 98 | |
| 99 | - name: update-ca-certificates |
| 100 | become: yes |
| 101 | command: update-ca-certificates |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 102 | |
Zack Williams | d8b8f47 | 2016-05-16 22:40:30 -0700 | [diff] [blame] | 103 | - name: Move cert to all service VM's |
| 104 | command: ansible services -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] | 105 | |
Zack Williams | d8b8f47 | 2016-05-16 22:40:30 -0700 | [diff] [blame] | 106 | - name: update-ca-certificates in service VM's |
| 107 | command: ansible services -b -u ubuntu -m command -a "update-ca-certificates" |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 108 | |