Skip to content

Instantly share code, notes, and snippets.

@NerrickT
Forked from btotr/ansible tcpdump
Created February 7, 2018 04:06
Show Gist options
  • Save NerrickT/dc9f9531d77d4109f78772147f860a7b to your computer and use it in GitHub Desktop.
Save NerrickT/dc9f9531d77d4109f78772147f860a7b to your computer and use it in GitHub Desktop.
# ansible-playbook -i inventory tcpdump.yml --extra-vars "target=stitchers"
- hosts: '{{ target }}'
become: yes
become_method: sudo
vars:
cap_file: packet_capture_{{ ansible_hostname }}_{{ ansible_date_time['epoch'] }}.cap
tasks:
- name: start tcpdump
command: /usr/sbin/tcpdump -i any -s 0 -w /tmp/{{ cap_file }}
async: 60
poll: 0
- pause: minutes=1 prompt="pause for 60 seconds or press Ctrl + c then c to continue"
- name: kill tcpdump
command: /usr/bin/pkill tcpdump
- name: compress capture file
command: gzip {{ cap_file }} chdir=/tmp
- name: copy logs to local boxes webroot
fetch: src=/tmp/{{ cap_file }}.gz dest=/tmp/ flat=yes
- name: remove files from server
file: path=/tmp/{{ cap_file }}.gz state=absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment