{"id":1096,"date":"2021-06-09T17:39:56","date_gmt":"2021-06-09T15:39:56","guid":{"rendered":"https:\/\/loeilduse.fr\/?p=1096"},"modified":"2021-06-11T09:03:51","modified_gmt":"2021-06-11T07:03:51","slug":"customize-an-ubuntu-vm-with-cloud-init-on-vsphere","status":"publish","type":"post","link":"https:\/\/loeilduse.fr\/?p=1096&lang=en","title":{"rendered":"Customize an Ubuntu VM with Cloud-Init on vSphere"},"content":{"rendered":"<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><a href=\"https:\/\/cloudinit.readthedocs.io\/en\/latest\/\"> Cloud-Init<\/a> <span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">seems to be the favorite customization tool for major OSs aiming to be installed on different cloud environments (AWS, Azure, GCP, vSphere, &#8230;), it is very powerful, heterogeneous but at the beginning, it is difficult to understand how it works. <\/span><\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">Personalization information are stored in a file called user-data. This file is transmitted to Cloud-Init using a mechanism specific to each cloud. In our case, it is the VMtools that will transmit the user-data file, once received, Cloud-Init will execute it. <\/span><\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">I wasted a tremendous amount of time finding the minimum steps to customize Ubuntu OS with Cloud-Init in a vSphere environment. I was looking for the possibility of customizing the OS when cloning from an OVF template. <\/span><\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">Below is the procedure I use for an Ubuntu 20.04.2 LTS, freshly installed and after its first reboot. I kept the default values \u200b\u200bexcept for the French keyboard and the installation of the OpenServer SSH option. <\/span><\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">Cloud-Init must be told to retrieve the user-data customization file via the OVF parameters of the VM, there is a step to be done on the VM side and an OS side.<\/span><\/span><br \/>\n<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><strong>OS side:<\/strong><\/span><\/p>\n<ul style=\"text-align: justify;\">\n<li style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">Delete the file that sets the Datasource to none instead of OVF:<\/span><\/span><\/span>\n<ul>\n<li style=\"text-align: left;\"><span style=\"font-family: courier new, courier, monospace;\">sudo rm \/etc\/cloud\/cloud.cfg.d\/99-installer.cfg<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">If you want the network configuration to be done, delete the file that disables it:<\/span><\/span><\/span>\n<ul>\n<li style=\"text-align: left;\"><span style=\"font-family: courier new, courier, monospace;\">sudo rm \/etc\/cloud\/cloud.cfg.d\/subiquity-disable-cloudinit-networking.cfg<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">If you are in DHCP, the VM will always retrieve the same IP because it will keep the same machine ID.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"1\">To avoid this, you must reset the identity of the OS<\/span><\/span>:<\/span>\n<ul>\n<li><span style=\"font-family: courier new, courier, monospace;\">sudo truncate -s 0 \/etc\/machine-id<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><strong>VM side:<\/strong><\/span><\/p>\n<ul style=\"text-align: justify;\">\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">Get the contents of your cloud-init user-data file and encoded it with base64<\/span><\/span>:<\/span>\n<ul>\n<li style=\"text-align: left;\"><span style=\"font-family: courier new, courier, monospace;\">Base64 user-data.yaml<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">From the vSphere client, when the VM is stopped, activate the properties of the OVF<\/span><\/span> :<\/span>\n<ul>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\">Select the VM =&gt; Configure =&gt; vApp Options =&gt; vApp Options are disabled &#8230; Edit =&gt; Click on &#8220;Enable vApp options&#8221;<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1086 aligncenter\" src=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/Enable-vApp.png\" alt=\"\" width=\"624\" height=\"295\" srcset=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/Enable-vApp.png 624w, https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/Enable-vApp-300x142.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/span><\/li>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\">In the OVF details tab =&gt; <label id=\"vsc-widget-id-35-ovfEnvironmentTransportLabelId\">OVF environment transport <\/label> =&gt; check the VMware Tools case<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1087 aligncenter\" src=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/Enable-vApp-VMTools.png\" alt=\"\" width=\"624\" height=\"433\" srcset=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/Enable-vApp-VMTools.png 624w, https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/Enable-vApp-VMTools-300x208.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">From the vSphere client, when the VM is stopped, add the user-data field in the properties of the OVF<\/span><\/span>:<\/span>\n<ul>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\">=&gt; Select the VM =&gt; Configure =&gt; vApp Options =&gt; Properties =&gt; ADD enter the Label and the Key id with the user-data value.<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1088 aligncenter\" src=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-Add-key-id.png\" alt=\"\" width=\"624\" height=\"269\" srcset=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-Add-key-id.png 624w, https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-Add-key-id-300x129.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">From the vSphere client, when the VM is stopped, add the value to the user-data field in the properties of the OVF:<\/span><\/span><br \/>\n<\/span><\/p>\n<ul>\n<li><span style=\"font-family: trebuchet ms, geneva, sans-serif;\">Select the VM =&gt; Configure =&gt; vApp Options =&gt; Properties =&gt; SET VALUE, a popup appear and set it with the base64 key comming from the user-data file retrieved in the step early<br \/>\n<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1090 aligncenter\" src=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-SetValue-user-data.png\" alt=\"\" width=\"624\" height=\"259\" srcset=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-SetValue-user-data.png 624w, https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-SetValue-user-data-300x125.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1089 aligncenter\" src=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-Properties-user-data.png\" alt=\"\" width=\"624\" height=\"323\" srcset=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-Properties-user-data.png 624w, https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-Properties-user-data-300x155.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1093 aligncenter\" src=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-final-user-data.png\" alt=\"\" width=\"624\" height=\"224\" srcset=\"https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-final-user-data.png 624w, https:\/\/loeilduse.fr\/wp-content\/uploads\/2021\/06\/vApp-final-user-data-300x108.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-family: trebuchet ms, geneva, sans-serif;\"><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"0\">Now from this VM, directly make a clone to make another VM or to make a template.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"fr\" data-phrase-index=\"1\">If you want to change the user-data file, when deploying the VM, change only the base64 key to the new key<\/span><\/span> <\/span><\/p>\n<p style=\"text-align: justify;\">\n","protected":false},"excerpt":{"rendered":"<p>Cloud-Init seems to be the favorite customization tool for major OSs aiming to be installed on different cloud environments (AWS, Azure, GCP, vSphere, &#8230;), it is very powerful, heterogeneous but at the beginning, it is difficult to understand how it works. Personalization information are stored in a file called user-data. This file is transmitted to<\/p><\/div>\n<div class=\"blog-btn\"><a href=\"https:\/\/loeilduse.fr\/?p=1096&#038;lang=en\" class=\"home-blog-btn\">Lire la suite<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[401],"tags":[515,529,531,517,519,521,523,456],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/loeilduse.fr\/index.php?rest_route=\/wp\/v2\/posts\/1096"}],"collection":[{"href":"https:\/\/loeilduse.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loeilduse.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loeilduse.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loeilduse.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1096"}],"version-history":[{"count":4,"href":"https:\/\/loeilduse.fr\/index.php?rest_route=\/wp\/v2\/posts\/1096\/revisions"}],"predecessor-version":[{"id":1101,"href":"https:\/\/loeilduse.fr\/index.php?rest_route=\/wp\/v2\/posts\/1096\/revisions\/1101"}],"wp:attachment":[{"href":"https:\/\/loeilduse.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loeilduse.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loeilduse.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}