cancel
Showing results for 
Search instead for 
Did you mean: 
spurs
Flight Engineer
Flight Engineer
  • 3,444 Views

register variable debug

Jump to solution

Hello, I thought to call the register variable (debug msg:) is {{ varaible.stdout }}

but I saw the script

- name: checksum verification

  stat:

    path: /path/to/file

    checksum_algorithm: md5

  register: result

- debug

    msg: "checksum is {{ result.stat.checksum }}"

 

In this case, why .stat.checksum is used? I'm a bit worried if I need to memorize whole thing what should type after register variable name as I thought only .stdout was the answer.

Labels (1)
3 Solutions

Accepted Solutions
andkra
Flight Engineer Flight Engineer
Flight Engineer
  • 3,421 Views

Have a look inside the doc from the ansible.builtin.stat module. Scroll to the topic Return values. There you have all returned values, usable with the registered variable result.

Also for learning, it is a good idea to print the whole registered variable out.

- name: Print the value of the variable result
  ansible.builtin.debug:
    var: result

The variable.stdout exists eg. if you use the command module.

View solution in original post

Chetan_Tiwary_
Community Manager
Community Manager
  • 3,403 Views

Hello @spurs !
Refer https://docs.ansible.com/ansible/2.9/modules/stat_module.html?highlight=stat 

Here you want to print the information of the checksum value registered in the variable name, hence var.stat.checksum was used. 

You can try this to get the detailed stats :

Chetan_Tiwary__2-1703776304478.png

and then use the details to filter out the stat.xxx  output :

Chetan_Tiwary__1-1703776267918.png

View solution in original post

0 Kudos
Chetan_Tiwary_
Community Manager
Community Manager
  • 3,182 Views

@spurs See here :

Chetan_Tiwary__0-1704098069002.png

I recommend to use theFQCN ( same as the doc ).

View solution in original post

0 Kudos
7 Replies
andkra
Flight Engineer Flight Engineer
Flight Engineer
  • 3,422 Views

Have a look inside the doc from the ansible.builtin.stat module. Scroll to the topic Return values. There you have all returned values, usable with the registered variable result.

Also for learning, it is a good idea to print the whole registered variable out.

- name: Print the value of the variable result
  ansible.builtin.debug:
    var: result

The variable.stdout exists eg. if you use the command module.

spurs
Flight Engineer
Flight Engineer
  • 3,276 Views

Cool, thanks! .stdout is for the command module! 

Good to know

Chetan_Tiwary_
Community Manager
Community Manager
  • 3,404 Views

Hello @spurs !
Refer https://docs.ansible.com/ansible/2.9/modules/stat_module.html?highlight=stat 

Here you want to print the information of the checksum value registered in the variable name, hence var.stat.checksum was used. 

You can try this to get the detailed stats :

Chetan_Tiwary__2-1703776304478.png

and then use the details to filter out the stat.xxx  output :

Chetan_Tiwary__1-1703776267918.png

0 Kudos
spurs
Flight Engineer
Flight Engineer
  • 3,276 Views

Thanks for the reply!

I'm terribly sorry but I don't see the checksum under the stat module on your screenshot. 

I saw on the doc link tho

 

***

I noticed that you used the full module name (not sure if it is correct term), ansible.builtin.stat instead of just 'stat:'.

Do you recommend to use full module name?

Chetan_Tiwary_
Community Manager
Community Manager
  • 3,183 Views

@spurs See here :

Chetan_Tiwary__0-1704098069002.png

I recommend to use theFQCN ( same as the doc ).

0 Kudos
spurs
Flight Engineer
Flight Engineer
  • 3,270 Views

+++++

so basically

if the register variable is 'result'

I can use

debug:

  msg: "the result is {{ result.stat.checksum }}"

or

debug:

  var: result

 

two different ways, is it correct?

 

one more here!

stat:

  path: /etc/motd

register: motd

then can I use 

debug:

  msg: "the result is {{ motd.stat }}"

 

on the book, it said

debug: 

  var: motd

Chetan_Tiwary_
Community Manager
Community Manager
  • 3,171 Views

@spurs Yes for the first part of your message :

debug: msg: "the result is {{ result.stat.checksum }}" will print a specific custmozied message of the checksum attribute from the list of  stat attributes.

whereas, debug: var: result  is used when you want to examine the entire structure of a variable or if you are unsure of the exact attribute names or values within a variable.

Chetan_Tiwary__0-1704107770330.png

 

 

 

 

for your second part , see the example :

debug the variable : motd 

Chetan_Tiwary__1-1704108113356.png

if you print the message as the string for the whole stat - then it will be like this :

Chetan_Tiwary__2-1704108169158.png

use the debug: msg to print a customized message of a stat attribute like checksum :

Chetan_Tiwary__3-1704108232257.png

in the course book , debug: var might be used in context for checking the entire structure or the content of the variable ( need to check where and why it is used in the book ).

Join the discussion
You must log in to join this conversation.