Scott Baker | 171d35e | 2016-06-20 17:36:29 -0700 | [diff] [blame] | 1 | --- |
| 2 | - hosts: {{ instance_name }} |
| 3 | #gather_facts: False |
| 4 | connection: ssh |
| 5 | user: ubuntu |
| 6 | sudo: yes |
| 7 | vars: |
| 8 | container_name: {{ container_name }} |
| 9 | wan_container_ip: {{ wan_container_ip }} |
| 10 | wan_container_netbits: {{ wan_container_netbits }} |
| 11 | wan_container_mac: {{ wan_container_mac }} |
| 12 | wan_container_gateway_ip: {{ wan_container_gateway_ip }} |
| 13 | wan_vm_ip: {{ wan_vm_ip }} |
| 14 | wan_vm_mac: {{ wan_vm_mac }} |
| 15 | |
| 16 | scope: {{ scope }} |
| 17 | test: {{ test }} |
| 18 | argument: {{ argument }} |
| 19 | result_fn: {{ result_fn }} |
| 20 | resultcode_fn: {{ resultcode_fn }} |
| 21 | |
| 22 | |
| 23 | tasks: |
| 24 | - name: Remove any old result file |
| 25 | shell: rm -f /tmp/{{ result_fn }} |
| 26 | |
| 27 | - name: Copy run_tcpdump.sh to VM |
| 28 | copy: src=/opt/xos/synchronizers/vtr/files/run_tcpdump.sh dest=/root/run_tcpdump.sh mode=0755 |
| 29 | when: (test=="tcpdump") |
| 30 | |
| 31 | |
| 32 | # ----------------- |
| 33 | # scope == VM |
| 34 | # ----------------- |
| 35 | |
| 36 | - name: Send the pings from VM |
| 37 | shell: ping -c 10 {{ argument }} 2>&1 > /tmp/{{ result_fn }} |
| 38 | ignore_errors: yes |
| 39 | register: vm_ping_result |
| 40 | when: (scope=="vm") and (test=="ping") |
| 41 | |
| 42 | - name: Store VM ping resultcode to file |
| 43 | shell: echo "{{ '{{' }} vm_ping_result.rc {{ '}}' }}" > /tmp/{{ resultcode_fn }} |
| 44 | when: (scope=="vm") and (test=="ping") |
| 45 | |
| 46 | - name: Install traceroute |
| 47 | apt: name=traceroute state=present |
| 48 | when: (scope=="vm") and (test=="traceroute") |
| 49 | |
| 50 | - name: Send traceroute from VM |
| 51 | shell: traceroute {{ argument }} 2>&1 > /tmp/{{ result_fn }} |
| 52 | ignore_errors: yes |
| 53 | register: vm_traceroute_result |
| 54 | when: (scope=="vm") and (test=="traceroute") |
| 55 | |
| 56 | - name: Store VM traceroute resultcode to file |
| 57 | shell: echo "{{ '{{' }} vm_traceroute_result.rc {{ '}}' }}" > /tmp/{{ resultcode_fn }} |
| 58 | when: (scope=="vm") and (test=="traceroute") |
| 59 | |
| 60 | - name: Run tcpdump for 30 seconds on VM |
| 61 | shell: /root/run_tcpdump.sh {{ argument }} 2>&1 > /tmp/{{ result_fn }} |
| 62 | ignore_errors: yes |
| 63 | register: vm_tcpdump_result |
| 64 | when: (scope=="vm") and (test=="tcpdump") |
| 65 | |
| 66 | - name: Store VM tcpdump resultcode to file |
| 67 | shell: echo "{{ '{{' }} vm_tcpdump_result.rc {{ '}}' }}" > /tmp/{{ resultcode_fn }} |
| 68 | when: (scope=="vm") and (test=="tcpdump") |
| 69 | |
| 70 | # ------------------ |
| 71 | # scope == container |
| 72 | # ------------------ |
| 73 | |
| 74 | - name: Send the pings from Container |
| 75 | shell: docker exec {{ container_name }} ping -c 10 {{ argument }} 2>&1 > /tmp/{{ result_fn }} |
| 76 | ignore_errors: yes |
| 77 | register: ctr_ping_result |
| 78 | when: (scope=="container") and (test=="ping") |
| 79 | |
| 80 | - name: Store ctr ping resultcode to file |
| 81 | shell: echo "{{ '{{' }} ctr_ping_result.rc {{ '}}' }}" > /tmp/{{ resultcode_fn }} |
| 82 | when: (scope=="container") and (test=="ping") |
| 83 | |
| 84 | - name: Install traceroute into Container |
| 85 | shell: docker exec {{ container_name }} apt-get -y install traceroute |
| 86 | when: (scope=="container") and (test=="traceroute") |
| 87 | |
| 88 | - name: Send traceroute from Container |
| 89 | shell: docker exec {{ container_name }} traceroute {{ argument }} 2>&1 > /tmp/{{ result_fn }} |
| 90 | ignore_errors: yes |
| 91 | register: ctr_traceroute_result |
| 92 | when: (scope=="container") and (test=="traceroute") |
| 93 | |
| 94 | - name: Store ctr traceroute resultcode to file |
| 95 | shell: echo "{{ '{{' }} ctr_traceroute_result.rc {{ '}}' }}" > /tmp/{{ resultcode_fn }} |
| 96 | when: (scope=="container") and (test=="traceroute") |
| 97 | |
| 98 | - name: Copy run_tcpdump.sh to container |
| 99 | command: docker cp /root/run_tcpdump.sh {{ container_name }}:/root/run_tcpdump.sh |
| 100 | when: (scope=="container") and (test=="tcpdump") |
| 101 | |
| 102 | - name: Run tcpdump for 30 seconds from Container |
| 103 | shell: docker exec {{ container_name }} /root/run_tcpdump.sh {{ argument }} 2>&1 > /tmp/{{ result_fn }} |
| 104 | ignore_errors: yes |
| 105 | register: diagresult |
| 106 | when: (scope=="container") and (test=="tcpdump") |
| 107 | |
| 108 | - name: Store ctr tcpdump resultcode to file |
| 109 | shell: echo "{{ '{{' }} ctr_tcpdump_result.rc {{ '}}' }}" > /tmp/{{ resultcode_fn }} |
| 110 | when: (scope=="container") and (test=="tcpdump") |
| 111 | |
| 112 | # ------------------ |
| 113 | # scope == * |
| 114 | # ------------------ |
| 115 | - name: Fetch the result |
| 116 | fetch: src=/tmp/{{ result_fn }} dest=/opt/xos/synchronizers/vtr/result/{{ result_fn }} flat=yes |
| 117 | |
| 118 | - name: Fetch the resultcode |
| 119 | fetch: src=/tmp/{{ resultcode_fn }} dest=/opt/xos/synchronizers/vtr/result/{{ resultcode_fn }} flat=yes |
| 120 | |
| 121 | |
| 122 | |
| 123 | |