blob: 279049d48047633629fffe9e96287c6f2c5abe84 [file] [log] [blame]
Zack Williams573bafc2016-02-26 16:35:42 -07001---
2# roles/juju-setup/main/tasks.yml
3
Zack Williamsd31bbc92016-05-20 11:43:18 -07004# sshkey is registered in head-prep task
Zack Williams91c08442016-05-17 14:37:21 -07005- name: Enable root ssh login on VM's that need it
Zack Williams94f3ac62016-05-17 14:44:59 -07006 command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'"
Zack Williams91c08442016-05-17 14:37:21 -07007 with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}"
Zack Williamsbc566da2016-05-17 14:07:47 -07008
Zack Williams573bafc2016-02-26 16:35:42 -07009- name: Initialize Juju
10 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070011 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070012
Zack Williams823d5292016-02-29 10:31:17 -070013- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070014 template:
Zack Williams823d5292016-02-29 10:31:17 -070015 src=environments.yaml.j2
16 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070017
18- name: Bootstrap Juju
19 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070020 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070021
Zack Williamsa627ae82016-04-13 12:37:10 -070022- name: Copy over juju-config.yml for configuring Juju services
Zack Williams573bafc2016-02-26 16:35:42 -070023 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070024 template:
Zack Williams684aa4c2016-04-14 07:04:38 -070025 src={{ juju_config_name }}_juju_config.yml.j2
Zack Williamsa627ae82016-04-13 12:37:10 -070026 dest={{ juju_config_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070027
Zack Williams0df6f2c2016-02-29 14:48:52 -070028# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070029- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070030 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070031
Zack Williams3dfe6af2016-04-30 11:37:09 -070032- name: Pause to let Juju settle before adding machines
33 pause:
34 prompt="Waiting for Juju..."
35 seconds=20
36
Zack Williams823d5292016-02-29 10:31:17 -070037# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070038# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070039# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070040
Zack Williams9cdf8622016-02-26 22:42:50 -070041- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070042 command: "juju add-machine ssh:{{ item }}"
Zack Williams3dfe6af2016-04-30 11:37:09 -070043 with_items: "{{ head_vm_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}"
Zack Williams709f11b2016-03-17 14:29:51 -070044
45# run this again, so machines will be in the juju_machines list
46- name: Obtain Juju Facts after machine creation
47 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -070048
49- name: Deploy services that are hosted in their own VM
Zack Williamsc2248c42016-04-30 13:19:42 -070050 command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item~'.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070051 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
52
53- name: Deploy mongodb to ceilometer VM
Zack Williamsc2248c42016-04-30 13:19:42 -070054 command: "juju deploy {{ charm_versions['mongodb'] | default('mongodb') }} --to {{ juju_machines['ceilometer.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070055 when: juju_services['mongodb'] is undefined
56
57- name: Deploy services that don't have their own VM
Zack Williams9332a1c2016-04-13 15:14:47 -070058 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070059 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070060
Zack Williams4bbfe1d2016-02-29 16:16:29 -070061- name: Create relations between services
62 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070063 register: juju_relation
64 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070065 with_subelements:
66 - "{{ service_relations }}"
67 - relations
68
Zack Williams709f11b2016-03-17 14:29:51 -070069# run another time, so services will be in juju_services list
70- name: Obtain Juju Facts after service creation
71 juju_facts:
72
Zack Williams7c35fac2016-04-11 23:52:43 -070073# 900s = 15m. Usually takes 10-12m on cloudlab for relations to come up
Zack Williams3dfe6af2016-04-30 11:37:09 -070074# Only checks for first port in list
Zack Williamsabd5d862016-04-26 15:26:47 -070075- name: Wait for juju services on VM's have open ports
Zack Williams7c35fac2016-04-11 23:52:43 -070076 wait_for:
77 host={{ item.name }}
78 port={{ item.forwarded_ports[0].int }}
79 timeout=900
80 with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}"
Zack Williams709f11b2016-03-17 14:29:51 -070081
Zack Williamsabd5d862016-04-26 15:26:47 -070082# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
Zack Williams3dfe6af2016-04-30 11:37:09 -070083# 40*15s = 600s = 10m max wait
Zack Williamsabd5d862016-04-26 15:26:47 -070084- name: Wait for juju services to start
85 action: command juju status --format=summary
86 register: juju_summary
87 until: juju_summary.stdout.find("pending:") == -1
88 retries: 40
89 delay: 15
90
Zack Williams709f11b2016-03-17 14:29:51 -070091- name: Create admin-openrc.sh credentials file
92 template:
93 src=admin-openrc.sh.j2
94 dest={{ ansible_user_dir }}/admin-openrc.sh
95
96- name: Copy nova-cloud-controller CA certificate to head
97 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
98 creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt
99
Zack Williams008ce252016-04-30 14:39:15 -0700100- name: Copy cert to system location
Zack Williams709f11b2016-03-17 14:29:51 -0700101 become: yes
Zack Williams008ce252016-04-30 14:39:15 -0700102 command: cp {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
Zack Williams709f11b2016-03-17 14:29:51 -0700103 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
104 notify: update-ca-certificates
105
Zack Williamsd8b8f472016-05-16 22:40:30 -0700106- name: Move cert to all service VM's
107 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 Williams5a2b62d2016-04-28 07:55:18 -0700108
Zack Williamsd8b8f472016-05-16 22:40:30 -0700109- name: update-ca-certificates in service VM's
110 command: ansible services -b -u ubuntu -m command -a "update-ca-certificates"
Zack Williams3dfe6af2016-04-30 11:37:09 -0700111