- 1 year ago
How to get the remaining size on C: with ansible?
To get the remaining size on the C: drive using Ansible, you can utilize the ansible.windows.win_disk_facts
module. Here's an example playbook that retrieves disk facts and prints the remaining size of the C: drive:
yaml---
- name: Get disk facts
hosts: windows_host
gather_facts: no
tasks:
- name: Retrieve disk facts
ansible.windows.win_disk_facts:
include_partitions: yes
- name: Print remaining size of C: drive
debug:
msg: "Remaining size on C: drive: {{ ansible_facts['ansible_mounts'] | selectattr('mount','equalto','C:') | map(attribute='size_available') | first }}"
Make sure to replace windows_host
with the hostname or IP address of your target Windows machine.
This playbook uses the win_disk_facts
module to gather disk information. The include_partitions
option is set to yes
to include detailed partition information.
The debug
task then prints the remaining size on the C: drive using the ansible_facts
variable. It filters the ansible_mounts
list to select the mount with the path 'C:' and retrieves the size_available
attribute.
Run the playbook using the ansible-playbook
command:
ansible-playbook disk_space.yml
The playbook will retrieve the disk facts and print the remaining size on the C: drive of the target Windows machine.