blob: d1607b8cc0304f7e24391f1df590fe84bdffb04e [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:
Zack Williams44845c62017-04-21 13:57:14 -070031 src=juju_config.yml.j2
Andy Bavier744fbea2016-12-02 16:26:21 -050032 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
Andy Bavier03363372017-02-23 14:57:34 -050042- name: Check that Juju is actually ready
43 juju_facts:
Zack Williamsba5549c2017-03-25 15:04:45 -070044 until: 'juju_machines["juju.{{ site_suffix }}"] is defined and juju_machines["juju.{{ site_suffix }}"]["agent_state"] == "started"'
Andy Bavier03363372017-02-23 14:57:34 -050045 retries: 40
46 delay: 15
Zack Williams43d62b52017-01-23 07:34:45 -070047
Zack Williams823d5292016-02-29 10:31:17 -070048# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070049# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070050# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070051
Zack Williams9cdf8622016-02-26 22:42:50 -070052- name: Add machines to Juju
Andy Bavier3a197d82016-11-14 08:22:43 -080053 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 -070054 command: "juju add-machine ssh:{{ item }}"
Andy Bavier3a197d82016-11-14 08:22:43 -080055 with_items: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}"
Andy Bavier03363372017-02-23 14:57:34 -050056 register: result
57 until: result | success
58 retries: 3
59 delay: 10
Zack Williams709f11b2016-03-17 14:29:51 -070060
61# run this again, so machines will be in the juju_machines list
62- name: Obtain Juju Facts after machine creation
63 juju_facts:
Andy Bavier50f9a532016-11-17 11:05:56 -080064 register: result
65 until: result | success
66 retries: 3
67 delay: 15
Zack Williams0df6f2c2016-02-29 14:48:52 -070068
Zack Williamsba5549c2017-03-25 15:04:45 -070069- name: Deploy services that are hosted in their own LXD container
Andy Bavier3a197d82016-11-14 08:22:43 -080070 when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}"
Zack Williamsc2248c42016-04-30 13:19:42 -070071 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 -080072 with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070073
Zack Williamsba5549c2017-03-25 15:04:45 -070074- name: Deploy services that don't have their own container
Zack Williams35624562016-08-28 17:12:26 -070075 when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}"
Zack Williams9332a1c2016-04-13 15:14:47 -070076 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070077 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070078
Zack Williams4bbfe1d2016-02-29 16:16:29 -070079- name: Create relations between services
80 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070081 register: juju_relation
82 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070083 with_subelements:
84 - "{{ service_relations }}"
85 - relations
Zack Williams35624562016-08-28 17:12:26 -070086 tags:
87 - skip_ansible_lint # benign to do this more than once, hard to check for
Zack Williamsba5549c2017-03-25 15:04:45 -070088
89- name: Create admin-openrc.sh OpenStack credentials file
90 template:
91 src: admin-openrc.sh.j2
92 dest: "{{ item }}/admin-openrc.sh"
93 with_items:
94 - "{{ ansible_user_dir }}"
95 - "{{ cord_profile_dir }}"
96