{"id":4751,"date":"2026-02-18T12:45:37","date_gmt":"2026-02-18T12:45:37","guid":{"rendered":"https:\/\/netguide.io\/linux\/?page_id=4751"},"modified":"2026-02-18T12:51:10","modified_gmt":"2026-02-18T12:51:10","slug":"ansible-playbook-check_netplan_status","status":"publish","type":"page","link":"https:\/\/netguide.io\/linux\/de\/ansible-playbooks\/ansible-playbook-check_netplan_status\/","title":{"rendered":"Ansible Playbook &#8211; Pr\u00fcfen ob Netplan Aktiv ist"},"content":{"rendered":"\n<p>Dieses Ansible-Playbook dient als <strong>Diagnose-Werkzeug<\/strong>, um den Fortschritt deiner Netzwerk-Migration von der alten Methode (<code>ifupdown<\/code>) hin zu <strong>Netplan<\/strong> zu \u00fcberwachen. Es ver\u00e4ndert nichts am System, sondern f\u00fchrt eine Bestandsaufnahme durch.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>---\n- name: Report on Netplan Migration Status\n  hosts: &#91;all&#93;  # &lt;--- Replace with your group name or \"all\"\n  become: true\n  gather_facts: false\n  tasks:\n    - name: Check network configurations on servers\n      shell: |\n        LEGACY=$(grep -P '^(?!#|lo|source|source-directory).*' \/etc\/network\/interfaces 2>\/dev\/null | wc -l)\n        IF_D=$(ls -A \/etc\/network\/interfaces.d\/ 2>\/dev\/null | wc -l)\n        NP=$(ls \/etc\/netplan\/*.yaml 2>\/dev\/null | wc -l)\n        echo \"$LEGACY|$IF_D|$NP\"\n      register: check_results\n      changed_when: false\n      ignore_unreachable: true\n\n    - name: Determine status logic\n      set_fact:\n        status_info: >-\n          {% if check_results.stdout is not defined %}\n          &#91;OFFLINE&#93; Host unreachable\n          {% elif check_results.stdout.split('|')&#91;2&#93;|int > 0 and check_results.stdout.split('|')&#91;0&#93;|int == 0 and check_results.stdout.split('|')&#91;1&#93;|int == 0 %}\n          &#91;OK&#93; Netplan active &amp; clean\n          {% elif check_results.stdout.split('|')&#91;2&#93;|int > 0 %}\n          &#91;!!&#93; Netplan exists, but legacy config found\n          {% else %}\n          &#91;WAIT&#93; NO Netplan found (Legacy active)\n          {% endif %}\n      when: check_results is defined\n\n- name: Display Result List\n  hosts: localhost\n  gather_facts: false\n  tasks:\n    - name: \"Show Summary\"\n      pause:\n        seconds: 2\n        prompt: |\n          \n          ================================================================================\n          NETPLAN MIGRATION STATUS REPORT (Generated: {{ now(fmt='%H:%M:%S') }})\n          ================================================================================\n          {% for host in groups&#91;'all'&#93; | sort %}\n          {% if hostvars&#91;host&#93;.status_info is defined or hostvars&#91;host&#93;.check_results is defined %}\n          {{ host.ljust(40) }} : {{ hostvars&#91;host&#93;.status_info | default('&#91;OFFLINE&#93; Connection failed') }}\n          {% endif %}\n          {% endfor %}\n          ================================================================================\n          NOTE: For &#91;!!&#93;, please clean up \/etc\/network\/interfaces!<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">---<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">- <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Report on Netplan Migration Status<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">hosts<\/span><span style=\"color: #E1E4E8\">: &#91;<\/span><span style=\"color: #9ECBFF\">all<\/span><span style=\"color: #E1E4E8\">&#93;  <\/span><span style=\"color: #6A737D\"># &lt;--- Replace with your group name or &quot;all&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">become<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">gather_facts<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">tasks<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    - <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Check network configurations on servers<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">shell<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">|<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        LEGACY=$(grep -P &#39;^(?!#|lo|source|source-directory).*&#39; \/etc\/network\/interfaces 2&gt;\/dev\/null | wc -l)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        IF_D=$(ls -A \/etc\/network\/interfaces.d\/ 2&gt;\/dev\/null | wc -l)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        NP=$(ls \/etc\/netplan\/*.yaml 2&gt;\/dev\/null | wc -l)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        echo &quot;$LEGACY|$IF_D|$NP&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">register<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">check_results<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">changed_when<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">ignore_unreachable<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    - <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Determine status logic<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">set_fact<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #85E89D\">status_info<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">&gt;-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% if check_results.stdout is not defined %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          &#91;OFFLINE&#93; Host unreachable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% elif check_results.stdout.split(&#39;|&#39;)&#91;2&#93;|int &gt; 0 and check_results.stdout.split(&#39;|&#39;)&#91;0&#93;|int == 0 and check_results.stdout.split(&#39;|&#39;)&#91;1&#93;|int == 0 %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          &#91;OK&#93; Netplan active &amp; clean<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% elif check_results.stdout.split(&#39;|&#39;)&#91;2&#93;|int &gt; 0 %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          &#91;!!&#93; Netplan exists, but legacy config found<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% else %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          &#91;WAIT&#93; NO Netplan found (Legacy active)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% endif %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">when<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">check_results is defined<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">- <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Display Result List<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">hosts<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">localhost<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">gather_facts<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">tasks<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    - <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Show Summary&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">pause<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #85E89D\">seconds<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #85E89D\">prompt<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">|<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          <\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          ================================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          NETPLAN MIGRATION STATUS REPORT (Generated: {{ now(fmt=&#39;%H:%M:%S&#39;) }})<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          ================================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% for host in groups&#91;&#39;all&#39;&#93; | sort %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% if hostvars&#91;host&#93;.status_info is defined or hostvars&#91;host&#93;.check_results is defined %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {{ host.ljust(40) }} : {{ hostvars&#91;host&#93;.status_info | default(&#39;&#91;OFFLINE&#93; Connection failed&#39;) }}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% endif %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% endfor %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          ================================================================================<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          NOTE: For &#91;!!&#93;, please clean up \/etc\/network\/interfaces!<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Funktionsweise<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Der Kopf des Playbooks (Zieldefinition)<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>- name: Report on Netplan Migration Status\n  hosts: &#91;all&#93;\n  become: true\n  gather_facts: false\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">- <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Report on Netplan Migration Status<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">hosts<\/span><span style=\"color: #E1E4E8\">: &#91;<\/span><span style=\"color: #9ECBFF\">all<\/span><span style=\"color: #E1E4E8\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">become<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">gather_facts<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">false<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>hosts: dimportVM<\/code><\/strong>: Legt fest, welche Gruppe aus deinem Inventory (<code>\/etc\/ansible\/hosts<\/code>) angesprochen wird.<\/li>\n\n\n\n<li><strong><code>become: true<\/code><\/strong>: Ansible f\u00fchrt die Befehle mit <code>sudo<\/code>-Rechten aus (n\u00f6tig, um <code>\/etc\/network\/interfaces<\/code> zu lesen).<\/li>\n\n\n\n<li><strong><code>gather_facts: false<\/code><\/strong>: Schaltet das automatische Sammeln von Systeminfos (CPU, RAM etc.) ab. Das macht das Playbook deutlich schneller.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. Die Analyse (Das Shell-Skript)<\/h3>\n\n\n\n<p>In diesem Abschnitt wird die &#8220;Detektivarbeit&#8221; auf den Servern geleistet.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>    - name: Check network configurations on servers\n      shell: |\n        LEGACY=$(grep -P '^(?!#|lo|source|source-directory).*' \/etc\/network\/interfaces 2>\/dev\/null | wc -l)\n        IF_D=$(ls -A \/etc\/network\/interfaces.d\/ 2>\/dev\/null | wc -l)\n        NP=$(ls \/etc\/netplan\/*.yaml 2>\/dev\/null | wc -l)\n        echo \"$LEGACY|$IF_D|$NP\"\n      register: check_results\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">    - <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Check network configurations on servers<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">shell<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">|<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        LEGACY=$(grep -P &#39;^(?!#|lo|source|source-directory).*&#39; \/etc\/network\/interfaces 2&gt;\/dev\/null | wc -l)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        IF_D=$(ls -A \/etc\/network\/interfaces.d\/ 2&gt;\/dev\/null | wc -l)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        NP=$(ls \/etc\/netplan\/*.yaml 2&gt;\/dev\/null | wc -l)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">        echo &quot;$LEGACY|$IF_D|$NP&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">register<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">check_results<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>grep -P '^(?!#|lo|source|source-directory).*'<\/code><\/strong>:\n<ul class=\"wp-block-list\">\n<li>Sucht nach Zeilen, die <strong>nicht<\/strong> mit <code>#<\/code> (Kommentar) beginnen.<\/li>\n\n\n\n<li>Ignoriert <code>lo<\/code> (Loopback), <code>source<\/code> und <code>source-directory<\/code>.<\/li>\n\n\n\n<li>Alles andere (wie <code>auto ens18<\/code> oder <code>iface...<\/code>) z\u00e4hlt als &#8220;Altlast&#8221;.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>ls -A ... | wc -l<\/code><\/strong>: Z\u00e4hlt, wie viele Dateien in den Ordnern liegen.<\/li>\n\n\n\n<li><strong><code>echo \"$LEGACY|$IF_D|$NP\"<\/code><\/strong>: Gibt die drei Zahlen durch ein <code>|<\/code> getrennt aus (z.B. <code>3|0|1<\/code>).<\/li>\n\n\n\n<li><strong><code>register: check_results<\/code><\/strong>: Speichert diese Ausgabe in einer Variable f\u00fcr den n\u00e4chsten Schritt.<\/li>\n\n\n\n<li><strong><code>ignore_unreachable: true<\/code><\/strong>: Verhindert den Abbruch des gesamten Playbooks, wenn eine VM offline ist.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. Die Logik (Status-Vergabe)<\/h3>\n\n\n\n<p>Hier entscheidet Ansible basierend auf den Zahlen, welcher &#8220;Stempel&#8221; auf den Host kommt.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>    - name: Determine status logic\n      set_fact:\n        status_info: >-\n          {% if check_results.stdout is not defined %} &#91;OFFLINE&#93; ...\n          {% elif check_results.stdout.split('|')&#91;2&#93;|int > 0 and check_results.stdout.split('|')&#91;0&#93;|int == 0 ... %} &#91;OK&#93; ...\n          {% elif check_results.stdout.split('|')&#91;2&#93;|int > 0 %} &#91;!!&#93; ...\n          {% else %} &#91;WAIT&#93; ...\n          {% endif %}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">    - <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Determine status logic<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">set_fact<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #85E89D\">status_info<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">&gt;-<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% if check_results.stdout is not defined %} &#91;OFFLINE&#93; ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% elif check_results.stdout.split(&#39;|&#39;)&#91;2&#93;|int &gt; 0 and check_results.stdout.split(&#39;|&#39;)&#91;0&#93;|int == 0 ... %} &#91;OK&#93; ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% elif check_results.stdout.split(&#39;|&#39;)&#91;2&#93;|int &gt; 0 %} &#91;!!&#93; ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% else %} &#91;WAIT&#93; ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% endif %}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>set_fact<\/code><\/strong>: Erstellt eine neue Variable (<code>status_info<\/code>) direkt f\u00fcr diesen Host.<\/li>\n\n\n\n<li><strong><code>split('|')<\/code><\/strong>: Zerlegt die Kette <code>3|0|1<\/code> wieder in einzelne Zahlen.<\/li>\n\n\n\n<li><strong>Logik-Check<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Wenn Netplan-Datei da (<code>&gt; 0<\/code>) <strong>UND<\/strong> Legacy-Zeilen weg (<code>== 0<\/code>) $\\rightarrow$ <strong>OK<\/strong>.<\/li>\n\n\n\n<li>Wenn Netplan-Datei da, aber Legacy-Zeilen auch noch da $\\rightarrow$ <strong>[!!] Altlasten<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. Der Bericht (Die Ausgabe)<\/h3>\n\n\n\n<p>Dieser Teil l\u00e4uft nicht auf den Servern, sondern auf deinem eigenen Rechner (<code>localhost<\/code>).<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>- name: Display Result List\n  hosts: localhost\n  tasks:\n    - name: \"Show Summary\"\n      pause:\n        seconds: 2\n        prompt: |\n          ...\n          {% for host in groups&#91;'all'&#93; | sort %}\n          {% if hostvars&#91;host&#93;.status_info is defined ... %}\n          {{ host.ljust(40) }} : {{ hostvars&#91;host&#93;.status_info }}\n          {% endif %}\n          {% endfor %}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">- <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">Display Result List<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">hosts<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">localhost<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #85E89D\">tasks<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    - <\/span><span style=\"color: #85E89D\">name<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Show Summary&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #85E89D\">pause<\/span><span style=\"color: #E1E4E8\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #85E89D\">seconds<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #85E89D\">prompt<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #F97583\">|<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% for host in groups&#91;&#39;all&#39;&#93; | sort %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% if hostvars&#91;host&#93;.status_info is defined ... %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {{ host.ljust(40) }} : {{ hostvars&#91;host&#93;.status_info }}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% endif %}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9ECBFF\">          {% endfor %}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>hosts: localhost<\/code><\/strong>: Schaltet auf deinen lokalen Rechner um, um die Ergebnisse aller Server zu sammeln.<\/li>\n\n\n\n<li><strong><code>pause<\/code><\/strong>: Eigentlich zum Warten gedacht, nutzen wir es hier, um einen sauberen, unformatierten Textblock (ohne JSON-Klammern) auszugeben.<\/li>\n\n\n\n<li><strong><code>for host in groups['all'] | sort<\/code><\/strong>: Geht alle Hosts alphabetisch durch.<\/li>\n\n\n\n<li><strong><code>hostvars[host].status_info<\/code><\/strong>: Greift auf die Status-Variable zu, die wir im vorherigen Schritt auf dem jeweiligen Server gespeichert haben.<\/li>\n\n\n\n<li><strong><code>ljust(40)<\/code><\/strong>: &#8220;Left Justify&#8221; \u2013 f\u00fcllt den Hostnamen mit Leerzeichen auf 40 Zeichen auf, damit die Doppelpunkte sch\u00f6n untereinander stehen.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Zusammenfassung: Der &#8220;Flow&#8221;<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Verbinden<\/strong> zu allen Servern in <code>dimportVM<\/code>.<\/li>\n\n\n\n<li><strong>Z\u00e4hlen<\/strong> von Dateien und Zeilen.<\/li>\n\n\n\n<li><strong>Bewerten<\/strong> der Situation (OK, !!, WAIT).<\/li>\n\n\n\n<li><strong>Sammeln<\/strong> aller Bewertungen auf deinem Rechner.<\/li>\n\n\n\n<li><strong>Drucken<\/strong> der h\u00fcbschen Tabelle.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Dieses Ansible-Playbook dient als Diagnose-Werkzeug, um den Fortschritt deiner Netzwerk-Migration von der alten Methode (ifupdown) hin zu Netplan zu \u00fcberwachen. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4737,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-4751","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"tobias.pries","author_link":"https:\/\/netguide.io\/linux\/author\/tobias-pries\/"},"uagb_comment_info":0,"uagb_excerpt":"Dieses Ansible-Playbook dient als Diagnose-Werkzeug, um den Fortschritt deiner Netzwerk-Migration von der alten Methode (ifupdown) hin zu Netplan zu \u00fcberwachen. [&hellip;]","_links":{"self":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/pages\/4751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/comments?post=4751"}],"version-history":[{"count":2,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/pages\/4751\/revisions"}],"predecessor-version":[{"id":4756,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/pages\/4751\/revisions\/4756"}],"up":[{"embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/pages\/4737"}],"wp:attachment":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/media?parent=4751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}