Ansible Register Variable-Ansible Register Module Examples

Ansible Register Module With Examples

Ansible register variable or ansible register module is used to capture or store the output of the command or task. By using the register module, you can store that output into any variable.

In the following example, I will show you how to find the status of httpd. I will start the httpd and I will see the status and I will store the status into a variable called httpd_status by using ansible register module. With below playbook, you can check whether httpd started with errors or without errors. The use of register module is you can verify your task is executed or not by checking task output in the log.

ansible register module with an example:

Here httpd_status is the variable so the output of the command “service httpd status” will be stored into variable httpd_status. So by using the register module, you can store the output of the task. To print that output we use debug module.


Whenever you executed any task or commands ansible will give you some return values like.

  • changed
  • cmd
  • delta
  • end
  • failed
  • rc
  • start
  • stderr
  • stderr_lines
  • stdout
  • stdout_lines

These return values depend on the task you executed if you want to know more about ansible return value you can check here.

  • ansible return values or ansible return codes

In the above return values our output will be stored in stdout, So to print exact output without any extra return values we can use like variablename.stdout or you can use stdout_lines. Stdout_lines will split the output into line by line.

playbook with stdout_lines:

output with stdout_lines:

Here you can see we got only stdout_lines return code output, Depends on our requirement we can mention any return value. But if you want the only output of the command we will mention variblename.stdout  or variblename.stdout_lines.


  • ansible register variable
  • ansible register example
  • register varible ansible
  • ansible register module with example
  • register variable ansible
  • ansible register variable example


Do You Want To Become An Expert in Devops?
                                    Subscribe To DecodingDevops
                                Get New Posts To your mail Inbox

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Decoding DevOps will use the information you provide on this form to be in touch with you and to provide updates and marketing.