blob: ae82be72f94cd1e7a1ae1a17859d7186cc498748 [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 Williams709f11b2016-03-17 14:29:51 -070010 shell: uvt-kvm create {{ item.name }} --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} ; \
Zack Williams0df6f2c2016-02-29 14:48:52 -070011 uvt-kvm wait --insecure {{ item.name }}
12 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
16 command: virsh autostart {{ item.name }}
17 with_items: "{{ head_vm_list }}"
18
Zack Williams0df6f2c2016-02-29 14:48:52 -070019- name: Create /etc/ansible/hosts file
20 become: yes
21 template:
22 src=ansible_hosts.j2
23 dest=/etc/ansible/hosts
24
Zack Williams573bafc2016-02-26 16:35:42 -070025- name: Verify that we can log into every VM
26 command: ansible services -m ping -u ubuntu
27
Zack Williams709f11b2016-03-17 14:29:51 -070028- name: Update software in all the VMs
29 command: ansible services -m apt -b -u ubuntu -a "upgrade=dist update_cache=yes cache_valid_time=3600"
30
31- name: Create VM's eth0 interface config file for DNS config via resolvconf program
Zack Williams4bd2dbc2016-03-10 12:50:02 -070032 template:
Zack Williams709f11b2016-03-17 14:29:51 -070033 src=eth0.cfg.j2
34 dest={{ ansible_user_dir }}/eth0.cfg
35
36- name: Copy eth0 interface config file to all VMs
37 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"
38
39- name: Restart eth0 interface on all VMs
40 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Zack Williams4bd2dbc2016-03-10 12:50:02 -070041
Zack Williams573bafc2016-02-26 16:35:42 -070042- name: Initialize Juju
43 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070044 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070045
Zack Williams823d5292016-02-29 10:31:17 -070046- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070047 template:
Zack Williams823d5292016-02-29 10:31:17 -070048 src=environments.yaml.j2
49 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070050
51- name: Bootstrap Juju
52 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070053 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070054
Zack Williams0df6f2c2016-02-29 14:48:52 -070055- name: Create openstack.cfg for Juju from template
Zack Williams573bafc2016-02-26 16:35:42 -070056 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070057 template:
58 src=openstack.cfg.j2
59 dest={{ openstack_cfg_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070060
Zack Williams0df6f2c2016-02-29 14:48:52 -070061# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070062- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070063 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070064
Zack Williams823d5292016-02-29 10:31:17 -070065# For setwise operations on desired vs Juju state:
Zack Williams0df6f2c2016-02-29 14:48:52 -070066# list of VM names in head_vm_list dict: head_vm_list | map(attribute='name') | list
Zack Williams32e12fb2016-02-29 10:25:59 -070067# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070068# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070069
Zack Williams9cdf8622016-02-26 22:42:50 -070070- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070071 command: "juju add-machine ssh:{{ item }}"
Zack Williams709f11b2016-03-17 14:29:51 -070072 with_items: "{{ head_vm_list | map(attribute='service') | list | difference( juju_machines.keys() ) }}"
73
74# run this again, so machines will be in the juju_machines list
75- name: Obtain Juju Facts after machine creation
76 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -070077
78- name: Deploy services that are hosted in their own VM
79 command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}"
80 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
81
82- name: Deploy mongodb to ceilometer VM
83 command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}"
84 when: juju_services['mongodb'] is undefined
85
86- name: Deploy services that don't have their own VM
87 command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}"
88 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070089
Zack Williams4bbfe1d2016-02-29 16:16:29 -070090# FIXME: ignoring errors when creating relationships.
91# Previous method wasn't idempotent either
Zack Williams4bbfe1d2016-02-29 16:16:29 -070092- name: Create relations between services
93 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070094 register: juju_relation
95 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070096 with_subelements:
97 - "{{ service_relations }}"
98 - relations
99
Zack Williams709f11b2016-03-17 14:29:51 -0700100# run another time, so services will be in juju_services list
101- name: Obtain Juju Facts after service creation
102 juju_facts:
103
Zack Williams4bd2dbc2016-03-10 12:50:02 -0700104# This should be able to test for the VM's coming up, but not working right now
105#- name: Wait for juju services on VM's to come up
Zack Williams709f11b2016-03-17 14:29:51 -0700106# wait_for:
Zack Williams4bd2dbc2016-03-10 12:50:02 -0700107# port={{ item.ext }}
108# timeout=10
109# with_items: "{{ head_vm_list | map(attribute='forwarded_ports') | reject('undefined') | list }}"
Zack Williams3db3b962016-03-01 21:59:25 -0700110
Zack Williams709f11b2016-03-17 14:29:51 -0700111# - name: Obtain keystone admin password
112# command: "juju run --unit={{ juju_services['keystone']['units'].keys()[0] }} 'sudo cat /var/lib/keystone/keystone.passwd'"
113# register: keystone_password
114
115- name: Create admin-openrc.sh credentials file
116 template:
117 src=admin-openrc.sh.j2
118 dest={{ ansible_user_dir }}/admin-openrc.sh
119
120- name: Copy nova-cloud-controller CA certificate to head
121 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
122 creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt
123
124- name: Move cert to system location
125 become: yes
126 command: mv {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
127 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
128 notify: update-ca-certificates
129