I would like to post to this group to find out if there is anyway for ansible to actually stamp the client with
Ansible Deployment or Deployment Stamp on what tasks were ran and when it was ran, like a VERSION or DEPLOYMENT file that we could deposit to the targets.
For example,
On first deployment the ansible scripts may just have tasks like:
APT UPDATE
NTPDATE
this then was deployment and stamps on the client like this:
Ansible Deployment 21/07/2020 13.35pm - v1.0
Tasks:
APT UPDATE 21/072020 13;40pm
NTPDATE 21/072020 13.42pm
Then this ansible script was updated to contain 2 more tasks like the below:
APT UPDATE
TIMESYNC DAEMON UPDATE
NTPDATE
PROXY UPDATE
And when this was ran again, the target system file gets updated once it completes with:
Something like this, this allows those who are maintaining individual platforms gets to know if the deployed platform is upto date or not.
This would also help to know if the target system is to the latest deployment or not.
Or is there any mechanism for this ?
At the beginning of your playbook you test is the fact relating to your playbook exist.
If existing, is the version different from the playbook you use
Do things differently if the version is x or y
Generally, this could be avoided using some automated test to not make regression in a future version (molecule could be useful here if target is a server)
This is a great insight you have provided. That would certainly a good way on how to manipulate the Ansible and Ansible Tasks on each runs.
What what it doesn’t solve is that how do i populate that fact file with Tasks that has already been ran.
For example, at the end of each Ansible run, if i could generate a JSON file that would look like:
{
“Task1”:1,
“Task2”:1
}
And on Ansible, I can write “When: {{ ansible_local[“Task1”] }} exists and {{ ansible_local[“Task1”] }} == 1”
then skip the task. This is ideal.
However, to generate the fact.d JSON file, i need a way for to know what tasks have been executed in the first place,
and thats something i am figuring out, how can i know within this ansible run, what were the tasks executed ?
I gave you some ideas, I did’nt say this is a good practice to know what tasks has been already ran.
When you produce ansible role and playbook, you should ensure that you can run it whenever previous state was and if run more than once without modification results on server should be the same !
This is a great insight you have provided. That would certainly a good way on how to manipulate the Ansible and Ansible
Tasks on each runs.
What what it doesn't solve is that how do i populate that fact file with Tasks that has already been ran.
For example, at the end of each Ansible run, if i could generate a JSON file that would look like:
{
"Task1":1,
"Task2":1
}
And on Ansible, I can write "When: {{ ansible_local["Task1"] }} exists and {{ ansible_local["Task1"] }} == 1"
then skip the task. This is ideal.
However, to generate the fact.d JSON file, i need a way for to know what tasks have been executed in the first place,
and thats something i am figuring out, how can i know within this ansible run, what were the tasks executed ?
As Jean-Yves points out, you are starting to negate the whole point of Ansibles idempotency. You write something once and no matter how many times you run it, it checks and only makes changes as necessary. Writing a timestamp to every file on every remote host is not a good practice.
So you want to log what’s going on? As Stefan points out look at something like ARA or better still look at AWX was you’ll probably quickly get to the point of needing other features which AWX has taken care of.