{"id":18980,"date":"2022-11-02T13:24:01","date_gmt":"2022-11-02T07:54:01","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/"},"modified":"2022-11-02T13:24:01","modified_gmt":"2022-11-02T07:54:01","slug":"solved-how-to-separate-the-output-of-register-into-dict","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/","title":{"rendered":"[Solved] How to separate the output of register into dict"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-71789190\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"71789190\" data-parentid=\"71759022\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>I create the dict vmoff2 using the following:<\/p>\n<pre><code>   - name: create Not Activated VM list\n      set_fact:\n        vmoff: &gt;-\n          {{ vmoff | default([])\n          + [{\n              'sec_sys': item.item.SEC_SYS,\n              'vm_na': dict(item.stdout_lines\n                | from_yaml\n                | select()\n                | map('split', ',')\n                | list)\n            }]\n          }}\n      loop: \"{{ output.results }}\"\n      loop_control:\n        label: \"{{ item.item.SEC_SYS }}\"\n\n<\/code><\/pre>\n<p>And eliminate the duplicate output with:<\/p>\n<pre><code>    - name: eliminate duplicate\n      set_fact:\n        vmoff2: \"{{ vmoff2 | default([]) + [{'sec_sys': item.1.0.sec_sys, 'vm_na': item.1.0.vm_na }] }}\"\n      loop: \"{{ vmoff|groupby('sec_sys') }}\"\n<\/code><\/pre>\n<p>Finally i have the following dict:<\/p>\n<pre><code>    \"vmoff2\": [\n        {\n            \"sec_sys\": \"CONT1\",\n            \"vm_na\": {\n                \"vm1\": \"Running\",\n                \"vm2\": \"Running\",\n                \"vm3\": \"Not Activated\",\n                \"vm4\": \"Not Activated\",\n                \"vm5\": \"Running\",\n                \"vm6\": \"Not Activated\"\n            }\n        },\n        {\n            \"sec_sys\": \"CONT2\",\n            \"vm_na\": {\n                \"vm1\": \"Not Activated\",\n                \"vm2\": \"Not Activated\",\n                \"vm3\": \"Running\",\n                \"vm4\": \"Running\",\n                \"vm5\": \"Not Activated\",\n                \"vm6\": \"Running\"\n            }\n        }\n    ]\n---------------\n    \"vmprof2\": [\n        {\n            \"proc\": {\n                \"vm1\": \"0.5\",\n                \"vm2\": \"0.7\",\n                \"vm3\": \"1.0\",\n                \"vm4\": \"0.5\",\n                \"vm5\": \"0.5\",\n                \"vm6\": \"0.5\"\n            },\n            \"sec_sys\": \"CONT1\"\n        },\n        {\n            \"proc\": {\n                \"vm1\": \"1.0\",\n                \"vm2\": \"0.7\",\n                \"vm3\": \"1.0\",\n                \"vm4\": \"0.7\",\n                \"vm5\": \"0.5\",\n                \"vm6\": \"0.7\"\n            },\n            \"sec_sys\": \"CONT2\"\n        }\n    ]\n<\/code><\/pre>\n<p>I want to sum the proc of the Not activated VM, and have the following output:<\/p>\n<pre><code>proc_steal:\n     - server: CONT1\n       proc: 1.7\n     - server: CONT2\n       proc: 2.4\n<\/code><\/pre>\n<p>I tried the following:<\/p>\n<pre><code>  - name: create proc_steal list\n      set_fact:\n        proc_steal: &gt;-\n          {{ proc_steal | default([])\n          + [{\n              'sec_sys': item.sec_sys,\n              'proc': vmprof2\n                | selectattr('sec_sys', '==', item.sec_sys)\n                | selectattr('proc', '==', item.vm_na)\n                | sum(attribute=\"value\")\n                | float\n            }]\n          }}\n      loop: \"{{ vmoff2 }}\"\n      loop_control:\n        label: \"{{ item.sec_sys }}\"\n<\/code><\/pre>\n<p>but i get:<\/p>\n<pre><code>    \"proc_steal\": [\n        {\n            \"proc\": 0.0,\n            \"sec_sys\": \"CONT1\"\n        },\n        {\n            \"proc\": 0.0,\n            \"sec_sys\": \"CONT2\"\n        }\n    ]\n}\n<\/code><\/pre>\n<p>Is not making the sum, maybe because is not float, but when i tried to put float i have an error, any guess?<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How to separate the output of register into dict <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I create the dict vmoff2 using the following: &#8211; name: create Not Activated VM list set_fact: vmoff: &gt;- {{ vmoff | default([]) + [{ &#8216;sec_sys&#8217;: item.item.SEC_SYS, &#8216;vm_na&#8217;: dict(item.stdout_lines | from_yaml | select() | map(&#8216;split&#8217;, &#8216;,&#8217;) | list) }] }} loop: &#8220;{{ output.results }}&#8221; loop_control: label: &#8220;{{ item.item.SEC_SYS }}&#8221; And eliminate the duplicate output with: &#8230; <a title=\"[Solved] How to separate the output of register into dict\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\" aria-label=\"More on [Solved] How to separate the output of register into dict\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[2465],"class_list":["post-18980","post","type-post","status-publish","format-standard","hentry","category-solved","tag-ansible"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] How to separate the output of register into dict - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How to separate the output of register into dict - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I create the dict vmoff2 using the following: - name: create Not Activated VM list set_fact: vmoff: &gt;- {{ vmoff | default([]) + [{ &#039;sec_sys&#039;: item.item.SEC_SYS, &#039;vm_na&#039;: dict(item.stdout_lines | from_yaml | select() | map(&#039;split&#039;, &#039;,&#039;) | list) }] }} loop: &quot;{{ output.results }}&quot; loop_control: label: &quot;{{ item.item.SEC_SYS }}&quot; And eliminate the duplicate output with: ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-02T07:54:01+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How to separate the output of register into dict\",\"datePublished\":\"2022-11-02T07:54:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\"},\"wordCount\":88,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"ansible\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\",\"name\":\"[Solved] How to separate the output of register into dict - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-11-02T07:54:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How to separate the output of register into dict\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How to separate the output of register into dict - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How to separate the output of register into dict - JassWeb","og_description":"[ad_1] I create the dict vmoff2 using the following: - name: create Not Activated VM list set_fact: vmoff: &gt;- {{ vmoff | default([]) + [{ 'sec_sys': item.item.SEC_SYS, 'vm_na': dict(item.stdout_lines | from_yaml | select() | map('split', ',') | list) }] }} loop: \"{{ output.results }}\" loop_control: label: \"{{ item.item.SEC_SYS }}\" And eliminate the duplicate output with: ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/","og_site_name":"JassWeb","article_published_time":"2022-11-02T07:54:01+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How to separate the output of register into dict","datePublished":"2022-11-02T07:54:01+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/"},"wordCount":88,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["ansible"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/","url":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/","name":"[Solved] How to separate the output of register into dict - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-11-02T07:54:01+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-separate-the-output-of-register-into-dict\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How to separate the output of register into dict"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/18980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=18980"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/18980\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=18980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=18980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=18980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}