This post will show you how we can view disk space through an ansible-playbook. Here I am using Linux-based identical machines and the Operating system is CentOS. In our playbook, I am going to use the register variable to capture the output and debug module to show the output of the variable.
In the register variable, the keyword we will use is the register, to capture the output. below the playbook, the code shows the structure of the register variable from a task.
the debug module to print the standard output of the task commands.
Next i am providing two playbook only two minor differences . You can use any one which you feel better to use .
Create a playbook inside your project directory and verify every managed host are running and working .
--- - name: Check Disk Space Usage hosts: srv1.example.com tasks: - name: Disk usage from command module command: df -h register: space - debug: var: space
The output of this playbook will consist of the whole output, which is captured in the register variable with stdout and stdout_lines.
The below playbook snippet will show only variable space.stdout_lines, which is automatically arranged in lines but you can also show complete information with stdout.
--- - name: Check Disk Space Usage hosts: srv1.example.com tasks: - name: Disk usage from command module command: df -h register: space - debug: var: space.stdout_lines
I have done the above task through the playbook but we can do this task through ansible ad-hoc command for like temporary purposes through playbook we can do through different modes according to your need.