Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in Ansible, How can I set log file name dynamilcally

Tags:

ansible

I'm currently developing ansible script to build and deploy java project.

so, I can set the log_path like below

log_path=/var/log/ansible.log

but, It is hard to look up build history. Is it possible to append datetime to log file name?

for example,

ansible.20150326145515.log

like image 935
Ickhyun Kwon Avatar asked Mar 26 '15 05:03

Ickhyun Kwon


People also ask

How do you call an Ansible VARs file?

The include_vars module can be used in a playbook or role to load variables from a file. Simply set the value of include_vars to a local file to load the variables it contains: --- # ./hello_world. yml - name: print greeting hosts: "*" tasks: - include_vars: name_vars.


2 Answers

I don't believe there is a built-in way to generate the date on the fly like that but one option you have is to use a lookup which can shell out to date. Example:

log_path="/var/log/ansible.{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}.log"
like image 94
jarv Avatar answered Sep 22 '22 02:09

jarv


Here is an option using ANSIBLE_LOG_PATH environment variable thanks to Bash shell alias:

alias ansible="ANSIBLE_LOG_PATH=ansible-\`date +%Y%m%d%H%M%S\`.log ansible"

Feel free to use an absolute path if you prefer.

like image 35
Yves Martin Avatar answered Sep 20 '22 02:09

Yves Martin