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