blob: e4815776e730e2b8cb51ed4681dd3d28df33e33c [file] [log] [blame]
Matteo Scandolo3896c472017-08-01 13:31:42 -07001
2# 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
16
Zack Williams573bafc2016-02-26 16:35:42 -070017---
18# roles/juju-setup/main/tasks.yml
19
Zack Williams573bafc2016-02-26 16:35:42 -070020- name: Initialize Juju
21 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070022 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070023
Zack Williams823d5292016-02-29 10:31:17 -070024- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070025 template:
Zack Williams823d5292016-02-29 10:31:17 -070026 src=environments.yaml.j2
27 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070028
Andy Bavier744fbea2016-12-02 16:26:21 -050029# Sometimes this fails yet the bootstrap eventually succeeds.
30# Handle this case by waiting for juju_facts after this step.
Zack Williams573bafc2016-02-26 16:35:42 -070031- name: Bootstrap Juju
32 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070033 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Andy Bavier744fbea2016-12-02 16:26:21 -050034 ignore_errors: yes
Zack Williams573bafc2016-02-26 16:35:42 -070035
Zack Williams0df6f2c2016-02-29 14:48:52 -070036# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070037- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070038 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080039 register: result
40 until: result | success
Andy Bavier744fbea2016-12-02 16:26:21 -050041 retries: 40
Andy Bavier50f9a532016-11-17 11:05:56 -080042 delay: 15
Zack Williams573bafc2016-02-26 16:35:42 -070043
Andy Bavier744fbea2016-12-02 16:26:21 -050044- name: Copy over juju-config.yml for configuring Juju services
45 become: yes
46 template:
Zack Williams44845c62017-04-21 13:57:14 -070047 src=juju_config.yml.j2
Andy Bavier744fbea2016-12-02 16:26:21 -050048 dest={{ juju_config_path }}
Zack Williams3dfe6af2016-04-30 11:37:09 -070049
Zack Williams43d62b52017-01-23 07:34:45 -070050# check that containers are ready to be accessed, juju add-machine may error
51- name: Check that machines are available for Juju
52 command: ansible containers -m ping -u ubuntu
53 tags:
54 - skip_ansible_lint # connectivity check
55 retries: 3
56 delay: 10
57
Andy Bavier03363372017-02-23 14:57:34 -050058- name: Check that Juju is actually ready
59 juju_facts:
Zack Williamsf6c3c572018-02-02 14:16:24 -070060 until: 'juju_machines["juju." ~ site_suffix ] is defined and juju_machines["juju." ~ site_suffix ]["agent_state"] == "started"'
Andy Bavier03363372017-02-23 14:57:34 -050061 retries: 40
62 delay: 15
Zack Williams43d62b52017-01-23 07:34:45 -070063
Zack Williams823d5292016-02-29 10:31:17 -070064# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070065# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070066# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070067
Zack Williams9cdf8622016-02-26 22:42:50 -070068- name: Add machines to Juju
Zack Williamsf6c3c572018-02-02 14:16:24 -070069 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 -070070 command: "juju add-machine ssh:{{ item }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080071 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 -050072 register: result
73 until: result | success
74 retries: 3
75 delay: 10
Zack Williams709f11b2016-03-17 14:29:51 -070076
77# run this again, so machines will be in the juju_machines list
78- name: Obtain Juju Facts after machine creation
79 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080080 register: result
81 until: result | success
82 retries: 3
83 delay: 15
Zack Williams0df6f2c2016-02-29 14:48:52 -070084
Zack Williamsba5549c2017-03-25 15:04:45 -070085- name: Deploy services that are hosted in their own LXD container
Zack Williamsf6c3c572018-02-02 14:16:24 -070086 when: lxd_service_list | difference( juju_services.keys() ) | length
Zack Williamsc2248c42016-04-30 13:19:42 -070087 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 -080088 with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070089
Zack Williamsba5549c2017-03-25 15:04:45 -070090- name: Deploy services that don't have their own container
Zack Williamsf6c3c572018-02-02 14:16:24 -070091 when: standalone_service_list | difference( juju_services.keys() ) | length
Zack Williams9332a1c2016-04-13 15:14:47 -070092 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070093 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070094
Zack Williams4bbfe1d2016-02-29 16:16:29 -070095- name: Create relations between services
96 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070097 register: juju_relation
98 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070099 with_subelements:
100 - "{{ service_relations }}"
101 - relations
Zack Williams35624562016-08-28 17:12:26 -0700102 tags:
103 - skip_ansible_lint # benign to do this more than once, hard to check for
Zack Williamsba5549c2017-03-25 15:04:45 -0700104