blob: be45acf00bb7a1b8b1cabba45f0d15e25c3bc072 [file] [log] [blame]
Zack Williamsf6cc0122018-03-30 16:00:49 -07001---
Matteo Scandolo3896c472017-08-01 13:31:42 -07002# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Zack Williams573bafc2016-02-26 16:35:42 -070016# roles/juju-setup/main/tasks.yml
17
Zack Williams573bafc2016-02-26 16:35:42 -070018- name: Initialize Juju
19 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070020 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070021
Zack Williams823d5292016-02-29 10:31:17 -070022- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070023 template:
Zack Williams823d5292016-02-29 10:31:17 -070024 src=environments.yaml.j2
25 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070026
Andy Bavier744fbea2016-12-02 16:26:21 -050027# Sometimes this fails yet the bootstrap eventually succeeds.
28# Handle this case by waiting for juju_facts after this step.
Zack Williams573bafc2016-02-26 16:35:42 -070029- name: Bootstrap Juju
30 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070031 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Andy Bavier744fbea2016-12-02 16:26:21 -050032 ignore_errors: yes
Zack Williams573bafc2016-02-26 16:35:42 -070033
Zack Williams0df6f2c2016-02-29 14:48:52 -070034# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070035- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070036 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080037 register: result
Zack Williamsf6cc0122018-03-30 16:00:49 -070038 until: result is success
Andy Bavier744fbea2016-12-02 16:26:21 -050039 retries: 40
Andy Bavier50f9a532016-11-17 11:05:56 -080040 delay: 15
Zack Williams573bafc2016-02-26 16:35:42 -070041
Andy Bavier744fbea2016-12-02 16:26:21 -050042- name: Copy over juju-config.yml for configuring Juju services
43 become: yes
44 template:
Zack Williams44845c62017-04-21 13:57:14 -070045 src=juju_config.yml.j2
Andy Bavier744fbea2016-12-02 16:26:21 -050046 dest={{ juju_config_path }}
Zack Williams3dfe6af2016-04-30 11:37:09 -070047
Zack Williams43d62b52017-01-23 07:34:45 -070048# check that containers are ready to be accessed, juju add-machine may error
49- name: Check that machines are available for Juju
50 command: ansible containers -m ping -u ubuntu
51 tags:
52 - skip_ansible_lint # connectivity check
53 retries: 3
54 delay: 10
55
Andy Bavier03363372017-02-23 14:57:34 -050056- name: Check that Juju is actually ready
57 juju_facts:
Zack Williamsf6c3c572018-02-02 14:16:24 -070058 until: 'juju_machines["juju." ~ site_suffix ] is defined and juju_machines["juju." ~ site_suffix ]["agent_state"] == "started"'
Andy Bavier03363372017-02-23 14:57:34 -050059 retries: 40
60 delay: 15
Zack Williams43d62b52017-01-23 07:34:45 -070061
Zack Williams823d5292016-02-29 10:31:17 -070062# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070063# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070064# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070065
Zack Williams9cdf8622016-02-26 22:42:50 -070066- name: Add machines to Juju
Zack Williamsf6c3c572018-02-02 14:16:24 -070067 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 -070068 command: "juju add-machine ssh:{{ item }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080069 with_items: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}"
Andy Bavier03363372017-02-23 14:57:34 -050070 register: result
Zack Williamsf6cc0122018-03-30 16:00:49 -070071 until: result is success
Andy Bavier03363372017-02-23 14:57:34 -050072 retries: 3
73 delay: 10
Zack Williams709f11b2016-03-17 14:29:51 -070074
75# run this again, so machines will be in the juju_machines list
76- name: Obtain Juju Facts after machine creation
77 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080078 register: result
Zack Williamsf6cc0122018-03-30 16:00:49 -070079 until: result is success
Andy Bavier50f9a532016-11-17 11:05:56 -080080 retries: 3
81 delay: 15
Zack Williams0df6f2c2016-02-29 14:48:52 -070082
Zack Williamsba5549c2017-03-25 15:04:45 -070083- name: Deploy services that are hosted in their own LXD container
Zack Williamsf6c3c572018-02-02 14:16:24 -070084 when: lxd_service_list | difference( juju_services.keys() ) | length
Zack Williamsc2248c42016-04-30 13:19:42 -070085 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 -080086 with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070087
Zack Williamsba5549c2017-03-25 15:04:45 -070088- name: Deploy services that don't have their own container
Zack Williamsf6c3c572018-02-02 14:16:24 -070089 when: standalone_service_list | difference( juju_services.keys() ) | length
Zack Williams9332a1c2016-04-13 15:14:47 -070090 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070091 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070092
Zack Williams4bbfe1d2016-02-29 16:16:29 -070093- name: Create relations between services
94 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070095 register: juju_relation
96 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070097 with_subelements:
98 - "{{ service_relations }}"
99 - relations
Zack Williams35624562016-08-28 17:12:26 -0700100 tags:
101 - skip_ansible_lint # benign to do this more than once, hard to check for
Zack Williamsba5549c2017-03-25 15:04:45 -0700102