
Display the registered output using debug module. The playbook ran “df -h /boot” command and register the output to variable “dfroot”.ģ. Gpfslinapp1 : ok=2 changed=1 unreachable=0 playbooks]$ playbooks]$ ansible-playbook -i lin-servers df.boot.yaml Ensure that “gpfslinapp1” host in the inventory file “lin-servers”. Use “register” to store the output to a variable. Create the playbook to execute the “df” command to check the /boot usage. In this article, we will walk through to capture the output in a variable and display it.ġ. In some cases, you might require to store configuration backup of the hosts. The output would help to generate the required reports. In some cases, you might need to capture the complex command output as results. Just change the value of test1 variable from Hello Vivek to say Hello World and see the output.Ansible playbooks/roles often used to complete the specific task which does not require an output. when can be used with a logical OR and logical AND condition as in all the programming languages. In this case, Equals will be printed as the test1 variable is equal as mentioned in the when condition. ConditionalsĬonditionals are used where one needs to run a specific step based on a condition. Writing the specific instruction in blocks helps to segregate functionality and handle it with exception handling if needed.Įxample of blocks is covered in variable usage,exception handling and loops above. The smallest piece of steps to execute is written in block. The playbook in totality is broken into blocks. "Install Tomcat artifacts task ended with message: ' Yum name = "demo-tomcat-1" state = present The following code is from one of the roles (install-tomcat) − Now taking a reference from the example shared. In the above example, we have defined a variable name tomcat_port and assigned the value 8080 to that variable and can use that in your playbook wherever needed. One can put conditions around the value of the variables and accordingly use them in the playbook. It helps you to use and assign a value to a variable and use that anywhere in the playbook. Variable in playbooks are very similar to using variables in any programming language.
