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.
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.
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 :
and then use the details to filter out the stat.xxx output :
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.
Cool, thanks! .stdout is for the command module!
Good to know
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 :
and then use the details to filter out the stat.xxx output :
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?
+++++
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
@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.
for your second part , see the example :
debug the variable : motd
if you print the message as the string for the whole stat - then it will be like this :
use the debug: msg to print a customized message of a stat attribute like checksum :
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 ).
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.