blob: 59605e003810b68add2662b715b249ec2229ab72 [file] [log] [blame]
Andrea Campanellaedfdbca2017-02-01 17:33:47 -08001---
2- hosts: {{ instance_name }}
3 gather_facts: False
4 connection: ssh
Andrea Campanella08c14ca2017-03-31 16:13:09 +02005 become_user: ubuntu
6
Andrea Campanellaedfdbca2017-02-01 17:33:47 -08007 vars:
8 cdn_enable: {{ cdn_enable }}
9 dnsdemux_ip: {{ dnsdemux_ip }}
10 firewall_enable: {{ firewall_enable }}
11 url_filter_enable: {{ url_filter_enable }}
12 c_tags:
13 {% for c_tag in c_tags %}
14 - {{ c_tag }}
15 {% endfor %}
16 s_tags:
17 {% for s_tag in s_tags %}
18 - {{ s_tag }}
19 {% endfor %}
20 firewall_rules:
21 {% for firewall_rule in firewall_rules.split("\n") %}
22 - {{ firewall_rule }}
23 {% endfor %}
24 cdn_prefixes:
25 {% for prefix in cdn_prefixes %}
26 - {{ prefix }}
27 {% endfor %}
28 bbs_addrs:
29 {% for bbs_addr in bbs_addrs %}
30 - {{ bbs_addr }}
31 {% endfor %}
32 dns_servers:
33 {% for dns_server in dns_servers %}
34 - {{ dns_server }}
35 {% endfor %}
36 nat_ip: {{ nat_ip }}
37 nat_mac: {{ nat_mac }}
38 lan_ip: {{ lan_ip }}
39 lan_mac: {{ lan_mac }}
40 wan_ip: {{ wan_ip }}
41 wan_mac: {{ wan_mac }}
42 wan_container_mac: {{ wan_container_mac }}
43 wan_next_hop: 10.0.1.253 # FIX ME
44 private_ip: {{ private_ip }}
45 private_mac: {{ private_mac }}
46 hpc_client_ip: {{ hpc_client_ip }}
47 hpc_client_mac: {{ hpc_client_mac }}
48 keystone_tenant_id: {{ keystone_tenant_id }}
49 keystone_user_id: {{ keystone_user_id }}
50 rabbit_user: {{ rabbit_user }}
51 rabbit_password: {{ rabbit_password }}
52 rabbit_host: {{ rabbit_host }}
53 safe_browsing:
54 {% for mac in safe_browsing_macs %}
55 - {{ mac }}
56 {% endfor %}
57 uplink_speed: {{ uplink_speed }}
58 downlink_speed: {{ downlink_speed }}
59 status: {{ status }}
60 enable_uverse: {{ enable_uverse }}
61 url_filter_kind: {{ url_filter_kind }}
62
63 tasks:
64{% if full_setup %}
65 - name: Docker repository
66 copy: src=/opt/xos/synchronizers/veg/files/docker.list
67 dest=/etc/apt/sources.list.d/docker.list
68
69 - name: Import the repository key
70 apt_key: keyserver=keyserver.ubuntu.com id=36A1D7869245C8950F966E92D8576A8BA88D21E9
71
72 - name: install Docker
73 apt: name=lxc-docker state=present update_cache=yes
74
75 - name: install python-setuptools
76 apt: name=python-setuptools state=present
77
78 - name: install pip
79 easy_install: name=pip
80
81 - name: install docker-py
82 pip: name=docker-py version=0.5.3
83
84 - name: install Pipework
85 get_url: url=https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework
86 dest=/usr/local/bin/pipework
87 mode=0755
88
89 - name: make sure /etc/dnsmasq.d exists
90 file: path=/etc/dnsmasq.d state=directory owner=root group=root
91
92 - name: Disable resolvconf service
93 shell: service resolvconf stop
94 shell: echo manual > /etc/init/resolvconf.override
95 shell: rm -f /etc/resolv.conf
96
97 - name: Install resolv.conf
98 copy: src=/opt/xos/synchronizers/veg/files/vm-resolv.conf
99 dest=/etc/resolv.conf
100
101 - 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 +0200102 shell: pgrep -f [v]veg_stats_notifier | wc -l
Andrea Campanellaedfdbca2017-02-01 17:33:47 -0800103 register: cron_job_pids_count
104
105# - name: DEBUG
106# debug: var=cron_job_pids_count.stdout
107
108# - name: make sure ~/bin exists
109# file: path=~/bin state=directory owner=root group=root
110# when: cron_job_pids_count.stdout == "0"
111
112 - name: Copy cron job to destination
113 copy: src=/opt/xos/synchronizers/veg/veg_stats_notifier.py
114 dest=/usr/local/sbin/veg_stats_notifier.py
115 when: cron_job_pids_count.stdout == "0"
116
117 - name: install python-kombu
118 apt: name=python-kombu state=present
119 when: cron_job_pids_count.stdout == "0"
120
121 - name: Initiate veg_stats_notifier cron job
122 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'
123 async: 9999999999999999
124 poll: 0
125 when: cron_job_pids_count.stdout == "0"
126{% endif %}
127
128 - name: vEG upstart
129 template: src=/opt/xos/synchronizers/veg/templates/veg.conf.j2 dest=/etc/init/veg-{{ s_tags[0] }}-{{ c_tags[0] }}.conf
130
131 - name: vEG startup script
132 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
133 notify:
134# - restart veg
135 - stop veg
136 - remove container
137 - start veg
138
139 - name: create /etc/veg-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d
140 file: path=/etc/veg-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d state=directory owner=root group=root
141
142 - name: vEG basic dnsmasq config
143 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
144 notify:
145 - restart dnsmasq
146
147 - name: dnsmasq config
148 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
149 notify:
150 - restart dnsmasq
151
152# These are samples, not necessary for correct function of demo
153
154# - name: networking info
155# template: src=/opt/xos/synchronizers/veg/templates/vlan_sample.j2 dest=/etc/vlan_sample owner=root group=root
156
157# - name: firewall info
158# template: src=/opt/xos/synchronizers/veg/templates/firewall_sample.j2 dest=/etc/firewall_sample owner=root group=root
159
160 - name: Make sure vEG service is running
161 service: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=started
162
163 handlers:
164 # Dnsmasq is automatically restarted in the container
165 - name: restart dnsmasq
166 shell: docker exec veg-{{ s_tags[0] }}-{{ c_tags[0] }} killall dnsmasq
167
168 - name: restart veg
169 shell: service veg-{{ s_tags[0] }}-{{ c_tags[0] }} stop; sleep 1; service veg-{{ s_tags[0] }}-{{ c_tags[0] }} start
170
171 - name: stop veg
172 service: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=stopped
173
174 - name: remove container
175 docker: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=absent image=docker-veg
176
177 - name: start veg
178 service: name=veg-{{ s_tags[0] }}-{{ c_tags[0] }} state=started
179