Zack Williams | f6cc012 | 2018-03-30 16:00:49 -0700 | [diff] [blame] | 1 | --- |
Matteo Scandolo | 3896c47 | 2017-08-01 13:31:42 -0700 | [diff] [blame] | 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 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 16 | # roles/juju-setup/main/tasks.yml |
| 17 | |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 18 | - name: Initialize Juju |
| 19 | command: juju generate-config |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 20 | creates={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 21 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 22 | - name: Create Juju config file from template |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 23 | template: |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 24 | src=environments.yaml.j2 |
| 25 | dest={{ ansible_user_dir }}/.juju/environments.yaml |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 26 | |
Andy Bavier | 744fbea | 2016-12-02 16:26:21 -0500 | [diff] [blame] | 27 | # Sometimes this fails yet the bootstrap eventually succeeds. |
| 28 | # Handle this case by waiting for juju_facts after this step. |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 29 | - name: Bootstrap Juju |
| 30 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 31 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Andy Bavier | 744fbea | 2016-12-02 16:26:21 -0500 | [diff] [blame] | 32 | ignore_errors: yes |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 33 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 34 | # Code for this is in library/juju_facts.py |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 35 | - name: Obtain Juju Facts for creating machines |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 36 | juju_facts: |
Andy Bavier | 50f9a53 | 2016-11-17 11:05:56 -0800 | [diff] [blame] | 37 | register: result |
Zack Williams | f6cc012 | 2018-03-30 16:00:49 -0700 | [diff] [blame] | 38 | until: result is success |
Andy Bavier | 744fbea | 2016-12-02 16:26:21 -0500 | [diff] [blame] | 39 | retries: 40 |
Andy Bavier | 50f9a53 | 2016-11-17 11:05:56 -0800 | [diff] [blame] | 40 | delay: 15 |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 41 | |
Andy Bavier | 744fbea | 2016-12-02 16:26:21 -0500 | [diff] [blame] | 42 | - name: Copy over juju-config.yml for configuring Juju services |
| 43 | become: yes |
| 44 | template: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 45 | src=juju_config.yml.j2 |
Andy Bavier | 744fbea | 2016-12-02 16:26:21 -0500 | [diff] [blame] | 46 | dest={{ juju_config_path }} |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 47 | |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 48 | # 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 Bavier | 0336337 | 2017-02-23 14:57:34 -0500 | [diff] [blame] | 56 | - name: Check that Juju is actually ready |
| 57 | juju_facts: |
Zack Williams | f6c3c57 | 2018-02-02 14:16:24 -0700 | [diff] [blame] | 58 | until: 'juju_machines["juju." ~ site_suffix ] is defined and juju_machines["juju." ~ site_suffix ]["agent_state"] == "started"' |
Andy Bavier | 0336337 | 2017-02-23 14:57:34 -0500 | [diff] [blame] | 59 | retries: 40 |
| 60 | delay: 15 |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 61 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 62 | # For setwise operations on desired vs Juju state: |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 63 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 64 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 65 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 66 | - name: Add machines to Juju |
Zack Williams | f6c3c57 | 2018-02-02 14:16:24 -0700 | [diff] [blame] | 67 | when: head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) | length |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 68 | command: "juju add-machine ssh:{{ item }}" |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 69 | with_items: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}" |
Andy Bavier | 0336337 | 2017-02-23 14:57:34 -0500 | [diff] [blame] | 70 | register: result |
Zack Williams | f6cc012 | 2018-03-30 16:00:49 -0700 | [diff] [blame] | 71 | until: result is success |
Andy Bavier | 0336337 | 2017-02-23 14:57:34 -0500 | [diff] [blame] | 72 | retries: 3 |
| 73 | delay: 10 |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 74 | |
| 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 Bavier | 50f9a53 | 2016-11-17 11:05:56 -0800 | [diff] [blame] | 78 | register: result |
Zack Williams | f6cc012 | 2018-03-30 16:00:49 -0700 | [diff] [blame] | 79 | until: result is success |
Andy Bavier | 50f9a53 | 2016-11-17 11:05:56 -0800 | [diff] [blame] | 80 | retries: 3 |
| 81 | delay: 15 |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 82 | |
Zack Williams | ba5549c | 2017-03-25 15:04:45 -0700 | [diff] [blame] | 83 | - name: Deploy services that are hosted in their own LXD container |
Zack Williams | f6c3c57 | 2018-02-02 14:16:24 -0700 | [diff] [blame] | 84 | when: lxd_service_list | difference( juju_services.keys() ) | length |
Zack Williams | c2248c4 | 2016-04-30 13:19:42 -0700 | [diff] [blame] | 85 | command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item~'.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}" |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 86 | with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 87 | |
Zack Williams | ba5549c | 2017-03-25 15:04:45 -0700 | [diff] [blame] | 88 | - name: Deploy services that don't have their own container |
Zack Williams | f6c3c57 | 2018-02-02 14:16:24 -0700 | [diff] [blame] | 89 | when: standalone_service_list | difference( juju_services.keys() ) | length |
Zack Williams | 9332a1c | 2016-04-13 15:14:47 -0700 | [diff] [blame] | 90 | command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 91 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 92 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 93 | - name: Create relations between services |
| 94 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 95 | register: juju_relation |
| 96 | 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] | 97 | with_subelements: |
| 98 | - "{{ service_relations }}" |
| 99 | - relations |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 100 | tags: |
| 101 | - skip_ansible_lint # benign to do this more than once, hard to check for |
Zack Williams | ba5549c | 2017-03-25 15:04:45 -0700 | [diff] [blame] | 102 | |