blob: 672c9be226151fc1cbc07d7992efc0316ead6e3d [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
Zack Williams709f11b2016-03-17 14:29:51 -07005 shell: uvt-kvm create {{ item.name }} --cpu={{ item.cpu }} --memory={{ item.memMB }} --disk={{ item.diskGB }} ; \
Zack Williams0df6f2c2016-02-29 14:48:52 -07006 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
Zack Williams0df6f2c2016-02-29 14:48:52 -070014- name: Create /etc/ansible/hosts file
15 become: yes
16 template:
17 src=ansible_hosts.j2
18 dest=/etc/ansible/hosts
19
Zack Williams573bafc2016-02-26 16:35:42 -070020- name: Verify that we can log into every VM
21 command: ansible services -m ping -u ubuntu
22
Zack Williams709f11b2016-03-17 14:29:51 -070023- name: Update software in all the VMs
24 command: ansible services -m apt -b -u ubuntu -a "upgrade=dist update_cache=yes cache_valid_time=3600"
25
26- name: Create VM's eth0 interface config file for DNS config via resolvconf program
Zack Williams4bd2dbc2016-03-10 12:50:02 -070027 template:
Zack Williams709f11b2016-03-17 14:29:51 -070028 src=eth0.cfg.j2
29 dest={{ ansible_user_dir }}/eth0.cfg
30
31- name: Copy eth0 interface config file to all VMs
32 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"
33
34- name: Restart eth0 interface on all VMs
35 command: ansible services -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
Zack Williams4bd2dbc2016-03-10 12:50:02 -070036
Zack Williams573bafc2016-02-26 16:35:42 -070037- name: Initialize Juju
38 command: juju generate-config
Zack Williams823d5292016-02-29 10:31:17 -070039 creates={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070040
Zack Williams823d5292016-02-29 10:31:17 -070041- name: Create Juju config file from template
Zack Williams573bafc2016-02-26 16:35:42 -070042 template:
Zack Williams823d5292016-02-29 10:31:17 -070043 src=environments.yaml.j2
44 dest={{ ansible_user_dir }}/.juju/environments.yaml
Zack Williams573bafc2016-02-26 16:35:42 -070045
46- name: Bootstrap Juju
47 command: juju bootstrap
Zack Williams823d5292016-02-29 10:31:17 -070048 creates={{ ansible_user_dir }}/.juju/environments/manual.jenv
Zack Williams573bafc2016-02-26 16:35:42 -070049
Zack Williams0df6f2c2016-02-29 14:48:52 -070050- name: Create openstack.cfg for Juju from template
Zack Williams573bafc2016-02-26 16:35:42 -070051 become: yes
Zack Williams0df6f2c2016-02-29 14:48:52 -070052 template:
53 src=openstack.cfg.j2
54 dest={{ openstack_cfg_path }}
Zack Williams573bafc2016-02-26 16:35:42 -070055
Zack Williams0df6f2c2016-02-29 14:48:52 -070056# Code for this is in library/juju_facts.py
Zack Williams709f11b2016-03-17 14:29:51 -070057- name: Obtain Juju Facts for creating machines
Zack Williams32e12fb2016-02-29 10:25:59 -070058 juju_facts:
Zack Williams573bafc2016-02-26 16:35:42 -070059
Zack Williams823d5292016-02-29 10:31:17 -070060# For setwise operations on desired vs Juju state:
Zack Williams0df6f2c2016-02-29 14:48:52 -070061# list of VM names in head_vm_list dict: head_vm_list | map(attribute='name') | list
Zack Williams32e12fb2016-02-29 10:25:59 -070062# list of active juju_machines names: juju_machines.keys()
Zack Williams823d5292016-02-29 10:31:17 -070063# list of active juju_services names: juju_services.keys()
Zack Williams573bafc2016-02-26 16:35:42 -070064
Zack Williams9cdf8622016-02-26 22:42:50 -070065- name: Add machines to Juju
Zack Williams32e12fb2016-02-29 10:25:59 -070066 command: "juju add-machine ssh:{{ item }}"
Zack Williams709f11b2016-03-17 14:29:51 -070067 with_items: "{{ head_vm_list | map(attribute='service') | list | difference( juju_machines.keys() ) }}"
68
69# run this again, so machines will be in the juju_machines list
70- name: Obtain Juju Facts after machine creation
71 juju_facts:
Zack Williams0df6f2c2016-02-29 14:48:52 -070072
73- name: Deploy services that are hosted in their own VM
74 command: "juju deploy {{ item }} --to {{ juju_machines[item]['machine_id'] }} --config={{ openstack_cfg_path }}"
75 with_items: "{{ vm_service_list | difference( juju_services.keys() ) }}"
76
77- name: Deploy mongodb to ceilometer VM
78 command: "juju deploy mongodb --to {{ juju_machines['ceilometer']['machine_id'] }} --config={{ openstack_cfg_path }}"
79 when: juju_services['mongodb'] is undefined
80
81- name: Deploy services that don't have their own VM
82 command: "juju deploy {{ item }} --config={{ openstack_cfg_path }}"
83 with_items: "{{ standalone_service_list | difference( juju_services.keys() ) }}"
Zack Williams32e12fb2016-02-29 10:25:59 -070084
Zack Williams4bbfe1d2016-02-29 16:16:29 -070085# FIXME: ignoring errors when creating relationships.
86# Previous method wasn't idempotent either
Zack Williams4bbfe1d2016-02-29 16:16:29 -070087- name: Create relations between services
88 command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
Zack Williams709f11b2016-03-17 14:29:51 -070089 register: juju_relation
90 failed_when: "juju_relation|failed and 'relation already exists' not in juju_relation.stderr"
Zack Williams4bbfe1d2016-02-29 16:16:29 -070091 with_subelements:
92 - "{{ service_relations }}"
93 - relations
94
Zack Williams709f11b2016-03-17 14:29:51 -070095# run another time, so services will be in juju_services list
96- name: Obtain Juju Facts after service creation
97 juju_facts:
98
Zack Williams4bd2dbc2016-03-10 12:50:02 -070099# This should be able to test for the VM's coming up, but not working right now
100#- name: Wait for juju services on VM's to come up
Zack Williams709f11b2016-03-17 14:29:51 -0700101# wait_for:
Zack Williams4bd2dbc2016-03-10 12:50:02 -0700102# port={{ item.ext }}
103# timeout=10
104# with_items: "{{ head_vm_list | map(attribute='forwarded_ports') | reject('undefined') | list }}"
Zack Williams3db3b962016-03-01 21:59:25 -0700105
Zack Williams709f11b2016-03-17 14:29:51 -0700106# - name: Obtain keystone admin password
107# command: "juju run --unit={{ juju_services['keystone']['units'].keys()[0] }} 'sudo cat /var/lib/keystone/keystone.passwd'"
108# register: keystone_password
109
110- name: Create admin-openrc.sh credentials file
111 template:
112 src=admin-openrc.sh.j2
113 dest={{ ansible_user_dir }}/admin-openrc.sh
114
115- name: Copy nova-cloud-controller CA certificate to head
116 command: juju scp {{ juju_services['nova-cloud-controller']['units'].keys()[0] }}:/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt {{ ansible_user_dir }}
117 creates={{ ansible_user_dir }}/keystone_juju_ca_cert.crt
118
119- name: Move cert to system location
120 become: yes
121 command: mv {{ ansible_user_dir }}/keystone_juju_ca_cert.crt /usr/local/share/ca-certificates
122 creates=/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt
123 notify: update-ca-certificates
124