blob: a1883dd940d89137ad4539ca79e364967a2e257a [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
13- name: Bootstrap Juju
14 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070015 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070016
Zack Williamsa627ae82016-04-13 12:37:10 -070017- name: Copy over juju-config.yml for configuring Juju services
Zack Williams573bafc2016-02-26 16:35:42 -070018 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070019 template:
Zack Williams684aa4c2016-04-14 07:04:38 -070020 src={{ juju_config_name }}_juju_config.yml.j2
Zack Williamsa627ae82016-04-13 12:37:10 -070021 dest={{ juju_config_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070022
Zack Williams0df6f2c2016-02-29 14:48:52 -070023# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070024- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070025 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080026 register: result
27 until: result | success
28 retries: 3
29 delay: 15
Zack Williams573bafc2016-02-26 16:35:42 -070030
Zack Williams3dfe6af2016-04-30 11:37:09 -070031- name: Pause to let Juju settle before adding machines
32 pause:
33 prompt="Waiting for Juju..."
34 seconds=20
35
Zack Williams823d5292016-02-29 10:31:17 -070036# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070037# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070038# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070039
Zack Williams9cdf8622016-02-26 22:42:50 -070040- name: Add machines to Juju
Andy Bavier3a197d82016-11-14 08:22:43 -080041 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 -070042 command: "juju add-machine ssh:{{ item }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080043 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 -070044
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 Bavier50f9a532016-11-17 11:05:56 -080048 register: result
49 until: result | success
50 retries: 3
51 delay: 15
Zack Williams0df6f2c2016-02-29 14:48:52 -070052
53- name: Deploy services that are hosted in their own VM
Andy Bavier3a197d82016-11-14 08:22:43 -080054 when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}"
Zack Williamsc2248c42016-04-30 13:19:42 -070055 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 -080056 with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070057
58- name: Deploy services that don't have their own VM
Zack Williams35624562016-08-28 17:12:26 -070059 when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}"
Zack Williams9332a1c2016-04-13 15:14:47 -070060 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070061 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070062
Zack Williams4bbfe1d2016-02-29 16:16:29 -070063- name: Create relations between services
64 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070065 register: juju_relation
66 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070067 with_subelements:
68 - "{{ service_relations }}"
69 - relations
Zack Williams35624562016-08-28 17:12:26 -070070 tags:
71 - skip_ansible_lint # benign to do this more than once, hard to check for