blob: 00b08864b1aae98a6042acd5f0d9126975b02662 [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
Zack Williams0db01a92016-05-01 06:54:24 -070010 become: yes
Andy Bavierd7710062016-04-25 15:01:30 -040011 shell: uvt-kvm create {{ item.name }} release={{ ansible_distribution_release }} \
12 --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} --bridge="mgmtbr"
Zack Williams0df6f2c2016-02-29 14:48:52 -070013 creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow
Zack Williams4bbfe1d2016-02-29 16:16:29 -070014 with_items: "{{ head_vm_list }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070015
Zack Williams3db3b962016-03-01 21:59:25 -070016- name: Have VMs autostart on reboot
Zack Williams0db01a92016-05-01 06:54:24 -070017 become: yes
Zack Williamsba883e32016-04-11 16:06:43 -070018 virt:
19 name={{ item.name }}
20 command=autostart
21 with_items: "{{ head_vm_list }}"
22
23- name: wait for VM's to come up
24 wait_for:
25 host={{ item.name }}
26 port=22
Zack Williams3db3b962016-03-01 21:59:25 -070027 with_items: "{{ head_vm_list }}"
28
Zack Williams0df6f2c2016-02-29 14:48:52 -070029- name: Create /etc/ansible/hosts file
30 become: yes
31 template:
32 src=ansible_hosts.j2
33 dest=/etc/ansible/hosts
34
Zack Williams573bafc2016-02-26 16:35:42 -070035- name: Verify that we can log into every VM
36 command: ansible services -m ping -u ubuntu
37
Zack Williams709f11b2016-03-17 14:29:51 -070038- name: Update software in all the VMs
39 command: ansible services -m apt -b -u ubuntu -a "upgrade=dist update_cache=yes cache_valid_time=3600"
40
41- name: Create VM's eth0 interface config file for DNS config via resolvconf program
Zack Williams4bd2dbc2016-03-10 12:50:02 -070042 template:
Zack Williams709f11b2016-03-17 14:29:51 -070043 src=eth0.cfg.j2
44 dest={{ ansible_user_dir }}/eth0.cfg
45
46- name: Copy eth0 interface config file to all VMs
47 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"
48
49- name: Restart eth0 interface on all VMs
50 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Zack Williams4bd2dbc2016-03-10 12:50:02 -070051
Zack Williamsca83c552016-04-28 09:45:38 -070052- name: Verify that we can log into every VM after restarting network interfaces
53 command: ansible services -m ping -u ubuntu
54
Zack Williams573bafc2016-02-26 16:35:42 -070055- name: Initialize Juju
56 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070057 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070058
Zack Williams823d5292016-02-29 10:31:17 -070059- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070060 template:
Zack Williams823d5292016-02-29 10:31:17 -070061 src=environments.yaml.j2
62 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070063
64- name: Bootstrap Juju
65 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070066 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070067
Zack Williamsa627ae82016-04-13 12:37:10 -070068- name: Copy over juju-config.yml for configuring Juju services
Zack Williams573bafc2016-02-26 16:35:42 -070069 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070070 template:
Zack Williams684aa4c2016-04-14 07:04:38 -070071 src={{ juju_config_name }}_juju_config.yml.j2
Zack Williamsa627ae82016-04-13 12:37:10 -070072 dest={{ juju_config_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070073
Zack Williams0df6f2c2016-02-29 14:48:52 -070074# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070075- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070076 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070077
Zack Williams3dfe6af2016-04-30 11:37:09 -070078- name: Pause to let Juju settle before adding machines
79 pause:
80 prompt="Waiting for Juju..."
81 seconds=20
82
Zack Williams823d5292016-02-29 10:31:17 -070083# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070084# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070085# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070086
Zack Williams9cdf8622016-02-26 22:42:50 -070087- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070088 command: "juju add-machine ssh:{{ item }}"
Zack Williams3dfe6af2016-04-30 11:37:09 -070089 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 -070090
91# run this again, so machines will be in the juju_machines list
92- name: Obtain Juju Facts after machine creation
93 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -070094
95- name: Deploy services that are hosted in their own VM
Zack Williamsc2248c42016-04-30 13:19:42 -070096 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 -070097 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
98
99- name: Deploy mongodb to ceilometer VM
Zack Williamsc2248c42016-04-30 13:19:42 -0700100 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 -0700101 when: juju_services['mongodb'] is undefined
102
103- name: Deploy services that don't have their own VM
Zack Williams9332a1c2016-04-13 15:14:47 -0700104 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -0700105 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -0700106
Zack Williams4bbfe1d2016-02-29 16:16:29 -0700107- name: Create relations between services
108 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -0700109 register: juju_relation
110 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -0700111 with_subelements:
112 - "{{ service_relations }}"
113 - relations
114
Zack Williams709f11b2016-03-17 14:29:51 -0700115# run another time, so services will be in juju_services list
116- name: Obtain Juju Facts after service creation
117 juju_facts:
118
Zack Williams7c35fac2016-04-11 23:52:43 -0700119# 900s = 15m. Usually takes 10-12m on cloudlab for relations to come up
Zack Williams3dfe6af2016-04-30 11:37:09 -0700120# Only checks for first port in list
Zack Williamsabd5d862016-04-26 15:26:47 -0700121- name: Wait for juju services on VM's have open ports
Zack Williams7c35fac2016-04-11 23:52:43 -0700122 wait_for:
123 host={{ item.name }}
124 port={{ item.forwarded_ports[0].int }}
125 timeout=900
126 with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}"
Zack Williams709f11b2016-03-17 14:29:51 -0700127
Zack Williamsabd5d862016-04-26 15:26:47 -0700128# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
Zack Williams3dfe6af2016-04-30 11:37:09 -0700129# 40*15s = 600s = 10m max wait
Zack Williamsabd5d862016-04-26 15:26:47 -0700130- name: Wait for juju services to start
131 action: command juju status --format=summary
132 register: juju_summary
133 until: juju_summary.stdout.find("pending:") == -1
134 retries: 40
135 delay: 15
136
Zack Williams709f11b2016-03-17 14:29:51 -0700137- name: Create admin-openrc.sh credentials file
138 template:
139 src=admin-openrc.sh.j2
140 dest={{ ansible_user_dir }}/admin-openrc.sh
141
142- name: Copy nova-cloud-controller CA certificate to head
143 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
144 creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt
145
Zack Williams008ce252016-04-30 14:39:15 -0700146- name: Copy cert to system location
Zack Williams709f11b2016-03-17 14:29:51 -0700147 become: yes
Zack Williams008ce252016-04-30 14:39:15 -0700148 command: cp {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
Zack Williams709f11b2016-03-17 14:29:51 -0700149 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
150 notify: update-ca-certificates
151
Zack Williams5a2b62d2016-04-28 07:55:18 -0700152- name: Move cert to xos vm
Zack Williams008ce252016-04-30 14:39:15 -0700153 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"
Zack Williams5a2b62d2016-04-28 07:55:18 -0700154
155- name: update-ca-certificates on xos vm
Zack Williams008ce252016-04-30 14:39:15 -0700156 command: ansible xos-1 -b -u ubuntu -m command -a "update-ca-certificates"
Zack Williams3dfe6af2016-04-30 11:37:09 -0700157