Knife Azurerm
Knife Azure Overview
Microsoft Azure is a cloud hosting platform from Microsoft that provides virtual machines for Linux and Windows Server, cloud and database services, and more. Use the knife azure subcommand to manage API-driven cloud servers hosted by Microsoft Azure.
Note
knife-azure version 1.6.0 and later supports Azure Resource Manager. Commands starting with knife azurerm use the Azure Resource Manager API. Commands starting with knife azure use the Azure Service Management API. While you can switch between the two command sets, they are not designed to work together.
Install Chef Workstation
Install the latest version of Chef Workstation from Chef Downloads.
Installation
knife-azure ships in Chef Workstation. Install the latest version of Chef Workstation from Chef Downloads
Configuration
The knife azurem (ARM mode) requires setting up a service principal for authentication and permissioning. For setting up a service principal from the command line, see Create service principal with PowerShell / Azure CLI 2.0.
Note
After creating the service principal, you will have the values:
- client id (GUID)
- client secret(string)
- tenant id (GUID).
Put the following in your knife.rb
knife[:azure_tenant_id] # found via: tenantId=$(azure account show -s <subscriptionId> --json | jq -r '.[0].tenantId')
knife[:azure_subscription_id] # found via: <subscriptionId>
knife[:azure_client_id] # appId=$(azure ad app show --search <principleappcreated> --json | jq -r '.[0].appId')
knife[:azure_client_secret] # password you set at the beginning
Microsoft Azure encourages the use of Azure CLI 2.0. If you are still using azure-xplat-cli _then simply run azure login and skip creating the service principal.
Knife Azurerm Commands
server create
Use the server create argument to provision a new server in Azure and then perform a Chef bootstrap.
Syntax
This argument has the following syntax:
knife azurerm server create (options)
Options
This argument has the following options:
-
-a,--azure-storage-account NAME Required for advanced server-create option. A name for the storage account that is unique within Windows Azure. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. This name is the DNS prefix name and can be used to access blobs, queues, and tables in the storage account. For example: http://ServiceName.blob.core.windows.net/mycontainer/
--azure-availability-set NAMEName of availability set to add virtual machine into.
--azure-extension-client-config CLIENT_PATHPath to a client.rb file for use by the bootstrapped node.
--azure-image-os-type OSTYPESpecifies the image OS Type for which server needs to be created. Accepted values:
ubuntu,centos,rhel,debian,windows.--azure-image-reference-offer OFFERSpecifies the offer of the image used to create the virtual machine. eg. CentOS, UbuntuServer, WindowsServer.
--azure-image-reference-publisher PUBLISHER_NAMESpecifies the publisher of the image used to create the virtual machine. eg. OpenLogic Canonical, MicrosoftWindowsServer.
--azure-image-reference-sku SKUSpecifies the SKU of the image used to create the virtual machine.
--azure-image-reference-version VERSIONSpecifies the version of the image used to create the virtual machine. Default: ‘latest’.
--azure-resource-group-name RESOURCE_GROUP_NAMEThe Resource Group name.
--azure-storage-account-type TYPEOne of the following account types (case-sensitive):
Standard_LRS(Standard Locally-redundant storage);Standard_ZRS(Standard Zone-redundant storage);Standard_GRS(Standard Geo-redundant storage);Standard_RAGRS(Standard Read access geo-redundant storage);Premium_LRS(Premium Locally-redundant storage).--azure-vm-name NAMERequired. Specifies the name for the virtual machine. The name must be unique within the ResourceGroup. Maximum length: 15 characters.
--azure-vm-size SIZESize of virtual machine. Values:
ExtraSmall,Small,Medium,Large,ExtraLarge.--azure-vnet-name VNET_NAMESpecifies the virtual network name. This may be the name of an existing vnet present under the given resource group or this may be the name of a new vnet to be added in the given resource group. If not specified then azure-vm-name will be taken as the default name for vnet name as well. Along with this option, the
azure-vnet-subnet-nameoption can also be specified or skipped.--azure-vnet-subnet-name VNET_SUBNET_NAMESpecifies the virtual network subnet name. Must be specified only with
azure-vnet-nameoption. This may be the name of an existing subnet present under the given virtual network or this may be the name of a new subnet to be added virtual network. If not specified thenazure-vm-namewill be taken as name for subnet name as well. Note:GatewaySubnetcannot be used as the name for the--azure-vnet-subnet-nameoption.--bootstrap-proxy PROXY_URLThe proxy server for the node being bootstrapped.
--bootstrap-version VERSIONThe version of Chef to install.
-
-c,--config CONFIG The configuration file to use.
--cert-passphrase PASSWORDSSL Certificate Password.
--cert-path PATHSSL Certificate Path.
--chef-daemon-interval INTERVALIt specifies the frequency (in minutes) at which the chef-service runs. Pass 0 if you don’t want the chef-service to be installed on the target machine.
--chef-zero-host HOSTHost for starting chef-zero.
--chef-zero-port PORTPort (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works.
--[no-]colorUse colored output. Default:
enabled--config-option OPTION=VALUEOverride a single configuration option.
-
-d,--disable-editing Accept the data without opening the editor.
--daemon DAEMONConfigures the Chef Infra Client service for unattended execution. Requires
--bootstrap-protocolto becloud-apiand the node platform to beWindows. Options: ‘none’ or ‘service’ or ‘task’. ‘none’ - Currently prevents the Chef Infra Client service from being configured as a service. ‘service’ - Configures Chef Infra Client to run automatically in the background as a service. ‘task’ - Configures Chef Infra Client to run automatically in the background as a scheduled task.--defaultsAccept default values for all questions
-
-e,--editor EDITOR Set the editor to use for interactive commands
-
-E,--environment ENVIRONMENT Set the Chef environment (except for in searches, where this will be flagrantly ignored)
--extended-logsIt shows chef convergence logs in detail.
-
-F,--format FORMAT Which format to use for output
--[no-]fipsEnable fips mode
-
-h,--help Show this message
-
-j,--json-attributes JSON A JSON string to be added to the first run of Chef Infra Client
--[no-]listenWhether a local mode (-z) server binds to a port
-
-k,--key KEY API Client Key
-
-m LOCATION,--azure-service-location Required if not using an Affinity Group. Specifies the geographic location - the name of the data center location that is valid for your subscription. Eg: westus, eastus, eastasia, southeastasia, northeurope, westeurope
-
-N,--node-name NAME The Chef node name for your new node
-
-o DISKNAME,--azure-os-disk-name Specifies the friendly name of the disk containing the guest OS image in the image repository.
--node-ssl-verify-mode [peer|none]Whether or not to verify the SSL cert for all HTTPS requests.
--[no-]node-verify-api-certVerify the SSL cert for HTTPS requests to the Chef Infra Server API.
--ohai-hints HINT_OPTIONSHint option names to be set in Ohai configuration the target node. Values:
vm_name,public_fqdnand platform. User can pass any comma separated combination of these values likevm_name,public_fqdn. Default:defaultwhich corresponds to supported values list mentioned here.--print-afterShow the data after a destructive operation
--profile PROFILEThe credentials profile to select
-
-r,--run-list RUN_LIST Comma separated list of roles/recipes to apply
-
-s,--secret The secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key ‘secret’
--secret-file SECRET_FILEA file containing the secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key ‘secret_file’
--server-count COUNTNumber of servers to create with same configuration. Maximum: 5. Default: 1.
--server-url URLChef Infra Server URL
--ssh-password PASSWORDThe ssh password
--ssh-port PORTThe ssh port. Default: 22.
--ssh-public-key FILENAMEIt is the ssh-rsa public key path. Specify either
ssh-passwordorssh-public-key.--ssh-user USERNAMEThe ssh username
-
-t,--tcp-endpoints PORT_LIST Comma-separated list of TCP ports to open e.g. ‘80,433’
--thumbprint THUMBPRINTThe thumprint of the ssl certificate
-
-u,--user USER API Client Username
-
-v,--version Show Chef version
-
-V,--verbose More verbose output. Use twice for max verbosity.
-
-P,--winrm-password PASSWORD The WinRM password
-
-x,--winrm-user USERNAME The WinRM username
-
-y,--yes Say yes to all prompts for confirmation
-
-z,--local-mode Point knife commands at local repository instead of server
knife azurerm server delete SERVER [SERVER] (options)
server delete
Use the server delete argument to delete existing ARM servers configured in the Azure account.
Syntax
This argument has the following syntax:
knife azurerm server delete (options)
Options
This argument has the following options:
-
-c,--config CONFIG The configuration file to use.
--chef-zero-host HOSTHost for starting chef-zero.
--chef-zero-port PORTPort (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works.
--[no-]colorUse colored output, defaults to enabled.
--config-option OPTION=VALUEOverride a single configuration option.
-
-d,--disable-editing Accept the data without opening the editor.
--defaultsAccept default values for all questions.
--delete-resource-groupDeletes corresponding resource group along with VirtualMachine.
-
-e,--editor EDITOR Set the editor to use for interactive commands.
-
-E,--environment ENVIRONMENT Set the Chef environment, except for use in searching.
-
-F,--format FORMAT Which format to use for output.
--[no-]fipsEnable fips mode.
-
-h,--help Show the help message
-
-k,--key KEY API Client Key.
--[no-]listenWhether a local mode (-z) server binds to a port.
-
-N,--node-name NAME The unique identifier of the node and client to delete, if it differs from the server name. Only has meaning when used with the ‘–purge’ option.
--print-afterShow the data after a destructive operation.
--profile PROFILEThe credentials profile to select.
-
-P,--purge Destroy corresponding node and client on the ChefServer, in addition to destroying the Windows Azure node itself. Assumes node and client have the same name as the server (if not, add the ‘–node-name’ option).
-
-r RESOURCE_GROUP_NAME,--azure-resource-group-name The Resource Group name.
-
-s,--server-url URL Chef Infra Server URL.
-
-u,--user USER API Client Username
-
-v,--version Show chef version
-
-V,--verbose More verbose output. Use twice for maximum verbosity.
-
-y,--yes Say yes to all prompts for confirmation.
-
-z,--local-mode Point knife commands at local repository instead of at the server.
server list
Use the server list argument to output a list of all ARM servers–including those not managed by the Chef server—in the Azure account.
Syntax
This argument has the following syntax:
knife azurerm server list (options)
Options
This argument has the following options:
-
-c,--config CONFIG The configuration file to use.
--chef-zero-host HOSTHost for starting chef-zero.
--chef-zero-port PORTPort (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works.
--[no-]colorUse colored output, defaults to enabled.
--config-option OPTION=VALUEOverride a single configuration option.
-
-d,--disable-editing Accept the data without opening the editor.
--defaultsAccept default values for all questions.
-
-e,--editor EDITOR Set the editor to use for interactive commands.
-
-E,--environment ENVIRONMENT Set the Chef environment, except for use in searching.
-
-F,--format FORMAT Which format to use for output.
--[no-]fipsEnable fips mode.
-
-h,--help Show the help message
-
-k,--key KEY API Client Key.
--[no-]listenWhether a local mode (-z) server binds to a port.
--print-afterShow the data after a destructive operation.
--profile PROFILEThe credentials profile to select.
-
-r RESOURCE_GROUP_NAME,--azure-resource-group-name The Resource Group name.
-
-s,--server-url URL Chef Infra Server URL.
-
-u,--user USER API Client Username
-
-v,--version Show chef version
-
-V,--verbose More verbose output. Use twice for maximum verbosity.
-
-y,--yes Say yes to all prompts for confirmation.
-
-z,--local-mode Point knife commands at local repository instead of at the server.
server show
Use the server show argument to output the details of an ARM server in the Azure account.
Syntax
This argument has the following syntax:
knife azurerm server show (options)
Options
This argument has the following options:
-
-c,--config CONFIG The configuration file to use.
--chef-zero-host HOSTHost for starting chef-zero.
--chef-zero-port PORTPort (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works.
--[no-]colorUse colored output, defaults to enabled.
--config-option OPTION=VALUEOverride a single configuration option.
-
-d,--disable-editing Accept the data without opening the editor.
--defaultsAccept default values for all questions.
-
-e,--editor EDITOR Set the editor to use for interactive commands.
-
-E,--environment ENVIRONMENT Set the Chef environment, except for use in searching.
-
-F,--format FORMAT Which format to use for output.
--[no-]fipsEnable fips mode.
-
-h,--help Show the help message
-
-k,--key KEY API Client Key.
--[no-]listenWhether a local mode (-z) server binds to a port.
--print-afterShow the data after a destructive operation.
--profile PROFILEThe credentials profile to select.
-
-r RESOURCE_GROUP_NAME,--azure-resource-group-name The Resource Group name.
-
-s,--server-url URL Chef Infra Server URL.
-
-u,--user USER API Client Username
-
-v,--version Show chef version
-
-V,--verbose More verbose output. Use twice for maximum verbosity.
-
-y,--yes Say yes to all prompts for confirmation.
-
-z,--local-mode Point knife commands at local repository instead of at the server.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/workstation/knife_azurerm/