I have set up some crons in Ansible, and I want to log when they start, finish, and if they fail.
How I could do it?
I don’t know so much about Ansible.
DevOps Stack Exchange is a question and answer site for software engineers working on automated testing, continuous delivery, service integration and monitoring, and building SDLC infrastructure. It only takes a minute to sign up.Sign up to join this community
Ansible is an automation tool, so it can automate things you can do by hands.
But as far as I know no existing cron-like services support sending logs to elasticsearch (Kibana is just a viewer, btw) out of the box.
So at first, you should create some wrapper script that will execute your actual job and send it's result to elasticsearch.
An then schedule this wrapper script via Ansible.
Or choose another route, setup syslog forwarding to logstash/elasticsearch on your target box to collect all logs, then just filter your desired cron jobs.
I would suggest checking out ansible callback plugins - they are python modules that implement callback functions that ansible will call during playbook execution. In fact, the messages ansible-playbook logs to your terminal is actually implemented as a callback plugin.
I have written callback plugins for logging to elasticsearch, influxdb, redis - they are quite powerful for hooking the results of your ansible runs up to other tools. Unfortunately I can not share them here as they were implemented during my day job.
Here are the callback plugins bundled with ansible by default: https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/callback - it's possible you may be able to use one of them to send results to logstash, which would feed them into Elasticsearch for viewing with Kibana.