{"id":291,"date":"2017-07-27T20:49:53","date_gmt":"2017-07-27T18:49:53","guid":{"rendered":"http:\/\/blog.le-vert.net\/?p=291"},"modified":"2017-07-27T20:49:53","modified_gmt":"2017-07-27T18:49:53","slug":"fixing-vmware-vcenter-template-customization-for-debian-stretch-nic-detected-as-ether","status":"publish","type":"post","link":"https:\/\/blog.le-vert.net\/?p=291","title":{"rendered":"Fixing VMware vCenter template customization for Debian Stretch (nic detected as &#8220;ether&#8221;)"},"content":{"rendered":"<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=Fixing+VMware+vCenter+template+customization+for+Debian+Stretch+%28nic+detected+as+%22ether%22%29\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/blog.le-vert.net\/?p=291\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><\/div><p>Hello,<\/p>\n<p>I&#8217;m a big fan of Foreman, I use it everywhere to spawn my virtual machines (mostly with VMWare vCenter or AWS) and then apply directly Puppet classes on it to get a fully configured new host in a few clicks. Maybe I&#8217;ll write about it one day, let&#8217;s see.<\/p>\n<p>Anyway, this week theme was mostly &#8220;Let&#8217;s upgrade from Jessie to Stretch, I&#8217;m craving Python 3.5 and the new async\/await syntax)&#8221;.<br \/>\nSadly, it went wrong. I was unable to use my Foreman anymore against ESX 6.0 because when injecting the customization XML file (used to define IP settings within the VM through open-vm-tools) the resulting VM had no network set.<br \/>\nAfter looking at what happened, I figured out <strong>\/etc\/network\/interfaces<\/strong> had been created wrong: instead of using eth0 (yes, I disabled <em>predicitve<\/em> interface name in my template) it was all set like the interface was named <strong>ether<\/strong>. Uh ?<\/p>\n<p>Quick Google search with &#8220;debian stretch vmware ether&#8221; lead me to the following <a href=\"https:\/\/github.com\/vmware\/open-vm-tools\/issues\/130\">GitHub bug<\/a> opened against open-vm-tools. Sadly the issue wouldn&#8217;t come from open-vm-tools: this issue comes from a VMWare script not parsing correctly current ifconfig output (yeah, I added net-tools in my template too).<\/p>\n<p>Here is an extract of the net-tools package NEWS.Debian file:<\/p>\n<pre class=\"attributes\" >net-tools (1.60+git20161116.90da8a0-1) unstable; urgency=medium\r\n\r\n  After 15 years without upstream development, net-tools is being worked on\r\n  again, fixing many long-standing issues.\r\n\r\n  The bad news is that the output of many commands has changed, and it is sure\r\n  to break scripts that relied on parsing it.\r\n\r\n  If you have customs scripts that use any of these commands, please make sure\r\n  they still work after this upgrade:\r\n\r\n    netstat, ifconfig, ipmaddr, iptunnel, mii-tool, nameif, plipconfig, rarp,\r\n    route, slattach, arp.\r\n\r\n  Apologies in advance for the trouble that this may cause, but maintaining a\r\n  separate version of net-tools just to keep the old format is something I am\r\n  not able to do.<\/pre>\n<p>Wow, that&#8217;s a pretty dangerous move you did here&#8230;.<\/p>\n<p>The script creating the network configuration is actually a piece of Perl crap copied directly from the vCenter server into the VM filesystem. Yeah, that sounds like black magic but the good news is that&#8217;s it&#8217;s Perl, so it&#8217;s fixable.<\/p>\n<p>So I searched for this &#8220;Customization.pm&#8221; file on my vCenter Windows server and I found it here:<br \/>\n<strong>C:\\Program Files\\VMware\\vCenter Server\\vpxd\\imgcust\\linux\\imgcust-scripts\\Customization.pm<\/strong><\/p>\n<p>I managed quite easily to understand what was wrong, and I must say that original output parsing was <em>pretty cheap<\/em>.<br \/>\nAnyway, here&#8217;s a better one that just works:<\/p>\n<pre class=\"lang:diff decode:true   \" >+++ Customization.pm.new\t2017-07-27 20:21:35.559476473 +0200\r\n@@ -756,17 +756,17 @@\r\n    if (! defined $ifcfgResult) {\r\n       $ifcfgResult = Utils::ExecuteCommand('\/sbin\/ifconfig -a');\r\n    }\r\n+  \r\n+   my @interfaces = split\/\\n\\n\/, $ifcfgResult;\r\n \r\n-   my $result = undef;\r\n-\r\n-   my $macAddressValid = ($macAddress =~ \/^([0-9a-f]{2}:){5}[0-9a-f]{2}$\/i);\r\n-\r\n-   if ($macAddressValid &amp;amp;&amp;amp;\r\n-      ($ifcfgResult =~ \/^\\s*(\\w+?)(:\\w*)?\\s+.*?$macAddress\/mi)) {\r\n-      $result = $1;\r\n+   foreach my $interface (@interfaces) {\r\n+      if ($interface =~ \/$macAddress\/) {\r\n+\t      print($interface);\r\n+          if ($interface =~ m\/^(\\w+)(:|\\s)\/) {\r\n+              return $1;\r\n+          }\r\n+      }\r\n    }\r\n-\r\n-   return $result;\r\n }\r\n \r\n sub GetInterfaceByMacAddressIPAddrShow<\/pre>\n<p>Nothing to restart, this file in copied everytime you apply customization to a template. You&#8217;ll find attached a text version of the patch: <a href=\"http:\/\/blog.le-vert.net\/?attachment_id=292\" rel=\"attachment wp-att-292\">vcenter_Customization_pm.diff<\/a><\/p>\n<p>Good luck!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, I&#8217;m a big fan of Foreman, I use it everywhere to spawn my virtual machines (mostly with VMWare vCenter or AWS) and then apply directly Puppet classes on it to get a fully configured new host in a few &hellip; <a href=\"https:\/\/blog.le-vert.net\/?p=291\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=\/wp\/v2\/posts\/291"}],"collection":[{"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291"}],"version-history":[{"count":4,"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions"}],"predecessor-version":[{"id":296,"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions\/296"}],"wp:attachment":[{"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.le-vert.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}