how to capture varnishlogs run time after curl req is sent
A
- i tired this way
-
name: varnishlog in T1
hosts: host1
become: yes
tasks:
- name: varnishlog
shell: varnishlog
async: 120
poll: 0
register: varnishlog_output
-
name: curl req in T2
hosts: host2
become: no
tasks:
-
name: Check if varnishlog is complete
async_status:
jid: “{{ varnishlog_output.ansible_job_id }}”
register: job_result
until: job_result.finished
delay: 10
retries: 3
still unable to get varnishlog run time
---
- name: Capture Varnish logs after curl request
hosts: host1 # Assuming host1 is where Varnish is running
become: yes # Assuming you need root or sudo to run varnishlog
tasks:
- name: Start varnishlog in background
shell: >
varnishlog > /tmp/varnishlog_{{ ansible_date_time.epoch }}.log &
echo $! > /tmp/varnishlog_pid_{{ ansible_date_time.epoch }}.pid
args:
executable: /bin/bash
register: varnishlog_start
- name: Wait for varnishlog to start
wait_for:
path: /tmp/varnishlog_{{ ansible_date_time.epoch }}.log
delegate_to: localhost
- name: Send curl request
shell: >
curl -vso /dev/null "http://54.144.19.76/index.html"
delegate_to: host2 # Assuming host2 is where you send the request from
become: no
- name: Wait for a moment to ensure logs are captured
pause:
seconds: 5 # Adjust based on how long it takes for logs to appear
- name: Stop varnishlog
shell: >
kill $(cat /tmp/varnishlog_pid_{{ ansible_date_time.epoch }}.pid) &&
rm -f /tmp/varnishlog_pid_{{ ansible_date_time.epoch }}.pid
- name: Fetch varnishlog output
fetch:
src: "/tmp/varnishlog_{{ ansible_date_time.epoch }}.log"
dest: "./varnish_logs/"
flat: yes
register: fetch_output
- name: Clean up temporary log file
file:
path: "/tmp/varnishlog_{{ ansible_date_time.epoch }}.log"
state: absent
- name: Display fetched log
debug:
msg: "{{ lookup('file', './varnish_logs/' + fetch_output.md5) }}"