Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get logs/details of ansible-playbook module executions?

Say I execute the following.

$ cat test.sh #!/bin/bash echo Hello World exit 0  $ cat Hello.yml ---  - hosts: MyTestHost   tasks:   - name: Hello yourself     script: test.sh   $ ansible-playbook  Hello.yml  PLAY [MyTestHost] ****************************************************************  GATHERING FACTS *************************************************************** ok: [MyTestHost]  TASK: [Hello yourself] ******************************************************** ok: [MyTestHost]  PLAY RECAP ******************************************************************** MyTestHost                    : ok=2    changed=0    unreachable=0    failed=0  $ 

I know for sure that it was successful.

Where/how do I see the "Hello World" echo'ed/printed by my script on the remote host (MyTestHost)? Or the return/exit code of script?

My research shows me it would be possible to write a plugin to intercept module execution callbacks or something on those lines and write a log file. I would prefer to not waste my time with that.

E.g. something like the stdout in below (note that I'm running ansible and not ansible-playbook):

$ ansible plabb54 -i /project/plab/svn/plab-maintenance/ansible/plab_hosts.txt -m script -a ./test.sh plabb54 | success >> {     "rc": 0,     "stderr": "",     "stdout": "Hello World\n" }  $ 
like image 953
Kashyap Avatar asked Sep 13 '13 20:09

Kashyap


People also ask

Where can I see Ansible logs?

ansible. cfg (in the home directory) /etc/ansible/ansible. cfg.

How do you debug an Ansible playbook?

You can enable the task debugger globally with a setting in ansible. cfg or with an environment variable. The only options are True or False . If you set the configuration option or environment variable to True , Ansible runs the debugger on failed tasks by default.


1 Answers

If you pass the -v flag to ansible-playbook on the command line, you'll see the stdout and stderr for each task executed:

$ ansible-playbook -v playbook.yaml 

Ansible also has built-in support for logging. Add the following lines to your ansible configuration file:

[defaults]  log_path=/path/to/logfile 

Ansible will look in several places for the config file:

  • ansible.cfg in the current directory where you ran ansible-playbook
  • ~/.ansible.cfg
  • /etc/ansible/ansible.cfg
like image 168
Lorin Hochstein Avatar answered Oct 06 '22 08:10

Lorin Hochstein