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 | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 34 | # For setwise operations on desired vs Juju state: |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 35 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 36 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 37 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 38 | - name: Add machines to Juju |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 39 | 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] | 40 | command: "juju add-machine ssh:{{ item }}" |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 41 | with_items: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 42 | |
| 43 | # run this again, so machines will be in the juju_machines list |
| 44 | - name: Obtain Juju Facts after machine creation |
| 45 | juju_facts: |
Andy Bavier | 50f9a53 | 2016-11-17 11:05:56 -0800 | [diff] [blame] | 46 | register: result |
| 47 | until: result | success |
| 48 | retries: 3 |
| 49 | delay: 15 |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 50 | |
| 51 | - name: Deploy services that are hosted in their own VM |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 52 | when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}" |
Zack Williams | c2248c4 | 2016-04-30 13:19:42 -0700 | [diff] [blame] | 53 | 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] | 54 | with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 55 | |
| 56 | - name: Deploy services that don't have their own VM |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 57 | when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}" |
Zack Williams | 9332a1c | 2016-04-13 15:14:47 -0700 | [diff] [blame] | 58 | command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 59 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 60 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 61 | - name: Create relations between services |
| 62 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 63 | register: juju_relation |
| 64 | 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] | 65 | with_subelements: |
| 66 | - "{{ service_relations }}" |
| 67 | - relations |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 68 | tags: |
| 69 | - skip_ansible_lint # benign to do this more than once, hard to check for |