blob: fc3c96a3e0c1b9bbff4f82c11cf0e4bf095788cf [file] [log] [blame]
Matteo Scandolo6288d5a2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Andrea Campanellaedfdbca2017-02-01 17:33:47 -080017---
18- hosts: {{ instance_name }}
19 gather_facts: False
20 connection: ssh
Andrea Campanella08c14ca2017-03-31 16:13:09 +020021 become_user: ubuntu
22
Andrea Campanellaedfdbca2017-02-01 17:33:47 -080023 vars:
24 cdn_enable: {{ cdn_enable }}
25 dnsdemux_ip: {{ dnsdemux_ip }}
26 firewall_enable: {{ firewall_enable }}
27 url_filter_enable: {{ url_filter_enable }}
28 c_tags:
29 {% for c_tag in c_tags %}
30 - {{ c_tag }}
31 {% endfor %}
32 s_tags:
33 {% for s_tag in s_tags %}
34 - {{ s_tag }}
35 {% endfor %}
36 firewall_rules:
37 {% for firewall_rule in firewall_rules.split("\n") %}
38 - {{ firewall_rule }}
39 {% endfor %}
40 cdn_prefixes:
41 {% for prefix in cdn_prefixes %}
42 - {{ prefix }}
43 {% endfor %}
44 bbs_addrs:
45 {% for bbs_addr in bbs_addrs %}
46 - {{ bbs_addr }}
47 {% endfor %}
48 dns_servers:
49 {% for dns_server in dns_servers %}
50 - {{ dns_server }}
51 {% endfor %}
52 nat_ip: {{ nat_ip }}
53 nat_mac: {{ nat_mac }}
54 lan_ip: {{ lan_ip }}
55 lan_mac: {{ lan_mac }}
56 wan_ip: {{ wan_ip }}
57 wan_mac: {{ wan_mac }}
58 wan_container_mac: {{ wan_container_mac }}
59 wan_next_hop: 10.0.1.253 # FIX ME
60 private_ip: {{ private_ip }}
61 private_mac: {{ private_mac }}
62 hpc_client_ip: {{ hpc_client_ip }}
63 hpc_client_mac: {{ hpc_client_mac }}
64 keystone_tenant_id: {{ keystone_tenant_id }}
65 keystone_user_id: {{ keystone_user_id }}
66 rabbit_user: {{ rabbit_user }}
67 rabbit_password: {{ rabbit_password }}
68 rabbit_host: {{ rabbit_host }}
69 safe_browsing:
70 {% for mac in safe_browsing_macs %}
71 - {{ mac }}
72 {% endfor %}
73 uplink_speed: {{ uplink_speed }}
74 downlink_speed: {{ downlink_speed }}
75 status: {{ status }}
76 enable_uverse: {{ enable_uverse }}
77 url_filter_kind: {{ url_filter_kind }}
78
79 tasks:
80{% if full_setup %}
81 - name: Docker repository
82 copy: src=/opt/xos/synchronizers/veg/files/docker.list
83 dest=/etc/apt/sources.list.d/docker.list
84
85 - name: Import the repository key
86 apt_key: keyserver=keyserver.ubuntu.com id=36A1D7869245C8950F966E92D8576A8BA88D21E9
87
88 - name: install Docker
89 apt: name=lxc-docker state=present update_cache=yes
90
91 - name: install python-setuptools
92 apt: name=python-setuptools state=present
93
94 - name: install pip
95 easy_install: name=pip
96
97 - name: install docker-py
98 pip: name=docker-py version=0.5.3
99
100 - name: install Pipework
101 get_url: url=https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework
102 dest=/usr/local/bin/pipework
103 mode=0755
104
105 - name: make sure /etc/dnsmasq.d exists
106 file: path=/etc/dnsmasq.d state=directory owner=root group=root
107
108 - name: Disable resolvconf service
109 shell: service resolvconf stop
110 shell: echo manual > /etc/init/resolvconf.override
111 shell: rm -f /etc/resolv.conf
112
113 - name: Install resolv.conf
114 copy: src=/opt/xos/synchronizers/veg/files/vm-resolv.conf
115 dest=/etc/resolv.conf
116
117 - name: Verify if veg_stats_notifier ([] is to avoid capturing the shell process) cron job is already running
Andrea Campanella08c14ca2017-03-31 16:13:09 +0200118 shell: pgrep -f [v]veg_stats_notifier | wc -l
Andrea Campanellaedfdbca2017-02-01 17:33:47 -0800119 register: cron_job_pids_count
120
121# - name: DEBUG
122# debug: var=cron_job_pids_count.stdout
123
124# - name: make sure ~/bin exists
125# file: path=~/bin state=directory owner=root group=root
126# when: cron_job_pids_count.stdout == "0"
127
128 - name: Copy cron job to destination
129 copy: src=/opt/xos/synchronizers/veg/veg_stats_notifier.py
130 dest=/usr/local/sbin/veg_stats_notifier.py
131 when: cron_job_pids_count.stdout == "0"
132
133 - name: install python-kombu
134 apt: name=python-kombu state=present
135 when: cron_job_pids_count.stdout == "0"
136
137 - name: Initiate veg_stats_notifier cron job
138 command: sudo python /usr/local/sbin/veg_stats_notifier.py --keystone_tenant_id={{ keystone_tenant_id }} --keystone_user_id={{ keystone_user_id }} --rabbit_user={{ rabbit_user }} --rabbit_password={{ rabbit_password }} --rabbit_host={{ rabbit_host }} --vegservice_rabbit_exchange='vegservice'
139 async: 9999999999999999
140 poll: 0
141 when: cron_job_pids_count.stdout == "0"
142{% endif %}
143
144 - name: vEG upstart
145 template: src=/opt/xos/synchronizers/veg/templates/veg.conf.j2 dest=/etc/init/veg-{{ s_tags[0] }}-{{ c_tags[0] }}.conf
146
147 - name: vEG startup script
148 template: src=/opt/xos/synchronizers/veg/templates/start-veg.sh.j2 dest=/usr/local/sbin/start-veg-{{ s_tags[0] }}-{{ c_tags[0] }}.sh mode=0755
149 notify:
150# - restart veg
151 - stop veg
152 - remove container
153 - start veg
154
155 - name: create /etc/veg-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d
156 file: path=/etc/veg-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d state=directory owner=root group=root
157
158 - name: vEG basic dnsmasq config
159 copy: src=/opt/xos/synchronizers/veg/files/veg.dnsmasq dest=/etc/veg-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d/veg.conf owner=root group=root
160 notify:
161 - restart dnsmasq
162
163 - name: dnsmasq config
164 template: src=/opt/xos/synchronizers/veg/templates/dnsmasq_servers.j2 dest=/etc/veg-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d/servers.conf owner=root group=root
165 notify:
166 - restart dnsmasq
167
168# These are samples, not necessary for correct function of demo
169
170# - name: networking info
171# template: src=/opt/xos/synchronizers/veg/templates/vlan_sample.j2 dest=/etc/vlan_sample owner=root group=root
172
173# - name: firewall info
174# template: src=/opt/xos/synchronizers/veg/templates/firewall_sample.j2 dest=/etc/firewall_sample owner=root group=root
175
176 - name: Make sure vEG service is running
177 service: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=started
178
179 handlers:
180 # Dnsmasq is automatically restarted in the container
181 - name: restart dnsmasq
182 shell: docker exec veg-{{ s_tags[0] }}-{{ c_tags[0] }} killall dnsmasq
183
184 - name: restart veg
185 shell: service veg-{{ s_tags[0] }}-{{ c_tags[0] }} stop; sleep 1; service veg-{{ s_tags[0] }}-{{ c_tags[0] }} start
186
187 - name: stop veg
188 service: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=stopped
189
190 - name: remove container
191 docker: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=absent image=docker-veg
192
193 - name: start veg
194 service: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=started
195