| --- |
| # roles/juju-setup/main/tasks.yml |
| |
| - name: Initialize Juju |
| command: juju generate-config |
| creates={{ ansible_user_dir }}/.juju/environments.yaml |
| |
| - name: Create Juju config file from template |
| template: |
| src=environments.yaml.j2 |
| dest={{ ansible_user_dir }}/.juju/environments.yaml |
| |
| # Sometimes this fails yet the bootstrap eventually succeeds. |
| # Handle this case by waiting for juju_facts after this step. |
| - name: Bootstrap Juju |
| command: juju bootstrap |
| creates={{ ansible_user_dir }}/.juju/environments/manual.jenv |
| ignore_errors: yes |
| |
| # Code for this is in library/juju_facts.py |
| - name: Obtain Juju Facts for creating machines |
| juju_facts: |
| register: result |
| until: result | success |
| retries: 40 |
| delay: 15 |
| |
| - name: Copy over juju-config.yml for configuring Juju services |
| become: yes |
| template: |
| src=juju_config.yml.j2 |
| dest={{ juju_config_path }} |
| |
| # check that containers are ready to be accessed, juju add-machine may error |
| - name: Check that machines are available for Juju |
| command: ansible containers -m ping -u ubuntu |
| tags: |
| - skip_ansible_lint # connectivity check |
| retries: 3 |
| delay: 10 |
| |
| - name: Check that Juju is actually ready |
| juju_facts: |
| until: 'juju_machines["juju.{{ site_suffix }}"] is defined and juju_machines["juju.{{ site_suffix }}"]["agent_state"] == "started"' |
| retries: 40 |
| delay: 15 |
| |
| # For setwise operations on desired vs Juju state: |
| # list of active juju_machines names: juju_machines.keys() |
| # list of active juju_services names: juju_services.keys() |
| |
| - name: Add machines to Juju |
| when: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) | length }}" |
| command: "juju add-machine ssh:{{ item }}" |
| with_items: "{{ head_lxd_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}" |
| register: result |
| until: result | success |
| retries: 3 |
| delay: 10 |
| |
| # run this again, so machines will be in the juju_machines list |
| - name: Obtain Juju Facts after machine creation |
| juju_facts: |
| register: result |
| until: result | success |
| retries: 3 |
| delay: 15 |
| |
| - name: Deploy services that are hosted in their own LXD container |
| when: "{{ lxd_service_list | difference( juju_services.keys() ) | length }}" |
| command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item~'.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}" |
| with_items: "{{ lxd_service_list | difference( juju_services.keys() ) }}" |
| |
| - name: Deploy services that don't have their own container |
| when: "{{ standalone_service_list | difference( juju_services.keys() ) | length }}" |
| command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}" |
| with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}" |
| |
| - name: Create relations between services |
| command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'" |
| register: juju_relation |
| failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr" |
| with_subelements: |
| - "{{ service_relations }}" |
| - relations |
| tags: |
| - skip_ansible_lint # benign to do this more than once, hard to check for |
| |