How can I get logs / runtime details of modules using unoccupied modules?

Let's say I do 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 "Hello World" selected / printed by my script on a remote host (MyTestHost)? Or script return / exit code?

My research shows that one could write a plugin to intercept module execution calls or something on these lines and write a log file. I would rather not waste time on this.

eg. something like stdout below (note that I am running an accessible and not listenable one):

 $ 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" } $ 
+68
logging ansible
Sep 13 '13 at 20:35
source share
6 answers

If you pass the -v flag to a loadable book on the command line, you will see stdout and stderr for each task you are doing:

 $ ansible-playbook -v playbook.yaml 

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

 [defaults] log_path=/path/to/logfile 

Ansible will look in several places for the configuration file:

  • ansible.cfg in the current directory where you ran ansible-playbook
  • ~/.ansible.cfg
  • /etc/ansible/ansible.cfg
+90
Sep 15 '13 at 0:23
source share
β€” -

There is also another way to create a log file.

Before starting ansible-playbook run the following commands to enable logging:

  • Specify a location for the log file.

    export ANSIBLE_LOG_PATH = ~ / ansible.log

  • Enable debugging

    export ANSIBLE_DEBUG = True

  • To check this generated log file.

    less than $ ANSIBLE_LOG_PATH

+5
Mar 29 '18 at 13:09
source share

Using callback plugins, you can output the command output command in readable form using the game: gist: human_log.py

Change, for example, the output:

  _____________________________________ < TASK: common | install apt packages > ------------------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || changed: [10.76.71.167] => (item=htop,vim-tiny,curl,git,unzip,update-motd,ssh-askpass,gcc,python-dev,libxml2,libxml2-dev,libxslt-dev,python-lxml,python-pip) stdout: Reading package lists... Building dependency tree... Reading state information... libxslt1-dev is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded. stderr: start: 2015-03-27 17:12:22.132237 end: 2015-03-27 17:12:22.136859 
+3
Mar 27 '15 at 17:13
source share

Ansible command line ansible-playbook --help such as ansible-playbook --help shows how to increase output detail by setting a more verbose mode (-v) for more granularity (-v vv) or to verbose connection debugging (-v vvv) This should give you some details that you are looking for in stdout that you can log in to.

0
May 16 '18 at 5:23
source share

Official plugins

You can use the output callback plugins . For example, starting with Ansible 2.4, you can use the debug output callback plugin:

 # In ansible.cfg: [defaults] stdout_callback = debug 

(Alternatively, run export ANSIBLE_STDOUT_CALLBACK=debug before starting your game book)

Important: you must run ansible-playbook with -v ( --verbose ) to see the effect. With stdout_callback = debug output should look something like this:

 TASK [Say Hello] ******************************** changed: [192.168.1.2] => { "changed": true, "rc": 0 } STDOUT: Hello! STDERR: Shared connection to 192.168.1.2 closed. 

There are other modules besides the debug module if you want the output to be formatted differently. There are json , yaml , unixy , dense , minimal , etc. ( Complete list ).

For example, with stdout_callback = yaml output would look something like this:

 TASK [Say Hello] ********************************** changed: [192.168.1.2] => changed=true rc: 0 stderr: |- Shared connection to 192.168.1.2 closed. stderr_lines: - Shared connection to 192.168.1.2 closed. stdout: |2- Hello! stdout_lines: <omitted> 

3rd party plugins

If none of the official plugins is satisfactory, you can try the human_log plugin. There are several versions:

0
Jan 29 '19 at 8:12
source share



All Articles