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