Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 1 | --- |
| 2 | - hosts: {{ instance_name }} |
| 3 | gather_facts: False |
| 4 | connection: ssh |
| 5 | user: ubuntu |
| 6 | sudo: yes |
| 7 | vars: |
| 8 | cdn_enable: {{ cdn_enable }} |
| 9 | dnsdemux_ip: {{ dnsdemux_ip }} |
| 10 | firewall_enable: {{ firewall_enable }} |
| 11 | url_filter_enable: {{ url_filter_enable }} |
| 12 | vlan_ids: |
| 13 | {% for vlan_id in vlan_ids %} |
| 14 | - {{ vlan_id }} |
| 15 | {% endfor %} |
| 16 | c_tags: |
| 17 | {% for c_tag in c_tags %} |
| 18 | - {{ c_tag }} |
| 19 | {% endfor %} |
| 20 | s_tags: |
| 21 | {% for s_tag in s_tags %} |
| 22 | - {{ s_tag }} |
| 23 | {% endfor %} |
| 24 | firewall_rules: |
| 25 | {% for firewall_rule in firewall_rules.split("\n") %} |
| 26 | - {{ firewall_rule }} |
| 27 | {% endfor %} |
| 28 | cdn_prefixes: |
| 29 | {% for prefix in cdn_prefixes %} |
| 30 | - {{ prefix }} |
| 31 | {% endfor %} |
| 32 | bbs_addrs: |
| 33 | {% for bbs_addr in bbs_addrs %} |
| 34 | - {{ bbs_addr }} |
| 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 | |
| 58 | tasks: |
| 59 | {% if full_setup %} |
| 60 | - name: Docker repository |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 61 | copy: src=/opt/xos/synchronizers/vcpe/files/docker.list |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 62 | dest=/etc/apt/sources.list.d/docker.list |
| 63 | |
| 64 | - name: Import the repository key |
| 65 | apt_key: keyserver=keyserver.ubuntu.com id=36A1D7869245C8950F966E92D8576A8BA88D21E9 |
| 66 | |
| 67 | - name: install Docker |
| 68 | apt: name=lxc-docker state=present update_cache=yes |
| 69 | |
| 70 | - name: install python-setuptools |
| 71 | apt: name=python-setuptools state=present |
| 72 | |
| 73 | - name: install pip |
| 74 | easy_install: name=pip |
| 75 | |
| 76 | - name: install docker-py |
| 77 | pip: name=docker-py version=0.5.3 |
| 78 | |
| 79 | - name: install Pipework |
| 80 | get_url: url=https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework |
| 81 | dest=/usr/local/bin/pipework |
| 82 | mode=0755 |
| 83 | |
| 84 | - name: make sure /etc/dnsmasq.d exists |
| 85 | file: path=/etc/dnsmasq.d state=directory owner=root group=root |
| 86 | |
| 87 | - name: Disable resolvconf service |
| 88 | shell: service resolvconf stop |
| 89 | shell: echo manual > /etc/init/resolvconf.override |
| 90 | shell: rm -f /etc/resolv.conf |
| 91 | |
| 92 | - name: Install resolv.conf |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 93 | copy: src=/opt/xos/synchronizers/vcpe/files/vm-resolv.conf |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 94 | dest=/etc/resolv.conf |
| 95 | |
| 96 | - name: Verify if vcpe_stats_notifier ([] is to avoid capturing the shell process) cron job is already running |
| 97 | shell: pgrep -f [v]cpe_stats_notifier | wc -l |
| 98 | register: cron_job_pids_count |
| 99 | |
| 100 | # - name: DEBUG |
| 101 | # debug: var=cron_job_pids_count.stdout |
| 102 | |
| 103 | - name: make sure ~/bin exists |
| 104 | file: path=~/bin state=directory owner=root group=root |
| 105 | when: cron_job_pids_count.stdout == "0" |
| 106 | |
| 107 | - name: Copy cron job to destination |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 108 | copy: src=/opt/xos/synchronizers/vcpe/vcpe_stats_notifier.py |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 109 | dest=~/bin/vcpe_stats_notifier.py |
| 110 | when: cron_job_pids_count.stdout == "0" |
| 111 | |
| 112 | - name: install python-kombu |
| 113 | apt: name=python-kombu state=present |
| 114 | when: cron_job_pids_count.stdout == "0" |
| 115 | |
| 116 | - name: Initiate vcpe_stats_notifier cron job |
| 117 | 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' |
| 118 | async: 9999999999999999 |
| 119 | poll: 0 |
| 120 | when: cron_job_pids_count.stdout == "0" |
| 121 | {% endif %} |
| 122 | |
| 123 | - name: vCPE upstart |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 124 | template: src=/opt/xos/synchronizers/vcpe/templates/vcpe.conf.j2 dest=/etc/init/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}.conf |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 125 | |
| 126 | - name: vCPE startup script |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 127 | template: src=/opt/xos/synchronizers/vcpe/templates/start-vcpe.sh.j2 dest=/usr/local/sbin/start-vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}.sh mode=0755 |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 128 | notify: |
| 129 | # - restart vcpe |
| 130 | - stop vcpe |
| 131 | - remove container |
| 132 | - start vcpe |
| 133 | |
| 134 | - name: create /etc/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d |
| 135 | file: path=/etc/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d state=directory owner=root group=root |
| 136 | |
| 137 | - name: vCPE basic dnsmasq config |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 138 | copy: src=/opt/xos/synchronizers/vcpe/files/vcpe.dnsmasq dest=/etc/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d/vcpe.conf owner=root group=root |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 139 | notify: |
| 140 | - restart dnsmasq |
| 141 | |
| 142 | - name: dnsmasq config |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 143 | template: src=/opt/xos/synchronizers/vcpe/templates/dnsmasq_servers.j2 dest=/etc/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d/servers.conf owner=root group=root |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 144 | notify: |
| 145 | - restart dnsmasq |
| 146 | |
| 147 | # These are samples, not necessary for correct function of demo |
| 148 | |
| 149 | # - name: networking info |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 150 | # template: src=/opt/xos/synchronizers/vcpe/templates/vlan_sample.j2 dest=/etc/vlan_sample owner=root group=root |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 151 | |
| 152 | # - name: firewall info |
Srikanth Vavilapalli | 562ba49 | 2016-01-25 20:06:43 -0500 | [diff] [blame] | 153 | # template: src=/opt/xos/synchronizers/vcpe/templates/firewall_sample.j2 dest=/etc/firewall_sample owner=root group=root |
Sapan Bhatia | 4d6cd13 | 2016-01-15 10:43:19 -0500 | [diff] [blame] | 154 | |
| 155 | - name: Make sure vCPE service is running |
| 156 | service: name=vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} state=started |
| 157 | |
| 158 | handlers: |
| 159 | # Dnsmasq is automatically restarted in the container |
| 160 | - name: restart dnsmasq |
| 161 | shell: docker exec vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} killall dnsmasq |
| 162 | |
| 163 | - name: restart vcpe |
| 164 | shell: service vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} stop; sleep 1; service vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} start |
| 165 | |
| 166 | - name: stop vcpe |
| 167 | service: name=vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} state=stopped |
| 168 | |
| 169 | - name: remove container |
| 170 | docker: name=vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} state=absent image=docker-vcpe |
| 171 | |
| 172 | - name: start vcpe |
| 173 | service: name=vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} state=started |
| 174 | |