<p>Ansible is an automation tool, so it can automate things you can do by hands.</p>

<p>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.</p>

<p>So at first, you should create some wrapper script that will execute your actual job and send it's result to elasticsearch.</p>

<p>An then schedule this wrapper script via Ansible.</p>

<p>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.</p>

CC BY-SA 3.0
2018-03-02T05:45:50.190Z
Thanks, before wrapping my script, I will give a try to eric coutu answer creating a callback plugin
xmartinez
CC BY-SA 3.0
2018-03-01T19:06:24.053Z
2018-03-01T19:06:24.053Z
Konstantin Suvorov
<p>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.</p>

<p>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.</p>

<p>Here are the callback plugins bundled with ansible by default: <a href="https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/callback" rel="nofollow noreferrer">https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/callback</a> - 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.</p>

CC BY-SA 3.0
2018-03-02T05:47:26.957Z
Thanks for your response I will try it, it seems that is just what I need!
xmartinez
CC BY-SA 3.0
2018-03-02T06:05:33.760Z
Hmm... Ansible callbacks can log only things that happen during playbook execution. But OPs requirement is to _to log when they start, finish, and if they fail_.
Konstantin Suvorov
CC BY-SA 3.0
2018-03-05T01:30:12.897Z
I was assuming that the cron job itself was an ansible-playbook call. If the OP is using ansible to create a cron job that executes a non-ansible command this would not work.

*However* the OP _could_ convert the non-ansible cron command to be run by an ansible playbook and benefit from callbacks plugins.
Emma
CC BY-SA 3.0
2018-03-01T19:08:06.460Z
2018-03-01T19:08:06.460Z
Emma
<p>I don't think there is anything to do with ansible after you add cron. How about writing log of cron on file or send it by otherway maybe through el and view on kibana? </p>

CC BY-SA 3.0
2018-03-01T18:27:58.393Z
2018-03-01T18:27:58.393Z
Hungry Mind
<p>I have set up some crons in Ansible, and I want to log when they start, finish, and if they fail.</p>

<p>How I could do it?</p>

<p>I don’t know so much about Ansible.</p>

<ansible><elastic>
How to perform logging of Ansible crons in Kibana?
xmartinez
# How to perform logging of Ansible crons in Kibana?

(Asked by: username_0 on 2018-03-01)

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.

**Tags:** ansible, elastic


---

## 3 answers

### Answer by username_1 on 2018-03-01. Score: 1 | Accepted answer

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.

> **Comments:**
> **username_0**: Thanks, before wrapping my script, I will give a try to eric coutu answer creating a callback plugin  

---

### Answer by username_2 on 2018-03-01. Score: 0

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.

> **Comments:**
> **username_0**: Thanks for your response I will try it, it seems that is just what I need!  
> **username_1**: Hmm... Ansible callbacks can log only things that happen during playbook execution. But OPs requirement is to _to log when they start, finish, and if they fail_.  
> **username_2**: I was assuming that the cron job itself was an ansible-playbook call. If the OP is using ansible to create a cron job that executes a non-ansible command this would not work.  *However* the OP _could_ convert the non-ansible cron command to be run by an ansible playbook and benefit from callbacks plugins.  

---

### Answer by username_3 on 2018-03-01. Score: 0

I don't think there is anything to do with ansible after you add cron. How about writing log of cron on file or send it by otherway maybe through el and view on kibana?


---

