blob: acbae5ee6f289b20c55630b11e34437a4090642e [file] [log] [blame]
Zack Williams573bafc2016-02-26 16:35:42 -07001---
2# roles/juju-setup/main/tasks.yml
3
Zack Williamsd31bbc92016-05-20 11:43:18 -07004- name: Disable host key checking in ~/.ssh/config
5 lineinfile:
6 dest={{ ansible_user_dir }}/.ssh/config
7 line="StrictHostKeyChecking no"
8 create=yes
9 mode=0600
Zack Williamsc59b6b22016-04-11 12:49:10 -070010
Zack Williamsd31bbc92016-05-20 11:43:18 -070011- name: Disable host key checking in ~/.ansible.cfg
12 copy:
13 src=ansible.cfg
14 dest={{ ansible_user_dir }}/.ansible.cfg
Zack Williams0df6f2c2016-02-29 14:48:52 -070015
Zack Williamsd31bbc92016-05-20 11:43:18 -070016# sshkey is registered in head-prep task
Zack Williams91c08442016-05-17 14:37:21 -070017- name: Enable root ssh login on VM's that need it
Zack Williams94f3ac62016-05-17 14:44:59 -070018 command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'"
Zack Williams91c08442016-05-17 14:37:21 -070019 with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}"
Zack Williamsbc566da2016-05-17 14:07:47 -070020
Zack Williams573bafc2016-02-26 16:35:42 -070021- name: Initialize Juju
22 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070023 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070024
Zack Williams823d5292016-02-29 10:31:17 -070025- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070026 template:
Zack Williams823d5292016-02-29 10:31:17 -070027 src=environments.yaml.j2
28 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070029
30- name: Bootstrap Juju
31 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070032 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070033
Zack Williamsa627ae82016-04-13 12:37:10 -070034- name: Copy over juju-config.yml for configuring Juju services
Zack Williams573bafc2016-02-26 16:35:42 -070035 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070036 template:
Zack Williams684aa4c2016-04-14 07:04:38 -070037 src={{ juju_config_name }}_juju_config.yml.j2
Zack Williamsa627ae82016-04-13 12:37:10 -070038 dest={{ juju_config_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070039
Zack Williams0df6f2c2016-02-29 14:48:52 -070040# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070041- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070042 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070043
Zack Williams3dfe6af2016-04-30 11:37:09 -070044- name: Pause to let Juju settle before adding machines
45 pause:
46 prompt="Waiting for Juju..."
47 seconds=20
48
Zack Williams823d5292016-02-29 10:31:17 -070049# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070050# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070051# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070052
Zack Williams9cdf8622016-02-26 22:42:50 -070053- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070054 command: "juju add-machine ssh:{{ item }}"
Zack Williams3dfe6af2016-04-30 11:37:09 -070055 with_items: "{{ head_vm_list | map(attribute='service') | list | reject('undefined') | map('format_string', '%s.'~site_suffix ) | difference( juju_machines.keys() ) }}"
Zack Williams709f11b2016-03-17 14:29:51 -070056
57# run this again, so machines will be in the juju_machines list
58- name: Obtain Juju Facts after machine creation
59 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -070060
61- name: Deploy services that are hosted in their own VM
Zack Williamsc2248c42016-04-30 13:19:42 -070062 command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item~'.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070063 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
64
65- name: Deploy mongodb to ceilometer VM
Zack Williamsc2248c42016-04-30 13:19:42 -070066 command: "juju deploy {{ charm_versions['mongodb'] | default('mongodb') }} --to {{ juju_machines['ceilometer.'~site_suffix]['machine_id'] }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070067 when: juju_services['mongodb'] is undefined
68
69- name: Deploy services that don't have their own VM
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
80
Zack Williams709f11b2016-03-17 14:29:51 -070081# run another time, so services will be in juju_services list
82- name: Obtain Juju Facts after service creation
83 juju_facts:
84
Zack Williams7c35fac2016-04-11 23:52:43 -070085# 900s = 15m. Usually takes 10-12m on cloudlab for relations to come up
Zack Williams3dfe6af2016-04-30 11:37:09 -070086# Only checks for first port in list
Zack Williamsabd5d862016-04-26 15:26:47 -070087- name: Wait for juju services on VM's have open ports
Zack Williams7c35fac2016-04-11 23:52:43 -070088 wait_for:
89 host={{ item.name }}
90 port={{ item.forwarded_ports[0].int }}
91 timeout=900
92 with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}"
Zack Williams709f11b2016-03-17 14:29:51 -070093
Zack Williamsabd5d862016-04-26 15:26:47 -070094# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
Zack Williams3dfe6af2016-04-30 11:37:09 -070095# 40*15s = 600s = 10m max wait
Zack Williamsabd5d862016-04-26 15:26:47 -070096- name: Wait for juju services to start
97 action: command juju status --format=summary
98 register: juju_summary
99 until: juju_summary.stdout.find("pending:") == -1
100 retries: 40
101 delay: 15
102
Zack Williams709f11b2016-03-17 14:29:51 -0700103- name: Create admin-openrc.sh credentials file
104 template:
105 src=admin-openrc.sh.j2
106 dest={{ ansible_user_dir }}/admin-openrc.sh
107
108- name: Copy nova-cloud-controller CA certificate to head
109 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
110 creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt
111
Zack Williams008ce252016-04-30 14:39:15 -0700112- name: Copy cert to system location
Zack Williams709f11b2016-03-17 14:29:51 -0700113 become: yes
Zack Williams008ce252016-04-30 14:39:15 -0700114 command: cp {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
Zack Williams709f11b2016-03-17 14:29:51 -0700115 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
116 notify: update-ca-certificates
117
Zack Williamsd8b8f472016-05-16 22:40:30 -0700118- name: Move cert to all service VM's
119 command: ansible services -b -u ubuntu -m copy -a "src={{ ansible_user_dir }}/keystone_juju_ca_cert.crt dest=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt owner=root group=root mode=0644"
Zack Williams5a2b62d2016-04-28 07:55:18 -0700120
Zack Williamsd8b8f472016-05-16 22:40:30 -0700121- name: update-ca-certificates in service VM's
122 command: ansible services -b -u ubuntu -m command -a "update-ca-certificates"
Zack Williams3dfe6af2016-04-30 11:37:09 -0700123