infrastructure icon indicating copy to clipboard operation
infrastructure copied to clipboard

Add logging to Ansible Playbooks

Open Haroon-Khel opened this issue 2 years ago • 10 comments

A solution inspired by @gdams. Add a role to the playbooks which updates a file on the remote machine indicating that the playbook has run on the remote machine, including a timestamp.

This file should be able to be queried by test tools to determine when the last playbook run happened on the remote machine

Features:

  • [x] Basic log (date and time)
  • [x] Runs even when certain roles are specified with -t
  • [ ] Logs which roles were executed
  • [ ] Runs log even when playbook fails (might require handlers)
  • [x] Logs git hash (or equivalent) of playbook

Haroon-Khel avatar Sep 15 '22 11:09 Haroon-Khel

I think the issue should be called "Use file on ansible target to track after each time playbook run"

zdtsw avatar Sep 15 '22 13:09 zdtsw

Very basic implementation at https://github.com/adoptium/infrastructure/pull/2746. Once merged I will work on adding extra features

Haroon-Khel avatar Sep 15 '22 17:09 Haroon-Khel

I think the issue should be called "Use file on ansible target to track after each time playbook run"

Feel free to change it 👍🏻 I'm terrible with issue titles

Haroon-Khel avatar Sep 15 '22 17:09 Haroon-Khel

Assume this issue should cover non-Linux machine as well? #2746 is only linux part

zdtsw avatar Sep 16 '22 06:09 zdtsw

I am also curious, if we run our playbook via AWX, does not AWX have API which other tools can query when was the last time it runs on any machine and so on?

Because to dump a file onto the machine so other tools to read this file , this requires high permission on that machine, than query AWX

zdtsw avatar Sep 16 '22 08:09 zdtsw

Assume this issue should cover non-Linux machine as well? https://github.com/adoptium/infrastructure/pull/2746 is only linux part

That pr covers mac and solaris aswell. I will add the role to the windows and aix playbooks soon

Haroon-Khel avatar Sep 16 '22 09:09 Haroon-Khel

I am also curious, if we run our playbook via AWX, does not AWX have API which other tools can query when was the last time it runs on any machine and so on?

One can also execute the playbooks from their workstation, so this ensures that in either circumstance a log file will be created

Because to dump a file onto the machine so other tools to read this file , this requires high permission on that machine, than query AWX

The file is currently in the jenkins home directory, which as far as I know, should be accessible to test tools. But we can change this in the future

Haroon-Khel avatar Sep 16 '22 09:09 Haroon-Khel

I am also curious, if we run our playbook via AWX, does not AWX have API which other tools can query when was the last time it runs on any machine and so on?

One can also execute the playbooks from their workstation, so this ensures that in either circumstance a log file will be created

Is the current working process allowing the ones with ssh-key to these machines to run playbook directly from local env.? how could this prevent non-master branch changes get onto such machines? looks like test tools not only need to know when was the last time ansbile was run but also which SHA ansible ran with.

zdtsw avatar Sep 16 '22 10:09 zdtsw

how could this prevent non-master branch changes get onto such machines? looks like test tools not only need to know when was the last time ansbile was run but also which SHA ansible ran with.

That is why the final checkbox on this issue is "Logs git hash (or equivalent) of playbook"

sxa avatar Sep 19 '22 21:09 sxa

@Haroon-Khel How is this different from https://github.com/adoptium/infrastructure/issues/2202?

sxa avatar Sep 19 '22 21:09 sxa

@Haroon-Khel How is this different from #2202?

I'm going to close this. If anyone disagrees feel free to reopen.

sxa avatar Feb 24 '23 13:02 sxa