I'm trying to figure out if there's way of adding a timestamp to a template file in Ansible so that everytime I run an Ansible playbook which uses a certain template, it adds in the destination file the time of the execution of the playbook.
For example, I'm templating a configuration file with Ansible and I want it on the destination machine to appear with a timestamp on the first line...
e.g.
cat something.conf_template
some config lines
After templating:
- template: src=/mytemplates/something.conf_template dest=/etc/something.conf owner=smth group=smth mode=0644
the contents should be
cat something.conf
#in this comment is the timestamp, format irrelevant
some config lines
Do you know any ansible module that can do this?
You can simply add # {{ ansible_managed }}
to the top of your template. This variable is defined in your configuration file to have a default of:
Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
Note that since this contains a timestamp by default it means that every time your template task is invoked it will update the destination file with the current timestamp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With