<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Script issue with changing hostname in VMware Aria Automation Orchestrator Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-Aria-Automation/Script-issue-with-changing-hostname/m-p/2705596#M23324</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Having an odd problem and I'm not good enough with JavaScript to figure out what I'm doing wrong.&amp;nbsp; Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've add Kali Linux to my vRA build but sadly VMware does not have a customization file setting that will work with the newest Kali Linux build.&amp;nbsp; Not a big deal I just need to be able to change hostnames, I figured an easy way to do this would be to make a vRO workflow to change the hostname to whatever the user named their VM.&amp;nbsp; I've written it all up and added all the proper attributes in vRO and it is giving me a coding error.&amp;nbsp; I'm assuming what it is saying is miss labeled so hopefully someone can see what I've done wrong.&amp;nbsp; Here is the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;System.log("Workflow started from workflow stub " + externalWFStub + " on vCAC host " + vCACHost.displayName);&lt;/P&gt;&lt;P&gt;System.log("Got vCAC virtual machine " + vCACVm.virtualMachineName);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (vCenterVm != null) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; System.log("Got vCenter VM " + vCenterVm.name);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Displaying vCAC VM properties&lt;/P&gt;&lt;P&gt;if (vCACVmProperties != null) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; var log = "";&lt;/P&gt;&lt;P&gt;&amp;nbsp; log += "vCAC VM properties :\n";&lt;/P&gt;&lt;P&gt;&amp;nbsp; var array = new Array();&lt;/P&gt;&lt;P&gt;&amp;nbsp; for each (var key in vCACVmProperties.keys) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; array.push(key + " : " + vCACVmProperties.get(key));&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; array.sort();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; for each (var line in array) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; log += "\t" + line + "\n";&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; System.log(log);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Obtain build information from Blueprint&lt;/P&gt;&lt;P&gt;Build=vCACVmProperties.get('VirtualMachine.BuildType');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Obtain new hostname from VM&lt;/P&gt;&lt;P&gt;newHostName=vCACVmProperties.get('vCenterVM.name')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Set hostname on server through ssh&lt;/P&gt;&lt;P&gt;if (Build=='Kali'){&lt;/P&gt;&lt;P&gt;&amp;nbsp; username='root';&lt;/P&gt;&lt;P&gt;&amp;nbsp; password='password1';&lt;/P&gt;&lt;P&gt;&amp;nbsp; hostNameOrIP=vCACVmProperties.get('VirtualMachine.Network0.Address');&lt;/P&gt;&lt;P&gt;&amp;nbsp; cmd='sed -i -e "s/CURRENTHOSTNAME/' + newHostName '/g" /etc/hosts';&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simple enough, it pulls the machines information and runs an ssh command if it sees a build profile attribute that labels it as Kali.&amp;nbsp; The problem is the last lines.&amp;nbsp; The error I'm getting is "missing ; before statement (script#34) which is the line "cmd=hostname ' + newHostName ';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;username, password, hostNameOrIP and cmd are all variables in the workflow and if I delete the cmd line it takes the error away.&amp;nbsp; I have no idea what it is actually looking for.&amp;nbsp; Any idea or more information needed?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Dec 2015 17:04:42 GMT</pubDate>
    <dc:creator>sutter</dc:creator>
    <dc:date>2015-12-31T17:04:42Z</dc:date>
    <item>
      <title>Script issue with changing hostname</title>
      <link>https://communities.vmware.com/t5/VMware-Aria-Automation/Script-issue-with-changing-hostname/m-p/2705596#M23324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Having an odd problem and I'm not good enough with JavaScript to figure out what I'm doing wrong.&amp;nbsp; Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've add Kali Linux to my vRA build but sadly VMware does not have a customization file setting that will work with the newest Kali Linux build.&amp;nbsp; Not a big deal I just need to be able to change hostnames, I figured an easy way to do this would be to make a vRO workflow to change the hostname to whatever the user named their VM.&amp;nbsp; I've written it all up and added all the proper attributes in vRO and it is giving me a coding error.&amp;nbsp; I'm assuming what it is saying is miss labeled so hopefully someone can see what I've done wrong.&amp;nbsp; Here is the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;System.log("Workflow started from workflow stub " + externalWFStub + " on vCAC host " + vCACHost.displayName);&lt;/P&gt;&lt;P&gt;System.log("Got vCAC virtual machine " + vCACVm.virtualMachineName);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (vCenterVm != null) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; System.log("Got vCenter VM " + vCenterVm.name);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Displaying vCAC VM properties&lt;/P&gt;&lt;P&gt;if (vCACVmProperties != null) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; var log = "";&lt;/P&gt;&lt;P&gt;&amp;nbsp; log += "vCAC VM properties :\n";&lt;/P&gt;&lt;P&gt;&amp;nbsp; var array = new Array();&lt;/P&gt;&lt;P&gt;&amp;nbsp; for each (var key in vCACVmProperties.keys) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; array.push(key + " : " + vCACVmProperties.get(key));&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; array.sort();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; for each (var line in array) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; log += "\t" + line + "\n";&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; System.log(log);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Obtain build information from Blueprint&lt;/P&gt;&lt;P&gt;Build=vCACVmProperties.get('VirtualMachine.BuildType');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Obtain new hostname from VM&lt;/P&gt;&lt;P&gt;newHostName=vCACVmProperties.get('vCenterVM.name')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Set hostname on server through ssh&lt;/P&gt;&lt;P&gt;if (Build=='Kali'){&lt;/P&gt;&lt;P&gt;&amp;nbsp; username='root';&lt;/P&gt;&lt;P&gt;&amp;nbsp; password='password1';&lt;/P&gt;&lt;P&gt;&amp;nbsp; hostNameOrIP=vCACVmProperties.get('VirtualMachine.Network0.Address');&lt;/P&gt;&lt;P&gt;&amp;nbsp; cmd='sed -i -e "s/CURRENTHOSTNAME/' + newHostName '/g" /etc/hosts';&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simple enough, it pulls the machines information and runs an ssh command if it sees a build profile attribute that labels it as Kali.&amp;nbsp; The problem is the last lines.&amp;nbsp; The error I'm getting is "missing ; before statement (script#34) which is the line "cmd=hostname ' + newHostName ';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;username, password, hostNameOrIP and cmd are all variables in the workflow and if I delete the cmd line it takes the error away.&amp;nbsp; I have no idea what it is actually looking for.&amp;nbsp; Any idea or more information needed?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Dec 2015 17:04:42 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-Aria-Automation/Script-issue-with-changing-hostname/m-p/2705596#M23324</guid>
      <dc:creator>sutter</dc:creator>
      <dc:date>2015-12-31T17:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with changing hostname</title>
      <link>https://communities.vmware.com/t5/VMware-Aria-Automation/Script-issue-with-changing-hostname/m-p/2705597#M23325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First when you are declaring a new variable be sure to use var unless you intention is to make it globally accessible.&amp;nbsp; I'm guessing this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;Build=vCACVmProperties.get('VirtualMachine.BuildType');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px; line-height: 1.5em;"&gt;should be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;var &lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;Build=vCACVmProperties.get('VirtualMachine.BuildType');&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;I'm not positive how all the scoping shakes out in vRO but if you haven't read up on variable scoping in javascript I'd take a look here &lt;A href="http://www.w3schools.com/js/js_scope.asp" title="http://www.w3schools.com/js/js_scope.asp"&gt;JavaScript Scope&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;and I think this is the line you want for setting cmd:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: proxima-nova, Arial, sans-serif; font-size: 14px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;var cmd='sed -i -e \"s/CURRENTHOSTNAME/' + newHostName + '/g\" /etc/hosts';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to escape the " and also forgot a plust sign between the strings and the variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Jan 2016 02:00:18 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-Aria-Automation/Script-issue-with-changing-hostname/m-p/2705597#M23325</guid>
      <dc:creator>qc4vmware</dc:creator>
      <dc:date>2016-01-01T02:00:18Z</dc:date>
    </item>
  </channel>
</rss>

