Question:I am using
ansible_date_time.epochto calculate days since a server was built. I get the build date information from a csv file and trying to do a calculation, but I am getting an error.
Answer:In order to do computation on date, you need both elements to be
In your task, you are trying to subtract a
string, from your CSV, to an epoch, which is of type
So you need:
- The current date, in a
datetimeformat, which can be achieved with
'%Y-%m-%d %H:%M:%S' | strftime | to_datetime
- The date from your CSV converted in a
datetime, which can be achieved with
lookup( 'csvfile', inventory_hostname, file='serverInventory.csv', delimiter=',', col=5 ) | to_datetime
- Then only you can subtract the two of them
So, we end up with a task like:
If you have better answer, please add a comment about this, thank you!