blob: cc240743f26368fbdb60c78fc4bc779d8656929e [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 Williams0db01a92016-05-01 06:54:24 -070016 become: yes
Zack Williamsba883e32016-04-11 16:06:43 -070017 virt:
18 name={{ item.name }}
19 command=autostart
20 with_items: "{{ head_vm_list }}"
21
22- name: wait for VM's to come up
23 wait_for:
24 host={{ item.name }}
25 port=22
Zack Williams3db3b962016-03-01 21:59:25 -070026 with_items: "{{ head_vm_list }}"
27
Zack Williams0df6f2c2016-02-29 14:48:52 -070028- name: Create /etc/ansible/hosts file
29 become: yes
30 template:
31 src=ansible_hosts.j2
32 dest=/etc/ansible/hosts
33
Zack Williams573bafc2016-02-26 16:35:42 -070034- name: Verify that we can log into every VM
35 command: ansible services -m ping -u ubuntu
36
Zack Williams5f25f362016-05-02 09:18:41 -070037- name: Have VM's use the apt-cache
Zack Williams3eb53422016-05-02 09:59:23 -070038 command: ansible services -b -u ubuntu -m lineinfile -a "dest=/etc/apt/apt.conf.d/02apt-cacher-ng create=yes mode=0644 owner=root group=root regexp='^Acquire' line='Acquire::http { Proxy \"http://{{ apt_cacher_name }}:{{ apt_cacher_port | default('3142') }}\"; };'"
Zack Williams5f25f362016-05-02 09:18:41 -070039
Zack Williams709f11b2016-03-17 14:29:51 -070040- name: Update software in all the VMs
41 command: ansible services -m apt -b -u ubuntu -a "upgrade=dist update_cache=yes cache_valid_time=3600"
42
43- name: Create VM's eth0 interface config file for DNS config via resolvconf program
Zack Williams4bd2dbc2016-03-10 12:50:02 -070044 template:
Zack Williams709f11b2016-03-17 14:29:51 -070045 src=eth0.cfg.j2
46 dest={{ ansible_user_dir }}/eth0.cfg
47
48- name: Copy eth0 interface config file to all VMs
49 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"
50
51- name: Restart eth0 interface on all VMs
52 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Zack Williams4bd2dbc2016-03-10 12:50:02 -070053
Zack Williamsca83c552016-04-28 09:45:38 -070054- name: Verify that we can log into every VM after restarting network interfaces
55 command: ansible services -m ping -u ubuntu
56
Zack Williamsbc566da2016-05-17 14:07:47 -070057- name: Register public key in variable
58 shell: cat {{ ansible_user_dir }}/.ssh/id_rsa.pub
59 register: sshkey
60
Zack Williams91c08442016-05-17 14:37:21 -070061- name: Enable root ssh login on VM's that need it
Zack Williams94f3ac62016-05-17 14:44:59 -070062 command: ansible {{ item.name }} -b -u ubuntu -m authorized_key -a "user='root' key='{{ sshkey.stdout }}'"
Zack Williams91c08442016-05-17 14:37:21 -070063 with_items: "{{ head_vm_list | selectattr('root_ssh_login', 'defined') | list }}"
Zack Williamsbc566da2016-05-17 14:07:47 -070064
Zack Williams573bafc2016-02-26 16:35:42 -070065- name: Initialize Juju
66 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070067 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070068
Zack Williams823d5292016-02-29 10:31:17 -070069- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070070 template:
Zack Williams823d5292016-02-29 10:31:17 -070071 src=environments.yaml.j2
72 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070073
74- name: Bootstrap Juju
75 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070076 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070077
Zack Williamsa627ae82016-04-13 12:37:10 -070078- name: Copy over juju-config.yml for configuring Juju services
Zack Williams573bafc2016-02-26 16:35:42 -070079 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070080 template:
Zack Williams684aa4c2016-04-14 07:04:38 -070081 src={{ juju_config_name }}_juju_config.yml.j2
Zack Williamsa627ae82016-04-13 12:37:10 -070082 dest={{ juju_config_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070083
Zack Williams0df6f2c2016-02-29 14:48:52 -070084# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070085- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070086 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070087
Zack Williams3dfe6af2016-04-30 11:37:09 -070088- name: Pause to let Juju settle before adding machines
89 pause:
90 prompt="Waiting for Juju..."
91 seconds=20
92
Zack Williams823d5292016-02-29 10:31:17 -070093# For setwise operations on desired vs Juju state:
Zack Williams32e12fb2016-02-29 10:25:59 -070094# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070095# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070096
Zack Williams9cdf8622016-02-26 22:42:50 -070097- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070098 command: "juju add-machine ssh:{{ item }}"
Zack Williams3dfe6af2016-04-30 11:37:09 -070099 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 -0700100
101# run this again, so machines will be in the juju_machines list
102- name: Obtain Juju Facts after machine creation
103 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -0700104
105- name: Deploy services that are hosted in their own VM
Zack Williamsc2248c42016-04-30 13:19:42 -0700106 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 -0700107 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
108
109- name: Deploy mongodb to ceilometer VM
Zack Williamsc2248c42016-04-30 13:19:42 -0700110 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 -0700111 when: juju_services['mongodb'] is undefined
112
113- name: Deploy services that don't have their own VM
Zack Williams9332a1c2016-04-13 15:14:47 -0700114 command: "juju deploy {{ charm_versions[item] | default(item) }} --config={{ juju_config_path }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -0700115 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -0700116
Zack Williams4bbfe1d2016-02-29 16:16:29 -0700117- name: Create relations between services
118 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -0700119 register: juju_relation
120 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -0700121 with_subelements:
122 - "{{ service_relations }}"
123 - relations
124
Zack Williams709f11b2016-03-17 14:29:51 -0700125# run another time, so services will be in juju_services list
126- name: Obtain Juju Facts after service creation
127 juju_facts:
128
Zack Williams7c35fac2016-04-11 23:52:43 -0700129# 900s = 15m. Usually takes 10-12m on cloudlab for relations to come up
Zack Williams3dfe6af2016-04-30 11:37:09 -0700130# Only checks for first port in list
Zack Williamsabd5d862016-04-26 15:26:47 -0700131- name: Wait for juju services on VM's have open ports
Zack Williams7c35fac2016-04-11 23:52:43 -0700132 wait_for:
133 host={{ item.name }}
134 port={{ item.forwarded_ports[0].int }}
135 timeout=900
136 with_items: "{{ head_vm_list | selectattr('forwarded_ports', 'defined') | list }}"
Zack Williams709f11b2016-03-17 14:29:51 -0700137
Zack Williamsabd5d862016-04-26 15:26:47 -0700138# secondary wait, as waiting on ports isn't enough. Probably only need one of these...
Zack Williams3dfe6af2016-04-30 11:37:09 -0700139# 40*15s = 600s = 10m max wait
Zack Williamsabd5d862016-04-26 15:26:47 -0700140- name: Wait for juju services to start
141 action: command juju status --format=summary
142 register: juju_summary
143 until: juju_summary.stdout.find("pending:") == -1
144 retries: 40
145 delay: 15
146
Zack Williams709f11b2016-03-17 14:29:51 -0700147- name: Create admin-openrc.sh credentials file
148 template:
149 src=admin-openrc.sh.j2
150 dest={{ ansible_user_dir }}/admin-openrc.sh
151
152- name: Copy nova-cloud-controller CA certificate to head
153 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
154 creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt
155
Zack Williams008ce252016-04-30 14:39:15 -0700156- name: Copy cert to system location
Zack Williams709f11b2016-03-17 14:29:51 -0700157 become: yes
Zack Williams008ce252016-04-30 14:39:15 -0700158 command: cp {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
Zack Williams709f11b2016-03-17 14:29:51 -0700159 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
160 notify: update-ca-certificates
161
Zack Williamsd8b8f472016-05-16 22:40:30 -0700162- name: Move cert to all service VM's
163 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 -0700164
Zack Williamsd8b8f472016-05-16 22:40:30 -0700165- name: update-ca-certificates in service VM's
166 command: ansible services -b -u ubuntu -m command -a "update-ca-certificates"
Zack Williams3dfe6af2016-04-30 11:37:09 -0700167