blob: 324e274aefca6f73bff85ee50a1fac2395a240eb [file] [log] [blame]
Sapan Bhatia4d6cd132016-01-15 10:43:19 -05001---
2- hosts: {{ instance_name }}
3 gather_facts: False
4 connection: ssh
5 user: {{ username }}
6 sudo: yes
7 vars:
8 container_name: {{ container_name }}
9 cdn_enable: {{ cdn_enable }}
10 dnsdemux_ip: {{ dnsdemux_ip }}
11 firewall_enable: {{ firewall_enable }}
12 url_filter_enable: {{ url_filter_enable }}
13 vlan_ids:
14 {% for vlan_id in vlan_ids %}
15 - {{ vlan_id }}
16 {% endfor %}
17 c_tags:
18 {% for c_tag in c_tags %}
19 - {{ c_tag }}
20 {% endfor %}
21 s_tags:
22 {% for s_tag in s_tags %}
23 - {{ s_tag }}
24 {% endfor %}
25 firewall_rules:
26 {% for firewall_rule in firewall_rules.split("\n") %}
27 - {{ firewall_rule }}
28 {% endfor %}
29 cdn_prefixes:
30 {% for prefix in cdn_prefixes %}
31 - {{ prefix }}
32 {% endfor %}
33 bbs_addrs:
34 {% for bbs_addr in bbs_addrs %}
35 - {{ bbs_addr }}
36 {% endfor %}
Scott Bakerd9fba162016-02-23 16:01:09 -080037 dns_servers:
38 {% for dns_server in dns_servers %}
39 - {{ dns_server }}
40 {% endfor %}
Sapan Bhatia4d6cd132016-01-15 10:43:19 -050041 nat_ip: {{ nat_ip }}
42 nat_mac: {{ nat_mac }}
43 lan_ip: {{ lan_ip }}
44 lan_mac: {{ lan_mac }}
45 wan_ip: {{ wan_ip }}
46 wan_mac: {{ wan_mac }}
47 wan_container_mac: {{ wan_container_mac }}
48 wan_next_hop: 10.0.1.253 # FIX ME
49 private_ip: {{ private_ip }}
50 private_mac: {{ private_mac }}
51 hpc_client_ip: {{ hpc_client_ip }}
52 hpc_client_mac: {{ hpc_client_mac }}
53 keystone_tenant_id: {{ keystone_tenant_id }}
54 keystone_user_id: {{ keystone_user_id }}
55 rabbit_user: {{ rabbit_user }}
56 rabbit_password: {{ rabbit_password }}
57 rabbit_host: {{ rabbit_host }}
58 safe_browsing:
59 {% for mac in safe_browsing_macs %}
60 - {{ mac }}
61 {% endfor %}
Scott Bakere98eea82016-03-01 20:44:40 -080062 uplink_speed: {{ uplink_speed }}
63 downlink_speed: {{ downlink_speed }}
64 status: {{ status }}
65 enable_uverse: {{ enable_uverse }}
Scott Bakerbe2bc9a2016-03-10 20:12:15 -080066 url_filter_kind: {{ url_filter_kind }}
Sapan Bhatia4d6cd132016-01-15 10:43:19 -050067
68 tasks:
69 - name: Verify if vcpe_stats_notifier ([] is to avoid capturing the shell process) cron job is already running
70 shell: pgrep -f [v]cpe_stats_notifier | wc -l
71 register: cron_job_pids_count
72
73# - name: DEBUG
74# debug: var=cron_job_pids_count.stdout
75
76 - name: make sure ~/bin exists
77 file: path=~/bin state=directory owner=root group=root
78 when: cron_job_pids_count.stdout == "0"
79
80 - name: Copy cron job to destination
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -050081 copy: src=/opt/xos/synchronizers/vcpe/vcpe_stats_notifier.py
Sapan Bhatia4d6cd132016-01-15 10:43:19 -050082 dest=~/bin/vcpe_stats_notifier.py
83 when: cron_job_pids_count.stdout == "0"
84
85 - name: install python-kombu
86 apt: name=python-kombu state=present
87 when: cron_job_pids_count.stdout == "0"
88
89 - name: Initiate vcpe_stats_notifier cron job
90 command: python ~/bin/vcpe_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 }} --vcpeservice_rabbit_exchange='vcpeservice'
91 async: 9999999999999999
92 poll: 0
93 when: cron_job_pids_count.stdout == "0"
94
95 - name: vCPE basic dnsmasq config
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -050096 copy: src=/opt/xos/synchronizers/vcpe/files/vcpe.dnsmasq dest=/var/container_volumes/{{ container_name }}/etc/dnsmasq.d/vcpe.conf owner=root group=root
Sapan Bhatia4d6cd132016-01-15 10:43:19 -050097 notify:
98 - restart dnsmasq
99
100 - name: dnsmasq config
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500101 template: src=/opt/xos/synchronizers/vcpe/templates/dnsmasq_servers.j2 dest=/var/container_volumes/{{ container_name }}/etc/dnsmasq.d/servers.conf owner=root group=root
Sapan Bhatia4d6cd132016-01-15 10:43:19 -0500102 notify:
103 - restart dnsmasq
104
105 - name: create directory for "safe" config
106 file: path=/var/container_volumes/{{ container_name }}/etc/dnsmasq.d/safe state=directory
107
108 - name: dnsmasq "safe" config
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500109 template: src=/opt/xos/synchronizers/vcpe/templates/dnsmasq_safe_servers.j2 dest=/var/container_volumes/{{ container_name }}/etc/dnsmasq.d/safe/servers.conf owner=root group=root
Sapan Bhatia4d6cd132016-01-15 10:43:19 -0500110 notify:
111 - restart dnsmasq
112
113 - name: copy base ufw files
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500114 synchronize: src=/opt/xos/synchronizers/vcpe/files/etc/ufw/ dest=/var/container_volumes/{{ container_name }}/etc/ufw/
Sapan Bhatia4d6cd132016-01-15 10:43:19 -0500115 notify:
116 - reload ufw
117
118 - name: redirection rules for safe DNS
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500119 template: src=/opt/xos/synchronizers/vcpe/templates/before.rules.j2 dest=/var/container_volumes/{{ container_name }}/etc/ufw/before.rules owner=root group=root
Sapan Bhatia4d6cd132016-01-15 10:43:19 -0500120 notify:
121 - reload ufw
122
123 - name: base ufw setup uses /etc/rc.local
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500124 copy: src=/opt/xos/synchronizers/vcpe/files/etc/rc.local dest=/var/container_volumes/{{ container_name }}/etc/ owner=root group=root
Sapan Bhatia4d6cd132016-01-15 10:43:19 -0500125 notify:
126 - copy in /etc/rc.local
127
128 handlers:
129 # Dnsmasq is automatically restarted in the container
130 - name: restart dnsmasq
131 shell: docker exec {{ container_name }} /usr/bin/killall dnsmasq
132
133 - name: reload ufw
134 shell: docker exec {{ container_name }} bash -c "/sbin/iptables -t nat -F PREROUTING; /usr/sbin/ufw reload"
135
136 # Use docker cp instead of single-file volume
137 # The reason is that changes to external file volume don't show up inside the container
138 # Probably Ansible deletes and then recreates the external file, and container has old version
139 - name: copy in /etc/rc.local
140 shell: docker cp /var/container_volumes/{{ container_name }}/etc/rc.local {{ container_name }}:/etc/