{"id":300,"date":"2022-01-21T19:11:18","date_gmt":"2022-01-21T19:11:18","guid":{"rendered":"https:\/\/www.edrockwell.com\/blog\/?p=300"},"modified":"2026-07-02T16:57:33","modified_gmt":"2026-07-02T16:57:33","slug":"ansible-how-to-get-the-size-of-a-directory-from-a-linux-server","status":"publish","type":"post","link":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/","title":{"rendered":"Ansible | How to get the size of a directory from a linux server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To get the filesystem size, used, available, % used, and what it&#8217;s mounted on run this simple ansible script to pull the data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It uses the df -h command of \/var\/log. You can modify it for any other directory you like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n- name: get the size of \r\n  hosts: all\r\n  tasks:\n    - name: get disk space using df -h \/var\/log\r\n      command: df -h \/var\/log\r\n      register: var_log_space_raw\r\n    - set_fact:\r\n        folder_size:\r\n        #  \"{{ var_log_space_raw.stdout.split()&#91;8,11]}}\"\r\n          \"{{ var_log_space_raw.stdout_lines}}\"\r\n        register: folder_size\r\n    - debug:\r\n        msg: \"{{ folder_size }}\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The remarked out line gives the fields for Size and Used%<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get the filesystem size, used, available, % used, and what it&#8217;s mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like The remarked out line gives the fields for Size and Used%<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"To get the filesystem size, used, available, % used, and what it&#039;s mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Ed Rockwell\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"System Admin [RESOLVED] | How To: Make My DevOps Life Easier\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]\" \/>\n\t\t<meta property=\"og:description\" content=\"To get the filesystem size, used, available, % used, and what it&#039;s mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-01-21T19:11:18+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-02T16:57:33+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]\" \/>\n\t\t<meta name=\"twitter:description\" content=\"To get the filesystem size, used, available, % used, and what it&#039;s mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#article\",\"name\":\"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]\",\"headline\":\"Ansible | How to get the size of a directory from a linux server\",\"author\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/#organization\"},\"datePublished\":\"2022-01-21T19:11:18+00:00\",\"dateModified\":\"2026-07-02T16:57:33+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#webpage\"},\"articleSection\":\"Uncategorized\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"name\":\"Uncategorized\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"position\":2,\"name\":\"Uncategorized\",\"item\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/category\\\/uncategorized\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#listItem\",\"name\":\"Ansible | How to get the size of a directory from a linux server\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#listItem\",\"position\":3,\"name\":\"Ansible | How to get the size of a directory from a linux server\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"name\":\"Uncategorized\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/#organization\",\"name\":\"System Admin [RESOLVED]\",\"description\":\"How To: Make My DevOps Life Easier\",\"url\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Ed Rockwell\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dea3152d7acd78aa28d280207c33f7ec516731ece9a54249cbbbebcfffc341e0?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Ed Rockwell\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#webpage\",\"url\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/\",\"name\":\"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]\",\"description\":\"To get the filesystem size, used, available, % used, and what it's mounted on run this simple ansible script to pull the data. It uses the df -h command of \\\/var\\\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2022-01-21T19:11:18+00:00\",\"dateModified\":\"2026-07-02T16:57:33+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/\",\"name\":\"System Admin [RESOLVED]\",\"description\":\"How To: Make My DevOps Life Easier\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.edrockwell.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]","description":"To get the filesystem size, used, available, % used, and what it's mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk","canonical_url":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#article","name":"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]","headline":"Ansible | How to get the size of a directory from a linux server","author":{"@id":"https:\/\/www.edrockwell.com\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/www.edrockwell.com\/blog\/#organization"},"datePublished":"2022-01-21T19:11:18+00:00","dateModified":"2026-07-02T16:57:33+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#webpage"},"isPartOf":{"@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#webpage"},"articleSection":"Uncategorized"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.edrockwell.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.edrockwell.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.edrockwell.com\/blog\/category\/uncategorized\/#listItem","name":"Uncategorized"}},{"@type":"ListItem","@id":"https:\/\/www.edrockwell.com\/blog\/category\/uncategorized\/#listItem","position":2,"name":"Uncategorized","item":"https:\/\/www.edrockwell.com\/blog\/category\/uncategorized\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#listItem","name":"Ansible | How to get the size of a directory from a linux server"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.edrockwell.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#listItem","position":3,"name":"Ansible | How to get the size of a directory from a linux server","previousItem":{"@type":"ListItem","@id":"https:\/\/www.edrockwell.com\/blog\/category\/uncategorized\/#listItem","name":"Uncategorized"}}]},{"@type":"Organization","@id":"https:\/\/www.edrockwell.com\/blog\/#organization","name":"System Admin [RESOLVED]","description":"How To: Make My DevOps Life Easier","url":"https:\/\/www.edrockwell.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.edrockwell.com\/blog\/author\/admin\/#author","url":"https:\/\/www.edrockwell.com\/blog\/author\/admin\/","name":"Ed Rockwell","image":{"@type":"ImageObject","@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/dea3152d7acd78aa28d280207c33f7ec516731ece9a54249cbbbebcfffc341e0?s=96&d=mm&r=g","width":96,"height":96,"caption":"Ed Rockwell"}},{"@type":"WebPage","@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#webpage","url":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/","name":"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]","description":"To get the filesystem size, used, available, % used, and what it's mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.edrockwell.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/#breadcrumblist"},"author":{"@id":"https:\/\/www.edrockwell.com\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/www.edrockwell.com\/blog\/author\/admin\/#author"},"datePublished":"2022-01-21T19:11:18+00:00","dateModified":"2026-07-02T16:57:33+00:00"},{"@type":"WebSite","@id":"https:\/\/www.edrockwell.com\/blog\/#website","url":"https:\/\/www.edrockwell.com\/blog\/","name":"System Admin [RESOLVED]","description":"How To: Make My DevOps Life Easier","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.edrockwell.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"System Admin [RESOLVED] | How To: Make My DevOps Life Easier","og:type":"article","og:title":"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]","og:description":"To get the filesystem size, used, available, % used, and what it's mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk","og:url":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/","article:published_time":"2022-01-21T19:11:18+00:00","article:modified_time":"2026-07-02T16:57:33+00:00","twitter:card":"summary","twitter:title":"Ansible | How to get the size of a directory from a linux server | System Admin [RESOLVED]","twitter:description":"To get the filesystem size, used, available, % used, and what it's mounted on run this simple ansible script to pull the data. It uses the df -h command of \/var\/log. You can modify it for any other directory you like --- - name: get the size of hosts: all tasks: - name: get disk"},"aioseo_meta_data":{"post_id":"300","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-6405f73a60c1a","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"businessInfo":{"name":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"line1":"","line2":"","zip":"","city":"","state":"","country":""},"contact":{"email":"","phone":"","fax":""},"ids":{"vatID":"","taxID":"","chamberID":""},"payment":{"priceIndication":"","currenciesAccepted":"","methodsAccepted":""},"areaServed":""},"openingHours":{"show":false,"closedLabel":"","open24h":false,"open24hLabel":"","open247":false,"use24hFormat":false,"twoSets":false,"timezone":"","hours":[]}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-01-21 19:04:10","updated":"2026-07-02 17:28:24","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.edrockwell.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.edrockwell.com\/blog\/category\/uncategorized\/\" title=\"Uncategorized\">Uncategorized<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tAnsible | How to get the size of a directory from a linux server\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.edrockwell.com\/blog"},{"label":"Uncategorized","link":"https:\/\/www.edrockwell.com\/blog\/category\/uncategorized\/"},{"label":"Ansible | How to get the size of a directory from a linux server","link":"https:\/\/www.edrockwell.com\/blog\/ansible-how-to-get-the-size-of-a-directory-from-a-linux-server\/"}],"_links":{"self":[{"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":1,"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/posts\/300\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edrockwell.com\/blog\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}