blob: fe114050f648f10928dcf26f923dbbd4aaf8ff2c [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 }}
Sapan Bhatia4d6cd132016-01-15 10:43:19 -050066
67 tasks:
68 - name: Verify if vcpe_stats_notifier ([] is to avoid capturing the shell process) cron job is already running
69 shell: pgrep -f [v]cpe_stats_notifier | wc -l
70 register: cron_job_pids_count
71
72# - name: DEBUG
73# debug: var=cron_job_pids_count.stdout
74
75 - name: make sure ~/bin exists
76 file: path=~/bin state=directory owner=root group=root
77 when: cron_job_pids_count.stdout == "0"
78
79 - name: Copy cron job to destination
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -050080 copy: src=/opt/xos/synchronizers/vcpe/vcpe_stats_notifier.py
Sapan Bhatia4d6cd132016-01-15 10:43:19 -050081 dest=~/bin/vcpe_stats_notifier.py
82 when: cron_job_pids_count.stdout == "0"
83
84 - name: install python-kombu
85 apt: name=python-kombu state=present
86 when: cron_job_pids_count.stdout == "0"
87
88 - name: Initiate vcpe_stats_notifier cron job
89 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'
90 async: 9999999999999999
91 poll: 0
92 when: cron_job_pids_count.stdout == "0"
93
94 - name: vCPE basic dnsmasq config
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -050095 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 -050096 notify:
97 - restart dnsmasq
98
99 - name: dnsmasq config
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500100 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 -0500101 notify:
102 - restart dnsmasq
103
104 - name: create directory for "safe" config
105 file: path=/var/container_volumes/{{ container_name }}/etc/dnsmasq.d/safe state=directory
106
107 - name: dnsmasq "safe" config
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500108 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 -0500109 notify:
110 - restart dnsmasq
111
112 - name: copy base ufw files
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500113 synchronize: src=/opt/xos/synchronizers/vcpe/files/etc/ufw/ dest=/var/container_volumes/{{ container_name }}/etc/ufw/
Sapan Bhatia4d6cd132016-01-15 10:43:19 -0500114 notify:
115 - reload ufw
116
117 - name: redirection rules for safe DNS
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500118 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 -0500119 notify:
120 - reload ufw
121
122 - name: base ufw setup uses /etc/rc.local
Srikanth Vavilapalli562ba492016-01-25 20:06:43 -0500123 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 -0500124 notify:
125 - copy in /etc/rc.local
126
127 handlers:
128 # Dnsmasq is automatically restarted in the container
129 - name: restart dnsmasq
130 shell: docker exec {{ container_name }} /usr/bin/killall dnsmasq
131
132 - name: reload ufw
133 shell: docker exec {{ container_name }} bash -c "/sbin/iptables -t nat -F PREROUTING; /usr/sbin/ufw reload"
134
135 # Use docker cp instead of single-file volume
136 # The reason is that changes to external file volume don't show up inside the container
137 # Probably Ansible deletes and then recreates the external file, and container has old version
138 - name: copy in /etc/rc.local
139 shell: docker cp /var/container_volumes/{{ container_name }}/etc/rc.local {{ container_name }}:/etc/