blob: d1b2f3043f4a73b9f8b79bfc3258c7d2aff7c059 [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
Zack Williams4bd2dbc2016-03-10 12:50:02 -070034- name: Have libvirt enable port forwarding to VM's
35 become: yes
36 template:
37 src={{ item }}.j2
38 dest=/etc/libvirt/hooks/{{ item }}
39 mode=0755 owner=root
40 with_items:
41 - daemon
42 - qemu
43 notify:
44 - reload libvirt-bin
45 - run qemu hook
46
Zack Williams573bafc2016-02-26 16:35:42 -070047- name: Initialize Juju
48 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070049 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070050
Zack Williams823d5292016-02-29 10:31:17 -070051- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070052 template:
Zack Williams823d5292016-02-29 10:31:17 -070053 src=environments.yaml.j2
54 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070055
56- name: Bootstrap Juju
57 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070058 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070059
Zack Williams0df6f2c2016-02-29 14:48:52 -070060- name: Create openstack.cfg for Juju from template
Zack Williams573bafc2016-02-26 16:35:42 -070061 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070062 template:
63 src=openstack.cfg.j2
64 dest={{ openstack_cfg_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070065
Zack Williams0df6f2c2016-02-29 14:48:52 -070066# Code for this is in library/juju_facts.py
Zack Williams32e12fb2016-02-29 10:25:59 -070067- name: Obtain Juju Facts
68 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070069
Zack Williams823d5292016-02-29 10:31:17 -070070# For setwise operations on desired vs Juju state:
Zack Williams0df6f2c2016-02-29 14:48:52 -070071# list of VM names in head_vm_list dict: head_vm_list | map(attribute='name') | list
Zack Williams32e12fb2016-02-29 10:25:59 -070072# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070073# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070074
Zack Williams9cdf8622016-02-26 22:42:50 -070075- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070076 command: "juju add-machine ssh:{{ item }}"
Zack Williams0df6f2c2016-02-29 14:48:52 -070077 with_items: "{{ head_vm_list | map(attribute='name') | list | difference( juju_machines.keys() ) }}"
78
79- name: Deploy services that are hosted in their own VM
80 command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}"
81 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
82
83- name: Deploy mongodb to ceilometer VM
84 command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}"
85 when: juju_services['mongodb'] is undefined
86
87- name: Deploy services that don't have their own VM
88 command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}"
89 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070090
Zack Williams4bbfe1d2016-02-29 16:16:29 -070091# FIXME: ignoring errors when creating relationships.
92# Previous method wasn't idempotent either
Zack Williams4bbfe1d2016-02-29 16:16:29 -070093- name: Create relations between services
94 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
95 ignore_errors: True
96 with_subelements:
97 - "{{ service_relations }}"
98 - relations
99
Zack Williams4bd2dbc2016-03-10 12:50:02 -0700100# This should be able to test for the VM's coming up, but not working right now
101#- name: Wait for juju services on VM's to come up
102# wait_for:
103# port={{ item.ext }}
104# timeout=10
105# with_items: "{{ head_vm_list | map(attribute='forwarded_ports') | reject('undefined') | list }}"
Zack Williams3db3b962016-03-01 21:59:25 -0700106