Second interface Linux bash script - ubuntu-16.04

I was wondering if it's possible to automatically assign an IP address to my second openstack VM. I'm looking for some sort of script that adds the interface during my cloud init, of Packer build.
Kind regards

Related

How to run a powershell script on Amazon EC2 instance at Startup?

I have to think this is a solved issue but I am just not getting it to work. So I have come to you StackOverflow with this issue:
I have a windows server 2016 machine running in amazon ec2. I have a machine.ps1 script in a config directory.
I create an image of the box. (I have tried with checking noreboot and unchecking it)
When I create a new instance of the image I want it to run machine.ps1 at launch to set the computer name and then set routes and some config settings for the box. The goal is to do this without logging into the box.
I have read and tried:
Running Powershell scripts at Start up
and used this to ensure user data was getting passed in:
EC2 Powershell Launch Tools
I have tried setting up a scheduled task that runs the machine.ps1 on start up (It just hangs)
I see the initializeInstance.ps1 on start up task and have tried to even coop that replacing the line to run userdata with the line to run my script. Nothing.
If I log into the box and run machine.ps1, it will restart the computer and set the computer name and then I need to run it once more to set routes. This works manually. I just need to find a way to do it automagically.
I want to launch these instances from powershell not with launch configurations and auto scale.
You can use User data
Whenever you deploy a new server, workstation or virtual machine there is nearly always a requirement to make final changes to the system before it’s ready for use. Typically this is normally done with a post-deployment script that might be triggered manually on start-up or it might be a final step in a Configuration Manager task sequence or if you using Azure you may use the Custom Script Extension. So how do you achieve similar functionality using EC2 instances in Amazon Web Services (AWS)? If you’ve created your own Amazon Machine Image (AMI) you can set the script to run from the Runonce registry key, but then can be a cumbersome approach particularly if you want to make changes to the script and it’s been embedded into the image. AWS offers a much more dynamic method of injecting a script to run upon start-up through a feature called user data.
Please refer following link for ther same:
Poershell User data
Windows typically won't let a powershell script call another powershell script unless it is being run as Administrator. It is a weird 'safety' feature. But it is perfectly okay to load the ps1 files and use any functions inside them.
The UserData script is typically run as "system". You would THINK that would pass muster. But it fails...
The SOLUTION: Make ALL of your scripts into powershell functions instead.
In your machine.ps1 - wrap the contents with function syntax
function MyDescriptiveName { <original script contents> }
Then in UserData - use the functions like this
# To use a relative path
Set-Location -Path <my location>
# Load script file into process memory
. <full-or-relpath>/machine.ps1
# Call function
MyDescriptiveName <params-if-applicable>
If the function needs to call other functions (aka scripts), you'll need to make those scripts into functions and load the script file into process memory in UserData also.

In chef how is it possible to generate a variable from a recipe and another recipe to use that variable?

I want a recipe which will run on a client to create a variable which will store the FQDN of the client and another recipe which will run on another server to use that variable .how is that possible in chef.
Looks like you are looking for service discovery, Chef might not be the best tool for this job. However, if your client is running Chef, its FQDN is already stored in Chef server. You can pull it in various ways. For example
client_node = search(:node, "recipes:client_cookbook::client_recipe")
Then you can access client's FQDN from the node mash - client_node["fqdn"].

powershell script for connecting HyperV VMM and create a VM from specific template

does anyone know is there a way we can connect HyperV-VMM and create a VM using particular template using powershell ?
Yes it is possible. The best way to get started with this is to create the template in VMM and go through the creation process for the vm. Before you finish creating it though, on the last page in the bottom corner, you will see a view script button. This actually gives you the powershell version of what is being performed from the GUI.

How to run a script on a new Hyper-V Windows VMM virtual machine

I use a powershell script, triggered by teamcity, to spin up new Windows Server VMs. Currently, when the machine is up and running, I need to log in via the VMM console to make a couple of configuration changes (enable file sharing, network discovery, msdeploy and remoting over winrm) in order to allow other teamcity jobs to be able to deploy enterprise apps to the VM.
I haven't found any way to run my config setup scripts on the new VM other than by using the GUI console in VMM. For VMHosts, there is Invoke-SCScriptCommand, but this doesn't work for virtual machines themselves. Am I missing something or do I have to alter the template that my VM's are built from, in order to get the required config on the VMs?
One way you could achieve what you require is by putting all your config changes in a powershell script sitting inside VM template and adding it to VM's startup scripts.
The script's first step is checks whether the config changes have been applied in the past by checking some kind of a flag(ie. a file c:\deployed.flag) and last step is to create the flag.
if(Test-Path c:\deployed.flag){
## deployment script run already, do nothing
}
else{
## your config changing code block
New-Item c:\deployed.flag -Type f
}
In VMWare/PowerCLI you can run Invoke-VMScript which executes command directly on a VM via VMWare tools but alas Hyper-V Integration Services don't have such functionality.

Azure: Change VM name using Cmdlets

I erroneously named a virtual machine.
Using the Azure Powershell I am able to rename cloud services using Set-AzureService. There doesn't seem to be a Set-AzureVM command to rename virtual machines.
Is there another way to rename a virtual machine? I do not wish to change the VM's service name.
EDIT, further clarity:
I do NOT want to rename the cloud service name or the machine/computer name in the VM instance. I purely wish to change the associated name that my virtual machine is labeled with. i.e. the name you see in the portal
The names in the column with the red arrow:
Set-AzureService does not change service name! It only changes deployment name and description. These properties are just kind of Meta-Data associated with the hosted service deployment. You cannot change cloud service name (**cloudservice**.cloudapp.net) by any means! You can only create or delete cloud service.
And, not you can't change VM's name via Azure PowerShell cmdlets, but most probably you can do this by remote power shell to the targeted VM. Please note that renaming a Windows machine always requires restart!
For information on how to use Remote Power Shell on Azure VM, please check out this article.
UPDATE
I think what you need is the UpdateRole action on the management API. It has parameter RoleName which is desribed as:
RoleName
Required. Specifies the name for the virtual machine. The name must be unique within Windows Azure.
And the powershell cmdlet to use is: Update-AzureVM