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 | |
| 13 | - name: Bootstrap Juju |
| 14 | command: juju bootstrap |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 15 | creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 16 | |
Zack Williams | a627ae8 | 2016-04-13 12:37:10 -0700 | [diff] [blame] | 17 | - name: Copy over juju-config.yml for configuring Juju services |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 18 | become: yes |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 19 | template: |
Zack Williams | 684aa4c | 2016-04-14 07:04:38 -0700 | [diff] [blame] | 20 | src={{ juju_config_name }}_juju_config.yml.j2 |
Zack Williams | a627ae8 | 2016-04-13 12:37:10 -0700 | [diff] [blame] | 21 | dest={{ juju_config_path }} |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 22 | |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 23 | # Code for this is in library/juju_facts.py |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 24 | - name: Obtain Juju Facts for creating machines |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 25 | juju_facts: |
Andy Bavier | 50f9a53 | 2016-11-17 11:05:56 -0800 | [diff] [blame] | 26 | register: result |
| 27 | until: result | success |
| 28 | retries: 3 |
| 29 | delay: 15 |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 30 | |
Zack Williams | 3dfe6af | 2016-04-30 11:37:09 -0700 | [diff] [blame] | 31 | - name: Pause to let Juju settle before adding machines |
| 32 | pause: |
| 33 | prompt="Waiting for Juju..." |
| 34 | seconds=20 |
| 35 | |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 36 | # For setwise operations on desired vs Juju state: |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 37 | # list of active juju_machines names: juju_machines.keys() |
Zack Williams | 823d529 | 2016-02-29 10:31:17 -0700 | [diff] [blame] | 38 | # list of active juju_services names: juju_services.keys() |
Zack Williams | 573bafc | 2016-02-26 16:35:42 -0700 | [diff] [blame] | 39 | |
Zack Williams | 9cdf862 | 2016-02-26 22:42:50 -0700 | [diff] [blame] | 40 | - name: Add machines to Juju |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 41 | 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] | 42 | command: "juju add-machine ssh:{{ item }}" |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 43 | 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] | 44 | |
| 45 | # run this again, so machines will be in the juju_machines list |
| 46 | - name: Obtain Juju Facts after machine creation |
| 47 | juju_facts: |
Andy Bavier | 50f9a53 | 2016-11-17 11:05:56 -0800 | [diff] [blame] | 48 | register: result |
| 49 | until: result | success |
| 50 | retries: 3 |
| 51 | delay: 15 |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 52 | |
| 53 | - name: Deploy services that are hosted in their own VM |
Andy Bavier | 3a197d8 | 2016-11-14 08:22:43 -0800 | [diff] [blame] | 54 | when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}" |
Zack Williams | c2248c4 | 2016-04-30 13:19:42 -0700 | [diff] [blame] | 55 | 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] | 56 | with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 57 | |
| 58 | - name: Deploy services that don't have their own VM |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 59 | when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}" |
Zack Williams | 9332a1c | 2016-04-13 15:14:47 -0700 | [diff] [blame] | 60 | command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}" |
Zack Williams | 0df6f2c | 2016-02-29 14:48:52 -0700 | [diff] [blame] | 61 | with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
Zack Williams | 32e12fb | 2016-02-29 10:25:59 -0700 | [diff] [blame] | 62 | |
Zack Williams | 4bbfe1d | 2016-02-29 16:16:29 -0700 | [diff] [blame] | 63 | - name: Create relations between services |
| 64 | command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
Zack Williams | 709f11b | 2016-03-17 14:29:51 -0700 | [diff] [blame] | 65 | register: juju_relation |
| 66 | 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] | 67 | with_subelements: |
| 68 | - "{{ service_relations }}" |
| 69 | - relations |
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 70 | tags: |
| 71 | - skip_ansible_lint # benign to do this more than once, hard to check for |