blob: 365aed96151a7fb156518cff9d93c99b0970ec71 [file] [log] [blame]
Zack Williams573bafc2016-02-26 16:35:42 -07001---
2# roles/juju-setup/main/tasks.yml
3
Zack Williamsc59b6b22016-04-11 12:49:10 -07004- name: Get ubuntu image for uvtool
5 become: yes
6 command: uvt-simplestreams-libvirt sync --source http://cloud-images.ubuntu.com/daily \
7 release={{ ansible_distribution_release }} arch=amd64
8
Zack Williams0df6f2c2016-02-29 14:48:52 -07009- name: create Virtual Machines with uvt-kvm
Andy Bavierd7710062016-04-25 15:01:30 -040010 shell: uvt-kvm create {{ item.name }} release={{ ansible_distribution_release }} \
11 --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr"
Zack Williams0df6f2c2016-02-29 14:48:52 -070012 creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow
Zack Williams4bbfe1d2016-02-29 16:16:29 -070013 with_items: "{{ head_vm_list }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070014
Zack Williams3db3b962016-03-01 21:59:25 -070015- name: Have VMs autostart on reboot
Zack Williamsba883e32016-04-11 16:06:43 -070016 virt:
17 name={{ item.name }}
18 command=autostart
19 with_items: "{{ head_vm_list }}"
20
21- name: wait for VM's to come up
22 wait_for:
23 host={{ item.name }}
24 port=22
Zack Williams3db3b962016-03-01 21:59:25 -070025 with_items: "{{ head_vm_list }}"
26
Zack Williams0df6f2c2016-02-29 14:48:52 -070027- name: Create /etc/ansible/hosts file
28 become: yes
29 template:
30 src=ansible_hosts.j2
31 dest=/etc/ansible/hosts
32
Zack Williams573bafc2016-02-26 16:35:42 -070033- name: Verify that we can log into every VM
34 command: ansible services -m ping -u ubuntu
35
Zack Williams709f11b2016-03-17 14:29:51 -070036- name: Update software in all the VMs
37 command: ansible services -m apt -b -u ubuntu -a "upgrade=dist update_cache=yes cache_valid_time=3600"
38
39- name: Create VM's eth0 interface config file for DNS config via resolvconf program
Zack Williams4bd2dbc2016-03-10 12:50:02 -070040 template:
Zack Williams709f11b2016-03-17 14:29:51 -070041 src=eth0.cfg.j2
42 dest={{ ansible_user_dir }}/eth0.cfg
43
44- name: Copy eth0 interface config file to all VMs
45 command: ansible services -b -u ubuntu -m copy -a "src={{ ansible_user_dir }}/eth0.cfg dest=/etc/network/interfaces.d/eth0.cfg owner=root group=root mode=0644"
46
47- name: Restart eth0 interface on all VMs
48 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Zack Williams4bd2dbc2016-03-10 12:50:02 -070049
Zack Williamsca83c552016-04-28 09:45:38 -070050- name: Verify that we can log into every VM after restarting network interfaces
51 command: ansible services -m ping -u ubuntu
52
Zack Williams573bafc2016-02-26 16:35:42 -070053- name: Initialize Juju
54 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070055 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070056
Zack Williams823d5292016-02-29 10:31:17 -070057- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070058 template:
Zack Williams823d5292016-02-29 10:31:17 -070059 src=environments.yaml.j2
60 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070061
62- name: Bootstrap Juju
63 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070064 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070065
Zack Williamsa627ae82016-04-13 12:37:10 -070066- name: Copy over juju-config.yml for configuring Juju services
Zack Williams573bafc2016-02-26 16:35:42 -070067 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070068 template:
Zack Williams684aa4c2016-04-14 07:04:38 -070069 src={{ juju_config_name }}_juju_config.yml.j2
Zack Williamsa627ae82016-04-13 12:37:10 -070070 dest={{ juju_config_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070071
Zack Williams0df6f2c2016-02-29 14:48:52 -070072# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070073- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070074 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070075
Zack Williams823d5292016-02-29 10:31:17 -070076# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070077# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070078# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070079
Zack Williams9cdf8622016-02-26 22:42:50 -070080- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070081 command: "juju add-machine ssh:{{ item }}"
Zack Williamsba883e32016-04-11 16:06:43 -070082 with_items: "{{ head_vm_list | map(attribute='service') | list | reject('undefined') | difference( juju_machines.keys() ) }}"
Zack Williams709f11b2016-03-17 14:29:51 -070083
84# run this again, so machines will be in the juju_machines list
85- name: Obtain Juju Facts after machine creation
86 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -070087
88- name: Deploy services that are hosted in their own VM
Zack Williams9332a1c2016-04-13 15:14:47 -070089 command: "juju deploy {{ charm_versions[item] | default(item) }} --to {{ juju_machines[item]['machine_id'] }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070090 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
91
92- name: Deploy mongodb to ceilometer VM
Zack Williams9332a1c2016-04-13 15:14:47 -070093 command: "juju deploy {{ charm_versions['mongodb'] | default('mongodb') }} --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070094 when: juju_services['mongodb'] is undefined
95
96- name: Deploy services that don't have their own VM
Zack Williams9332a1c2016-04-13 15:14:47 -070097 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070098 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070099
Zack Williams4bbfe1d2016-02-29 16:16:29 -0700100# FIXME: ignoring errors when creating relationships.
101# Previous method wasn't idempotent either
Zack Williams4bbfe1d2016-02-29 16:16:29 -0700102- name: Create relations between services
103 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -0700104 register: juju_relation
105 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -0700106 with_subelements:
107 - "{{ service_relations }}"
108 - relations
109
Zack Williams709f11b2016-03-17 14:29:51 -0700110# run another time, so services will be in juju_services list
111- name: Obtain Juju Facts after service creation
112 juju_facts:
113
Zack Williams7c35fac2016-04-11 23:52:43 -0700114# 900s = 15m. Usually takes 10-12m on cloudlab for relations to come up
115# Only checks for first port in list.
Zack Williamsabd5d862016-04-26 15:26:47 -0700116- name: Wait for juju services on VM's have open ports
Zack Williams7c35fac2016-04-11 23:52:43 -0700117 wait_for:
118 host={{ item.name }}
119 port={{ item.forwarded_ports[0].int }}
120 timeout=900
121 with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}"
Zack Williams709f11b2016-03-17 14:29:51 -0700122
Zack Williamsabd5d862016-04-26 15:26:47 -0700123# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
124# 10m max wait
125- name: Wait for juju services to start
126 action: command juju status --format=summary
127 register: juju_summary
128 until: juju_summary.stdout.find("pending:") == -1
129 retries: 40
130 delay: 15
131
Zack Williams709f11b2016-03-17 14:29:51 -0700132- name: Create admin-openrc.sh credentials file
133 template:
134 src=admin-openrc.sh.j2
135 dest={{ ansible_user_dir }}/admin-openrc.sh
136
137- name: Copy nova-cloud-controller CA certificate to head
138 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
139 creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt
140
141- name: Move cert to system location
142 become: yes
143 command: mv {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
144 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
145 notify: update-ca-certificates
146
Zack Williams5a2b62d2016-04-28 07:55:18 -0700147- name: Move cert to xos vm
148 command: ansible xos-1 -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"
149
150- name: update-ca-certificates on xos vm
151 command: ansible xos-1 -b -u ubuntu -m command -a "update-ca-certificates"