New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packer ARM Succeeded - Now What? #201

Closed
ndouba opened this Issue Feb 9, 2016 · 7 comments

Comments

Projects
None yet
6 participants
@ndouba

ndouba commented Feb 9, 2016

So the packer script succeeded after assigning the application I created with the Owner role to the Subcription object. I see the blob in my storage account but now I'm stuck at figuring out how we actually hydrate that image into a running VM? There doesn't seem to be any functionality in the Azure portal to do that. Could you please advise on the recommended steps?

@boumenot

This comment has been minimized.

Show comment
Hide comment
@boumenot

boumenot Feb 10, 2016

Member

The latest Azure portal does not currently provide too much if you just want to deploy and go.. 😦 All of the legos are exposed, and you need (get?) to build them the way you want. We are working on making improving the experience.

At the end of a packer build you will have a template (.json), and a .vhd.

Portal

  1. Create a NIC for you VM, and attach it the appropriate Virtual Network and Subnet. Click + New > See all > Search for "Network Interface" > Select "Network interface > Create. Locate the NIC you just created, and copy the Resource ID (located under properties).
  2. Locate the template file, and copy the contents.
  3. Click + New > Template Deployment > Edit Template, and paste the contents of the template over all existing data. Click save.
  4. Edit Parameters - provide appropriate values for your template, you will be prompted for all of values that are required. The hardest value to supply in my case is networkInterfaceId, which is a fully qualified resource string of the form "/subscription/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/networkInterfaces/{name}. If you do not have one, you will need to create one in the portal or via the CLI.

Azure CLI:

Assuming these are the names of our resources.

  • Resource Group: MyResourceGroup
  • Location: westus
  • Virtual Network: MyVirtualNetwork
  • Subnet: MySubnet
  • Deployment Name: MyDeployment
  • Template URI: https://... (copy the URI from the portal, or download it and reference it directly.)
  • NIC: MyNic

Create a NIC.

azure network nic create MyResourceGroup MyNic westus --subnet-vnet-name MyVirtualNetwork --subnet-name MySubnet

The above command will out an Id for the NIC just created. Copy it, and use it in the command below.

Deploy a VM based on our image.

azure group deployment create -g MyResourceGroup -n MyDeployment --template-uri https://...

The above command will automatically prompt you for all of the values in the template that need to be set, such as vmName, adminUserName, adminPassword, and networkInterfaceId.

HTH.

Member

boumenot commented Feb 10, 2016

The latest Azure portal does not currently provide too much if you just want to deploy and go.. 😦 All of the legos are exposed, and you need (get?) to build them the way you want. We are working on making improving the experience.

At the end of a packer build you will have a template (.json), and a .vhd.

Portal

  1. Create a NIC for you VM, and attach it the appropriate Virtual Network and Subnet. Click + New > See all > Search for "Network Interface" > Select "Network interface > Create. Locate the NIC you just created, and copy the Resource ID (located under properties).
  2. Locate the template file, and copy the contents.
  3. Click + New > Template Deployment > Edit Template, and paste the contents of the template over all existing data. Click save.
  4. Edit Parameters - provide appropriate values for your template, you will be prompted for all of values that are required. The hardest value to supply in my case is networkInterfaceId, which is a fully qualified resource string of the form "/subscription/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/networkInterfaces/{name}. If you do not have one, you will need to create one in the portal or via the CLI.

Azure CLI:

Assuming these are the names of our resources.

  • Resource Group: MyResourceGroup
  • Location: westus
  • Virtual Network: MyVirtualNetwork
  • Subnet: MySubnet
  • Deployment Name: MyDeployment
  • Template URI: https://... (copy the URI from the portal, or download it and reference it directly.)
  • NIC: MyNic

Create a NIC.

azure network nic create MyResourceGroup MyNic westus --subnet-vnet-name MyVirtualNetwork --subnet-name MySubnet

The above command will out an Id for the NIC just created. Copy it, and use it in the command below.

Deploy a VM based on our image.

azure group deployment create -g MyResourceGroup -n MyDeployment --template-uri https://...

The above command will automatically prompt you for all of the values in the template that need to be set, such as vmName, adminUserName, adminPassword, and networkInterfaceId.

HTH.

@boumenot boumenot added the question label Feb 10, 2016

@paulmey

This comment has been minimized.

Show comment
Hide comment
@paulmey

paulmey Mar 23, 2016

Member

We should at least create a post-processor for this...

Member

paulmey commented Mar 23, 2016

We should at least create a post-processor for this...

@Ancillas

This comment has been minimized.

Show comment
Hide comment
@Ancillas

Ancillas Mar 24, 2016

@paulmey What would a post-processor look like for this? Doesn't the process of creating a NIC, and then a VM, have to occur every time the custom VHD is used?

Ancillas commented Mar 24, 2016

@paulmey What would a post-processor look like for this? Doesn't the process of creating a NIC, and then a VM, have to occur every time the custom VHD is used?

@paulmey

This comment has been minimized.

Show comment
Hide comment
@paulmey

paulmey Mar 24, 2016

Member

@Ancillas The builder deploys the initial VM with a template specifying all these resources. A post-processor could do the same thing. IIRC, there should be a json with a template left next to the vhd. See also #220, where we were discussing what the builder artifact should contain.

Member

paulmey commented Mar 24, 2016

@Ancillas The builder deploys the initial VM with a template specifying all these resources. A post-processor could do the same thing. IIRC, there should be a json with a template left next to the vhd. See also #220, where we were discussing what the builder artifact should contain.

@pburkholder

This comment has been minimized.

Show comment
Hide comment
@pburkholder

pburkholder Jan 20, 2017

Here's the CLI guide for folks who are still finding their way around Packer and AzureRM:

Create the NIC

Assuming you're using the same ARM_RESOURCE_GROUP and LOCATION from packer build:

az network vnet create \
  -g $ARM_RESOURCE_GROUP -l $LOCATION \
  --name PackerVirtualNetwork --address-prefix 10.0.0.0/16

az network vnet subnet create \
  -g $ARM_RESOURCE_GROUP \
  --vnet-name PackerVirtualNetwork \
  -n PackerSubnet --address-prefix 10.0.1.0/24

az network nic create \
  -g $ARM_RESOURCE_GROUP \
  --vnet-name PackerVirtualNetwork \
  --subnet PackerSubnet \
  -n PackerDemoNic

This last command will spit out a lot JSON, you'll want the line that looks like this:

"id": "/subscriptions/12345678-abcd-1234-5678-1234567890ab/resourceGroups/my_dev_packer/providers/Microsoft.Network/networkInterfaces/PackerDemoNic/ipConfigurations/ipconfig1",

Create a params files

The newer azure-cli doesn't prompt for template params, so I created x.parameters.json file like this:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "PackerDemoVm"
    },
    "adminUserName": {
      "value": "PackerDemoVm"
    },
    "adminPassword": {
      "value": "PackerD3moVm%%"
    },
    "networkInterfaceId": {
      "value": "/subscriptions/12345678-abcd-1234-5678-1234567890ab/resourceGroups/my_dev_packer/providers/Microsoft.Network/networkInterfaces/PackerDemoNic"
    }
  }
}

Run create with template-uri and parameters

Then I could run az group create:

az group deployment create -g $ARM_RESOURCE_GROUP \
  -n PackerDeployment \
  --parameters @x.parameters.json \
  --template-uri \
  'https://....

Since there's no public IP associated with the instance here, it cant actually be reached, but it should exist.

HTH, Peter

pburkholder commented Jan 20, 2017

Here's the CLI guide for folks who are still finding their way around Packer and AzureRM:

Create the NIC

Assuming you're using the same ARM_RESOURCE_GROUP and LOCATION from packer build:

az network vnet create \
  -g $ARM_RESOURCE_GROUP -l $LOCATION \
  --name PackerVirtualNetwork --address-prefix 10.0.0.0/16

az network vnet subnet create \
  -g $ARM_RESOURCE_GROUP \
  --vnet-name PackerVirtualNetwork \
  -n PackerSubnet --address-prefix 10.0.1.0/24

az network nic create \
  -g $ARM_RESOURCE_GROUP \
  --vnet-name PackerVirtualNetwork \
  --subnet PackerSubnet \
  -n PackerDemoNic

This last command will spit out a lot JSON, you'll want the line that looks like this:

"id": "/subscriptions/12345678-abcd-1234-5678-1234567890ab/resourceGroups/my_dev_packer/providers/Microsoft.Network/networkInterfaces/PackerDemoNic/ipConfigurations/ipconfig1",

Create a params files

The newer azure-cli doesn't prompt for template params, so I created x.parameters.json file like this:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "PackerDemoVm"
    },
    "adminUserName": {
      "value": "PackerDemoVm"
    },
    "adminPassword": {
      "value": "PackerD3moVm%%"
    },
    "networkInterfaceId": {
      "value": "/subscriptions/12345678-abcd-1234-5678-1234567890ab/resourceGroups/my_dev_packer/providers/Microsoft.Network/networkInterfaces/PackerDemoNic"
    }
  }
}

Run create with template-uri and parameters

Then I could run az group create:

az group deployment create -g $ARM_RESOURCE_GROUP \
  -n PackerDeployment \
  --parameters @x.parameters.json \
  --template-uri \
  'https://....

Since there's no public IP associated with the instance here, it cant actually be reached, but it should exist.

HTH, Peter

@mohdfayez

This comment has been minimized.

Show comment
Hide comment
@mohdfayez

mohdfayez Jun 23, 2018

Hey Everyone,

Wondering if packer can be used to generate a custom rhel/centos image for azure. (Azure uses a set of steps for Hyper-V - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/redhat-create-upload-vhd), The image I am referring to is not from any publishers from market place or aws, instead the image contains the OS plus a set of customizations that include separate filesystems / /home, etc to name a few, so when I build my VM through packer, the VM already contains all these I am looking for.

Or the right way to go with using packer to provision Azure VMs is to first have this custom .vhd file ready as depicted in the link here https://docs.microsoft.com/en-us/azure/virtual-machines/linux/redhat-create-upload-vhd and use that VHD to build VMs on Azure? Now with this same VHD, can packer be used to provision VMs on other platforms like aws, vmware, etc?

Much appreciated.
Thanks.

mohdfayez commented Jun 23, 2018

Hey Everyone,

Wondering if packer can be used to generate a custom rhel/centos image for azure. (Azure uses a set of steps for Hyper-V - https://docs.microsoft.com/en-us/azure/virtual-machines/linux/redhat-create-upload-vhd), The image I am referring to is not from any publishers from market place or aws, instead the image contains the OS plus a set of customizations that include separate filesystems / /home, etc to name a few, so when I build my VM through packer, the VM already contains all these I am looking for.

Or the right way to go with using packer to provision Azure VMs is to first have this custom .vhd file ready as depicted in the link here https://docs.microsoft.com/en-us/azure/virtual-machines/linux/redhat-create-upload-vhd and use that VHD to build VMs on Azure? Now with this same VHD, can packer be used to provision VMs on other platforms like aws, vmware, etc?

Much appreciated.
Thanks.

@boumenot

This comment has been minimized.

Show comment
Hide comment
@boumenot

boumenot Jun 25, 2018

Member

Yes, you can start from a custom image. Please review https://www.packer.io/docs/builders/azure.html. Using the same image on Azure, AWS, and VMware will be trickier. My default opinion, having never done this, is to instead create a common recipe for building the image, and then use the builder from each cloud provider with your common recipe. I am sure you could make one image work, but you would have to deal with all of the various platform issues (kernel drivers, services, etc), which may not be worth it.

There are examples in the official Packer repository to help get you started.

  1. https://github.com/hashicorp/packer/blob/master/examples/azure/linux_custom_image.json
  2. https://github.com/hashicorp/packer/blob/master/examples/azure/linux_custom_managed_image.json
Member

boumenot commented Jun 25, 2018

Yes, you can start from a custom image. Please review https://www.packer.io/docs/builders/azure.html. Using the same image on Azure, AWS, and VMware will be trickier. My default opinion, having never done this, is to instead create a common recipe for building the image, and then use the builder from each cloud provider with your common recipe. I am sure you could make one image work, but you would have to deal with all of the various platform issues (kernel drivers, services, etc), which may not be worth it.

There are examples in the official Packer repository to help get you started.

  1. https://github.com/hashicorp/packer/blob/master/examples/azure/linux_custom_image.json
  2. https://github.com/hashicorp/packer/blob/master/examples/azure/linux_custom_managed_image.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment