blob: 554add9821e2bb78b4892be8b9692600658e9831 [file] [log] [blame]
Zack Williams573bafc2016-02-26 16:35:42 -07001---
2# roles/juju-setup/main/tasks.yml
3
Zack Williams573bafc2016-02-26 16:35:42 -07004- name: Initialize Juju
5 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -07006 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -07007
Zack Williams823d5292016-02-29 10:31:17 -07008- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -07009 template:
Zack Williams823d5292016-02-29 10:31:17 -070010 src=environments.yaml.j2
11 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070012
Andy Bavier744fbea2016-12-02 16:26:21 -050013# Sometimes this fails yet the bootstrap eventually succeeds.
14# Handle this case by waiting for juju_facts after this step.
Zack Williams573bafc2016-02-26 16:35:42 -070015- name: Bootstrap Juju
16 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070017 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Andy Bavier744fbea2016-12-02 16:26:21 -050018 ignore_errors: yes
Zack Williams573bafc2016-02-26 16:35:42 -070019
Zack Williams0df6f2c2016-02-29 14:48:52 -070020# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070021- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070022 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080023 register: result
24 until: result | success
Andy Bavier744fbea2016-12-02 16:26:21 -050025 retries: 40
Andy Bavier50f9a532016-11-17 11:05:56 -080026 delay: 15
Zack Williams573bafc2016-02-26 16:35:42 -070027
Andy Bavier744fbea2016-12-02 16:26:21 -050028- 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 Williams3dfe6af2016-04-30 11:37:09 -070033
Zack Williams823d5292016-02-29 10:31:17 -070034# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070035# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070036# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070037
Zack Williams9cdf8622016-02-26 22:42:50 -070038- name: Add machines to Juju
Andy Bavier3a197d82016-11-14 08:22:43 -080039 when: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) | length }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070040 command: "juju add-machine ssh:{{ item }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080041 with_items: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}"
Zack Williams709f11b2016-03-17 14:29:51 -070042
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 Bavier50f9a532016-11-17 11:05:56 -080046 register: result
47 until: result | success
48 retries: 3
49 delay: 15
Zack Williams0df6f2c2016-02-29 14:48:52 -070050
51- name: Deploy services that are hosted in their own VM
Andy Bavier3a197d82016-11-14 08:22:43 -080052 when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}"
Zack Williamsc2248c42016-04-30 13:19:42 -070053 command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item~'.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080054 with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070055
56- name: Deploy services that don't have their own VM
Zack Williams35624562016-08-28 17:12:26 -070057 when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}"
Zack Williams9332a1c2016-04-13 15:14:47 -070058 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070059 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070060
Zack Williams4bbfe1d2016-02-29 16:16:29 -070061- name: Create relations between services
62 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070063 register: juju_relation
64 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070065 with_subelements:
66 - "{{ service_relations }}"
67 - relations
Zack Williams35624562016-08-28 17:12:26 -070068 tags:
69 - skip_ansible_lint # benign to do this more than once, hard to check for