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