Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :

  • ansible playbook are executed successfully then should send summary
  • ansible playbook if not executed successfully should send summary of what failed

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 .

like image 972
Ankit Kulkarni Avatar asked Nov 19 '15 08:11

Ankit Kulkarni


People also ask

Where the Ansible playbook output is stored?

You can also see the output is stored in a folder called show-output and the file name is the hostname of the device as it appears in the inventory file. Running the playbook is as easy as running any other Ansible Playbook – ansible-playbook show-commands.

Can Ansible playbook return value?

Ansible modules normally return a data structure that can be registered into a variable, or seen directly when output by the ansible program. Each module can optionally document its own unique return values (visible through ansible-doc and on the main docsite).


1 Answers

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

But this screams for a callback plugin. Have a look at the plugin log_plays. 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 mail plugin which will send emails on failed tasks.

like image 53
udondan Avatar answered Sep 27 '22 00:09

udondan