[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-168975-en":3,"doc-seo-168975-105":30,"detail-sidebar-cat-1-en-105":90},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":11,"category_id":12,"category_name":13,"doc_title":14,"doc_description":15,"doc_content":16,"file_id":17,"file_url":18,"file_type":19,"file_size":20,"view_count":11,"is_deleted":4,"is_public":11,"is_downloadable":11,"audit_status":11,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":27,"seo_description":15,"update_tm":28,"read_time":29},168975,962085571259,"Putri","https://ap-avatar.wpscdn.com/davatar_29158cc5080c5b710cf443261637dec0",1,158,"General","Manipulate Ansible Data - using Jinja Filters","Ansible data transformation and manipulation is achieved through Jinja2 template filters that run on the Ansible controller, minimizing data transfer to remote hosts. The document explains how the Ansible filtering engine builds on Jinja templating to turn input variables into controlled outputs, then applies the results for follow-on Ansible tasks like debugging. It also covers filter usage syntax and demonstrates practical examples across formatting, defaulting, debugging, math operations, and hashing.","Manipulate Ansible Data using Jinja Filters\nOn some occasions, when you are using Ansible to automate various tasks, you may need to transform and manipulate data. In Ansible, you can use a set of built-in filters or create custom filters to manipulate, process, and convert data. Ansible uses jinja2 template filters in the background to allow users to create filters for specified data. It is important to note that filter templating is carried out on the Ansible controller, and not on the specified remote hosts. This helps to reduce the amount of data transferred to the remote host after local processing. If you are unfamiliar with jinja templating, Jinja is a simple, intuitive, fast, and secure templating language for the Python programming language developed after the popular Python framework Django templates. We will not get into how jinja templating works, though it can be an added advantage to understand how it works with templates. Check out the resource provided below to learn more about Jinja. \u0013 HYPERLINK \"https://linkfy.to/jinjaDocs\" \u0014https://linkfy.to/jinjaDocs\u0015\nHow Ansible Filters Work\nAs mentioned, the Ansible filtering engine builds upon the Jinja templating model. This allows users to use these templates to input data, process them, and provide an output based on the defined filters. Once the data is transformed and filtered using the defined template, you can use it to perform other tasks in Ansible. You can learn more about filters in Ansible at the following website: \u0013 HYPERLINK \"https://linkfy.to/AnsibleFilters\" \u0014https://linkfy.to/AnsibleFilters\u0015 Ansible has many filters that are all very useful and applicable to many different scenarios. Once you have the filter output, you can use it to perform other tasks, such as debugging. The general syntax for filtering data is as follows: [cc lang=\"bash\" width=\"100%\" height=\"100%\" escaped=\"true\" theme=\"blackboard\" nowrap=\"0\"] {{ \u003Cinput> | \u003Cfilter> }}[/cc]\nUsing Ansible Filters\nWe will now look at examples of Ansible filters that we can use to perform various tasks. NOTE: As previously mentioned, Ansible has many filters, so we cannot cover all of them in this article. Instead, this tutorial seeks to provide you with the basics of using various Ansible filters.\nExample 1: Ansible Format Data Filters\nThe Ansible format data filters take an output data structure in a template and use the specified filter to render it in the format called in the filter. Below is an example filter to convert to JSON and YAML: [cc lang=\"bash\" width=\"100%\" height=\"100%\" escaped=\"true\" theme=\"blackboard\" nowrap=\"0\"] {{ variable | to_json}} {{ variable | to_yaml}}[/cc] For example, consider the following playbook: [cc lang=\"bash\" width=\"100%\" height=\"100%\" escaped=\"true\" theme=\"blackboard\" nowrap=\"0\"] - hosts: all tasks: - shell: cat /tmp/all.json register: result - debug: msg: \"{{result.stdout | to_nice_yaml}}\"[/cc] Running the above playbook will produce an output for the JSON data converted to YAML. The following is an example output:\nYou can also specify other filters such, as to_nice_yaml, to obtain the output in a human-readable format. [cc lang=\"bash\" width=\"100%\" height=\"100%\" escaped=\"true\" theme=\"blackboard\" nowrap=\"0\"] {{ variable | to_nice_json }} {{ variable | to_nice_yaml }}[/cc] Using the formatting data filters, you can transform data into various formats and use it for various tasks. For instance, you can pass parse multi-document YAML strings, as in the playbook below: [cc lang=\"bash\" width=\"100%\" height=\"100%\" escaped=\"true\" theme=\"blackboard\" nowrap=\"0\"] - hosts: all tasks: - shell: cat /tmp/all.json register: result - debug: msg: \"{{result.stdout | to_yaml | list}}\"[/cc]\nExample 2: Ansible Default Filter\nThe Ansible default filter helps to default values to undefined variables. The default Ansible configuration fails undefined variables. For example, if you have an undefined variable, you can tell Ansible to default to a value instead of raising an error. The general syntax","cbCaiiirUm1rfZtJ","https://ap.wps.com/l/cbCaiiirUm1rfZtJ","docx",40432,4,"English","en",105,"# How Ansible Filters Work\n# Using Ansible Filters\n## Example 1: Ansible Format Data Filters\n## Example 2: Ansible Default Filter\n## Example 3: Ansible Debug Filters\n## Example 4: Math Filters\n## Example 5: Hash Filters","[{\"question\":\"Where does Ansible apply Jinja filters: on the controller or on remote hosts?\",\"answer\":\"Filter templating is carried out on the Ansible controller, not on the specified remote hosts. This reduces the amount of data transferred after local processing.\"},{\"question\":\"What is the general syntax for applying filters to Ansible data?\",\"answer\":\"Filtering follows the template expression form: {{ \\u003cinput\\u003e | \\u003cfilter\\u003e }}. The document uses this structure across examples like JSON/YAML conversion and debugging.\"},{\"question\":\"How do the default and mandatory filters differ for undefined variables?\",\"answer\":\"The default filter assigns a fallback value when a variable is undefined instead of raising an error. The mandatory filter forces a value to be provided by failing when the required input is missing.\"}]","Manipulate Ansible Data - using Jinja Filters | DOCX",1788241522,2,{"code":4,"msg":31,"data":32},"ok",{"site_id":24,"language":23,"slug":33,"title":14,"keywords":34,"description":15,"schema_data":35,"social_meta":85,"head_meta":87,"extra_data":89,"updated_unix":28},"manipulate-ansible-data-using-jinja-filters","",{"@graph":36,"@context":84},[37,52,67],{"@type":38,"itemListElement":39},"BreadcrumbList",[40,44,47,50],{"item":41,"name":42,"@type":43,"position":11},"https://docshare.wps.com","Home","ListItem",{"item":45,"name":46,"@type":43,"position":29},"https://docshare.wps.com/template/","Template",{"item":48,"name":13,"@type":43,"position":49},"https://docshare.wps.com/template/general/",3,{"item":51,"name":14,"@type":43,"position":21},"https://docshare.wps.com/template/manipulate-ansible-data-using-jinja-filters/168975/",{"url":51,"name":14,"@type":53,"author":54,"headline":14,"publisher":56,"fileFormat":59,"inLanguage":23,"description":15,"dateModified":60,"datePublished":61,"encodingFormat":59,"isAccessibleForFree":62,"interactionStatistic":63},"DigitalDocument",{"name":9,"@type":55},"Person",{"url":41,"name":57,"@type":58},"DocShare","Organization","application/vnd.openxmlformats-officedocument.wordprocessingml.document","2026-09-04","2026-09-01",true,{"@type":64,"interactionType":65,"userInteractionCount":11},"InteractionCounter",{"@type":66},"ViewAction",{"@type":68,"mainEntity":69},"FAQPage",[70,76,80],{"name":71,"@type":72,"acceptedAnswer":73},"Where does Ansible apply Jinja filters: on the controller or on remote hosts?","Question",{"text":74,"@type":75},"Filter templating is carried out on the Ansible controller, not on the specified remote hosts. This reduces the amount of data transferred after local processing.","Answer",{"name":77,"@type":72,"acceptedAnswer":78},"What is the general syntax for applying filters to Ansible data?",{"text":79,"@type":75},"Filtering follows the template expression form: {{ \u003Cinput> | \u003Cfilter> }}. The document uses this structure across examples like JSON/YAML conversion and debugging.",{"name":81,"@type":72,"acceptedAnswer":82},"How do the default and mandatory filters differ for undefined variables?",{"text":83,"@type":75},"The default filter assigns a fallback value when a variable is undefined instead of raising an error. The mandatory filter forces a value to be provided by failing when the required input is missing.","https://schema.org",{"og:url":51,"og:type":86,"og:title":14,"og:site_name":57,"og:description":15},"article",{"robots":88,"canonical":51},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":91},[92,97,102,107,112,117,122,127,132],{"id":93,"doc_module":11,"doc_module_name":46,"category_name":94,"show_sort_weight":95,"slug":96},11,"Presentations",90,"presentations",{"id":98,"doc_module":11,"doc_module_name":46,"category_name":99,"show_sort_weight":100,"slug":101},12,"Resumes",80,"resumes",{"id":103,"doc_module":11,"doc_module_name":46,"category_name":104,"show_sort_weight":105,"slug":106},14,"Invoices",70,"invoices",{"id":108,"doc_module":11,"doc_module_name":46,"category_name":109,"show_sort_weight":110,"slug":111},15,"Posters",60,"posters",{"id":113,"doc_module":11,"doc_module_name":46,"category_name":114,"show_sort_weight":115,"slug":116},16,"Social Media",50,"social-media",{"id":118,"doc_module":11,"doc_module_name":46,"category_name":119,"show_sort_weight":120,"slug":121},17,"Forms",40,"forms",{"id":123,"doc_module":11,"doc_module_name":46,"category_name":124,"show_sort_weight":125,"slug":126},18,"Letters",30,"letters",{"id":128,"doc_module":11,"doc_module_name":46,"category_name":129,"show_sort_weight":130,"slug":131},21,"Paper Templates",5,"papers-templates",{"id":12,"doc_module":11,"doc_module_name":46,"category_name":13,"show_sort_weight":4,"slug":133},"general-158"]