Ankit Kulkarni
Ankit Kulkarni

Reputation: 1345

Access ansible playbook results after run of playbook

I am running an ansible script using ansible-pull on a remote machine(client side) which I can't see .

I want to make sure that :

Enabling ansible logs store information in some log file but was wondering if I can get the results of below ansible output via some variables predefined in ansible.

PLAY [localhost] ************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [localhost]

TASK: [Install the hello package] ********************************************* 
ok: [localhost] => {"changed": false}

TASK: [Install the cmatrix package] ******************************************* 
ok: [localhost] => {"changed": false}

PLAY RECAP ******************************************************************** 
localhost                  : ok=3    changed=0    unreachable=0    failed=0  

If not then I will have to write the custom scripts to parse the logs , save information in some db on machine and send it back to our servers .

Upvotes: 5

Views: 9533

Answers (1)

udondan
udondan

Reputation: 60079

AFAIK there is no variable where you could just get this data from.

But this screams for a Callback plugins. Have a look at the plugin community.general/plugins/callback/log_plays.py. It writes its own logfile. You could intercept all the messages, collect them and at the end (define a method def playbook_on_stats(self, stats): in your plugin) do with it whatever you want. There also is the community.general/plugins/callback/mail.py which will send emails on failed tasks.

Upvotes: 7

Related Questions