blob: b29cbdf3cbdedf668540c3604c00c53f7cb3bcb2 [file] [log] [blame]
Zack Williams573bafc2016-02-26 16:35:42 -07001---
2# roles/juju-setup/main/tasks.yml
3
Zack Williams573bafc2016-02-26 16:35:42 -07004- name: Initialize Juju
5 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -07006 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -07007
Zack Williams823d5292016-02-29 10:31:17 -07008- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -07009 template:
Zack Williams823d5292016-02-29 10:31:17 -070010 src=environments.yaml.j2
11 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070012
13- name: Bootstrap Juju
14 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070015 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070016
Zack Williamsa627ae82016-04-13 12:37:10 -070017- name: Copy over juju-config.yml for configuring Juju services
Zack Williams573bafc2016-02-26 16:35:42 -070018 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070019 template:
Zack Williams684aa4c2016-04-14 07:04:38 -070020 src={{ juju_config_name }}_juju_config.yml.j2
Zack Williamsa627ae82016-04-13 12:37:10 -070021 dest={{ juju_config_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070022
Zack Williams0df6f2c2016-02-29 14:48:52 -070023# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070024- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070025 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070026
Zack Williams3dfe6af2016-04-30 11:37:09 -070027- name: Pause to let Juju settle before adding machines
28 pause:
29 prompt="Waiting for Juju..."
30 seconds=20
31
Zack Williams823d5292016-02-29 10:31:17 -070032# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070033# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070034# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070035
Zack Williams9cdf8622016-02-26 22:42:50 -070036- name: Add machines to Juju
Andy Bavier3a197d82016-11-14 08:22:43 -080037 when: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) | length }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070038 command: "juju add-machine ssh:{{ item }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080039 with_items: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}"
Zack Williams709f11b2016-03-17 14:29:51 -070040
41# run this again, so machines will be in the juju_machines list
42- name: Obtain Juju Facts after machine creation
43 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -070044
45- name: Deploy services that are hosted in their own VM
Andy Bavier3a197d82016-11-14 08:22:43 -080046 when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}"
Zack Williamsc2248c42016-04-30 13:19:42 -070047 command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item~'.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080048 with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070049
50- name: Deploy services that don't have their own VM
Zack Williams35624562016-08-28 17:12:26 -070051 when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}"
Zack Williams9332a1c2016-04-13 15:14:47 -070052 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070053 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070054
Zack Williams4bbfe1d2016-02-29 16:16:29 -070055- name: Create relations between services
56 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070057 register: juju_relation
58 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070059 with_subelements:
60 - "{{ service_relations }}"
61 - relations
Zack Williams35624562016-08-28 17:12:26 -070062 tags:
63 - skip_ansible_lint # benign to do this more than once, hard to check for
Zack Williams4bbfe1d2016-02-29 16:16:29 -070064
Zack Williams709f11b2016-03-17 14:29:51 -070065# run another time, so services will be in juju_services list
66- name: Obtain Juju Facts after service creation
67 juju_facts:
68
Zack Williamsd13af162016-06-02 14:53:00 -070069# 1800s = 30m. Usually takes 10-12m on cloudlab for relations to come up
Zack Williams3dfe6af2016-04-30 11:37:09 -070070# Only checks for first port in list
Andy Bavier3a197d82016-11-14 08:22:43 -080071- name: Wait for juju services to have open ports
Zack Williams7c35fac2016-04-11 23:52:43 -070072 wait_for:
73 host={{ item.name }}
74 port={{ item.forwarded_ports[0].int }}
Zack Williamsd13af162016-06-02 14:53:00 -070075 timeout=1800
Andy Bavier3a197d82016-11-14 08:22:43 -080076 with_items: "{{ head_lxd_list | selectattr('forwarded_ports', 'defined') | list }}"
Zack Williams709f11b2016-03-17 14:29:51 -070077
Zack Williamsabd5d862016-04-26 15:26:47 -070078# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
Zack Williams70d512c2016-06-02 12:33:14 -070079# 160*15s = 2400s = 40m max wait
Zack Williamsabd5d862016-04-26 15:26:47 -070080- name: Wait for juju services to start
Zack Williams35624562016-08-28 17:12:26 -070081 command: juju status --format=summary
Zack Williamsabd5d862016-04-26 15:26:47 -070082 register: juju_summary
83 until: juju_summary.stdout.find("pending:") == -1
Zack Williams70d512c2016-06-02 12:33:14 -070084 retries: 160
Zack Williamsabd5d862016-04-26 15:26:47 -070085 delay: 15
Zack Williams35624562016-08-28 17:12:26 -070086 tags:
87 - skip_ansible_lint # checking/waiting on a system to be up
Zack Williamsabd5d862016-04-26 15:26:47 -070088
Zack Williams709f11b2016-03-17 14:29:51 -070089- name: Create admin-openrc.sh credentials file
90 template:
91 src=admin-openrc.sh.j2
92 dest={{ ansible_user_dir }}/admin-openrc.sh
93
94- name: Copy nova-cloud-controller CA certificate to head
95 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
Andy Bavierc2335122016-06-25 09:59:22 -040096 register: result
97 until: result | success
Zack Williamsb364ef52016-08-17 17:18:22 -070098 retries: 40
Zack Williams6f5a6e72016-08-10 17:45:27 -070099 delay: 15
Zack Williams35624562016-08-28 17:12:26 -0700100 tags:
101 - skip_ansible_lint # checking/waiting on file availibilty
Zack Williams709f11b2016-03-17 14:29:51 -0700102
Zack Williams008ce252016-04-30 14:39:15 -0700103- name: Copy cert to system location
Zack Williams709f11b2016-03-17 14:29:51 -0700104 become: yes
Zack Williams35624562016-08-28 17:12:26 -0700105 copy:
106 src: "{{ ansible_user_dir }}/keystone_juju_ca_cert.crt"
107 dest: "/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt"
108 remote_src: true
Andy Bavier0077cd22016-11-14 16:54:09 -0800109 notify:
110 - update-ca-certificates
111 - Move cert to all service VMs
112 - update-ca-certificates in service VMs