blob: 9ce227927e69d5ad39485efff2f2022c75d8bec7 [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 Williams43d62b52017-01-23 07:34:45 -070034# 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
42- name: Pause to allow juju to become ready
43 pause:
44 seconds: 15
45
Zack Williams823d5292016-02-29 10:31:17 -070046# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070047# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070048# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070049
Zack Williams9cdf8622016-02-26 22:42:50 -070050- name: Add machines to Juju
Andy Bavier3a197d82016-11-14 08:22:43 -080051 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 -070052 command: "juju add-machine ssh:{{ item }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080053 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 -070054
55# run this again, so machines will be in the juju_machines list
56- name: Obtain Juju Facts after machine creation
57 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080058 register: result
59 until: result | success
60 retries: 3
61 delay: 15
Zack Williams0df6f2c2016-02-29 14:48:52 -070062
63- name: Deploy services that are hosted in their own VM
Andy Bavier3a197d82016-11-14 08:22:43 -080064 when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}"
Zack Williamsc2248c42016-04-30 13:19:42 -070065 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 -080066 with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070067
68- name: Deploy services that don't have their own VM
Zack Williams35624562016-08-28 17:12:26 -070069 when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}"
Zack Williams9332a1c2016-04-13 15:14:47 -070070 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070071 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070072
Zack Williams4bbfe1d2016-02-29 16:16:29 -070073- name: Create relations between services
74 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070075 register: juju_relation
76 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070077 with_subelements:
78 - "{{ service_relations }}"
79 - relations
Zack Williams35624562016-08-28 17:12:26 -070080 tags:
81 - skip_ansible_lint # benign to do this more than once, hard to check for