blob: 6b7c25e9ebb6f74a6560dc4f4180f713bb1015d8 [file] [log] [blame]
Zack Williams573bafc2016-02-26 16:35:42 -07001---
2# roles/juju-setup/main/tasks.yml
3
Zack Williams0df6f2c2016-02-29 14:48:52 -07004- name: create Virtual Machines with uvt-kvm
5 shell: uvt-kvm create {{ item.name }} --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }}; \
6 uvt-kvm wait --insecure {{ item.name }}
7 creates=/var/lib/uvtool/libvirt/images/{{ item.name }}.qcow
Zack Williams4bbfe1d2016-02-29 16:16:29 -07008 with_items: "{{ head_vm_list }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -07009
Zack Williams3db3b962016-03-01 21:59:25 -070010- name: Have VMs autostart on reboot
11 command: virsh autostart {{ item.name }}
12 with_items: "{{ head_vm_list }}"
13
14- name: Discover VM IP addresses
Zack Williams4bbfe1d2016-02-29 16:16:29 -070015 shell: "uvt-kvm ip {{ item.name }}"
16 with_items: "{{ head_vm_list }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070017 register: vm_ip
18
19- name: Create /etc/hosts with VM IP addresses
20 become: yes
21 template:
22 src=hosts.j2
23 dest=/etc/hosts
24
25- name: Create /etc/ansible/hosts file
26 become: yes
27 template:
28 src=ansible_hosts.j2
29 dest=/etc/ansible/hosts
30
Zack Williams573bafc2016-02-26 16:35:42 -070031- name: Verify that we can log into every VM
32 command: ansible services -m ping -u ubuntu
33
34- name: Initialize Juju
35 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070036 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070037
Zack Williams823d5292016-02-29 10:31:17 -070038- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070039 template:
Zack Williams823d5292016-02-29 10:31:17 -070040 src=environments.yaml.j2
41 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070042
43- name: Bootstrap Juju
44 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070045 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070046
Zack Williams0df6f2c2016-02-29 14:48:52 -070047- name: Create openstack.cfg for Juju from template
Zack Williams573bafc2016-02-26 16:35:42 -070048 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070049 template:
50 src=openstack.cfg.j2
51 dest={{ openstack_cfg_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070052
Zack Williams0df6f2c2016-02-29 14:48:52 -070053# Code for this is in library/juju_facts.py
Zack Williams32e12fb2016-02-29 10:25:59 -070054- name: Obtain Juju Facts
55 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070056
Zack Williams823d5292016-02-29 10:31:17 -070057# For setwise operations on desired vs Juju state:
Zack Williams0df6f2c2016-02-29 14:48:52 -070058# list of VM names in head_vm_list dict: head_vm_list | map(attribute='name') | list
Zack Williams32e12fb2016-02-29 10:25:59 -070059# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070060# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070061
Zack Williams9cdf8622016-02-26 22:42:50 -070062- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070063 command: "juju add-machine ssh:{{ item }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070064 with_items: "{{ head_vm_list | map(attribute='name') | list | difference( juju_machines.keys() ) }}"
65
66- name: Deploy services that are hosted in their own VM
67 command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}"
68 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
69
70- name: Deploy mongodb to ceilometer VM
71 command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}"
72 when: juju_services['mongodb'] is undefined
73
74- name: Deploy services that don't have their own VM
75 command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}"
76 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070077
Zack Williams4bbfe1d2016-02-29 16:16:29 -070078# FIXME: ignoring errors when creating relationships.
79# Previous method wasn't idempotent either
80
81- name: Create relations between services
82 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
83 ignore_errors: True
84 with_subelements:
85 - "{{ service_relations }}"
86 - relations
87
88# Need to wait for services to come up here
Zack Williams3db3b962016-03-01 21:59:25 -070089# Possibly do so by using wait_for and wating on forwarded ports after next step?
90
91- name: Have libvirt enable port forwarding to VM's
92 become: yes
93 copy:
94 src={{ item }}
95 dest=/etc/libvirt/hooks/{{ item }}
96 mode=0755 owner=root
97 with_items:
98 - daemon
99 - qemu
100 notify:
101 - reload libvirt-bin
102 - run qemu hook
103