Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [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 | 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/vsg/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/vsg/files/vm-resolv.conf |
| 99 | dest=/etc/resolv.conf |
| 100 | |
| 101 | - name: Verify if vcpe_stats_notifier ([] is to avoid capturing the shell process) cron job is already running |
| 102 | shell: pgrep -f [v]cpe_stats_notifier | wc -l |
| 103 | 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/vsg/vcpe_stats_notifier.py |
| 114 | dest=/usr/local/sbin/vcpe_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 vcpe_stats_notifier cron job |
| 122 | command: sudo python /usr/local/sbin/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' |
| 123 | async: 9999999999999999 |
| 124 | poll: 0 |
| 125 | when: cron_job_pids_count.stdout == "0" |
| 126 | {% endif %} |
| 127 | |
| 128 | - name: vCPE upstart |
| 129 | template: src=/opt/xos/synchronizers/vsg/templates/vcpe.conf.j2 dest=/etc/init/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}.conf |
| 130 | |
| 131 | - name: vCPE startup script |
| 132 | template: src=/opt/xos/synchronizers/vsg/templates/start-vcpe.sh.j2 dest=/usr/local/sbin/start-vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}.sh mode=0755 |
| 133 | notify: |
| 134 | # - restart vcpe |
| 135 | - stop vcpe |
| 136 | - remove container |
| 137 | - start vcpe |
| 138 | |
| 139 | - name: create /etc/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d |
| 140 | file: path=/etc/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d state=directory owner=root group=root |
| 141 | |
| 142 | - name: vCPE basic dnsmasq config |
| 143 | copy: src=/opt/xos/synchronizers/vsg/files/vcpe.dnsmasq dest=/etc/vcpe-{{ s_tags[0] }}-{{ c_tags[0] }}/dnsmasq.d/vcpe.conf owner=root group=root |
| 144 | notify: |
| 145 | - restart dnsmasq |
| 146 | |
| 147 | - name: dnsmasq config |
| 148 | template: src=/opt/xos/synchronizers/vsg/templates/dnsmasq_servers.j2 dest=/etc/vcpe-{{ 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/vsg/templates/vlan_sample.j2 dest=/etc/vlan_sample owner=root group=root |
| 156 | |
| 157 | # - name: firewall info |
| 158 | # template: src=/opt/xos/synchronizers/vsg/templates/firewall_sample.j2 dest=/etc/firewall_sample owner=root group=root |
| 159 | |
| 160 | - name: Make sure vCPE service is running |
| 161 | service: name=vcpe-{{ 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 vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} killall dnsmasq |
| 167 | |
| 168 | - name: restart vcpe |
| 169 | shell: service vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} stop; sleep 1; service vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} start |
| 170 | |
| 171 | - name: stop vcpe |
| 172 | service: name=vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} state=stopped |
| 173 | |
| 174 | - name: remove container |
| 175 | docker: name=vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} state=absent image=docker-vcpe |
| 176 | |
| 177 | - name: start vcpe |
| 178 | service: name=vcpe-{{ s_tags[0] }}-{{ c_tags[0] }} state=started |
| 179 | |