-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Azure Automation Tutorial template #332
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98f8e35
Adding Azure Automation 101 deployment template
elcooper 33ce99a
minor template modifications
elcooper c8030ed
Merge pull request #1 from Azure/master
elcooper 3f1d0c5
modified username in readme
elcooper 17b8e12
Merge branch 'master' of https://github.com/elcooper/azure-quickstart…
elcooper 193e023
adding comma to metadata file
elcooper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| | ||
| #Connect to your Azure account | ||
| Add-AzureAccount | ||
|
|
||
| #Select your subscription if you have more than one | ||
| #Select-AzureSubscription -SubscriptionName "My Subscription Name" | ||
|
|
||
| #Create a GUID for the job | ||
| $JobGUID = [System.Guid]::NewGuid().toString() | ||
|
|
||
| #Use Azure resource Manager to deploy template | ||
| Switch-AzureMode -Name AzureResourceManager | ||
|
|
||
| #Set the parameter values for the template | ||
| $Params = @{ | ||
| "accountName" = "MyAccount" ; | ||
| "jobId" = $JobGUID; | ||
| "regionId" = "Japan East"; | ||
| "credentialName" = "DefaultAzureCredential"; | ||
| "userName" = "MyUserName"; | ||
| "password" = "MyPassword" | ||
| } | ||
|
|
||
| $TemplateURI = "https://raw.githubusercontent.com/azureautomation/resources/master/automation-packs/101-get-vm-tutorial/deployAutomationResources.json" | ||
|
|
||
| New-AzureResourceGroupDeployment -TemplateParameterObject $Params -ResourceGroupName "MyResourceGroup" -TemplateUri $TemplateURI | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Create VM tutorial runbook, Automation credential, and start a job | ||
|
|
||
| This sample shows how you can deploy a runbook, a credential the runbook relies on, and how to start a job through an Azure Resource Manager template. | ||
|
|
||
| It contains a sample script, Deploy-ThroughARM, that you can use to get you started with the deployment. | ||
|
|
||
| ##Resources Deployed | ||
| ###Automation Account | ||
| This is the account that will contain your credentials. If you want to deploy to an existing account, make sure that the Resource Group, region, tags, and SKU in the template are all the same as your existing account, otherwise the properties will be overwritten. | ||
|
|
||
| ###Runbook | ||
| The runbook provides an example of how you can authenticate to Azure and use Azure cmdlets in a runbook. It uses an Azure AD organizational ID to connect to Azure. It then prints out the first 10 VMs in your account. | ||
|
|
||
| ###Credential | ||
| The credential should contain the username and password of the Azure AD organizalation ID to connect to Azure. To learn about how to create this user, see [Get set up to automate Azure]("http://aka.ms/getsetuptoautomate") and check out this blog post [Authenticating to Azure using Active Directory]("http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/"). | ||
|
|
||
| ###Job | ||
| A job will be triggered once the other resources are deployed. The job needs a unique GUID as the jobId. You can use this to identify the job later in your script and to retrieve the job output. |
39 changes: 39 additions & 0 deletions
39
101-automation-runbook-getvms/Runbooks/Get-AzureVMTutorial.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <# | ||
| .DESCRIPTION | ||
| An example runbook which prints out the first 10 Azure VMs in your subscription (ordered alphabetically). | ||
| For more information about how this runbook authenticates to your Azure subscription, see our documentation here: http://aka.ms/fxu3mn | ||
|
|
||
| .NOTES | ||
| AUTHOR: Azure Automation Team | ||
| LASTEDIT: Mar 27, 2015 | ||
| #> | ||
| workflow Get-AzureVMTutorial | ||
| { | ||
| #The name of the Automation Credential Asset this runbook will use to authenticate to Azure. | ||
| $CredentialAssetName = 'DefaultAzureCredential' | ||
|
|
||
| #Get the credential with the above name from the Automation Asset store | ||
| $Cred = Get-AutomationPSCredential -Name $CredentialAssetName | ||
| if(!$Cred) { | ||
| Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account." | ||
| } | ||
|
|
||
| #Connect to your Azure Account | ||
| $Account = Add-AzureAccount -Credential $Cred | ||
| if(!$Account) { | ||
| Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct." | ||
| } | ||
|
|
||
| #TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used. | ||
| #Select-AzureSubscription -SubscriptionName "TODO: your Azure subscription name here" | ||
|
|
||
| #Get all the VMs you have in your Azure subscription | ||
| $VMs = Get-AzureVM | ||
|
|
||
| #Print out up to 10 of those VMs | ||
| if(!$VMs) { | ||
| Write-Output "No VMs were found in your subscription." | ||
| } else { | ||
| Write-Output $VMs[0..9] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "accountName": { | ||
| "value": "MyAutomationAccount" | ||
| }, | ||
| "jobId": { | ||
| "value": "e6abf1fd-6311-4442-ac1a-22aae3cacdae" | ||
| }, | ||
| "regionId": { | ||
| "value": "East US 2" | ||
| }, | ||
| "credentialName": { | ||
| "value": "DefaultAzureCredential" | ||
| }, | ||
| "userName": { | ||
| "value": "MyAzureADUser" | ||
| }, | ||
| "password": { | ||
| "value": "MyAzureADPassword" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| { | ||
| "$schema": "http://schemas.microsoft.org/azure/deploymentTemplate?api-version=2015-01-01-preview#", | ||
| "contentVersion": "1.0", | ||
| "parameters": { | ||
| "accountName": { | ||
| "type": "string", | ||
| "metadata": { | ||
| "description": "The name of the Azure Automation account to deploy to." | ||
| } | ||
| }, | ||
| "regionId": { | ||
| "type": "string", | ||
| "allowedValues": [ | ||
| "Japan East", | ||
| "East US 2", | ||
| "West Europe", | ||
| "Southeast Asia", | ||
| "South Central US" | ||
| ], | ||
| "metadata": { | ||
| "description": "The region to deploy the Automation account in." | ||
| } | ||
| }, | ||
| "credentialName": { | ||
| "type": "string", | ||
| "metadata": { | ||
| "description": "DefaultAzureCredential is the name of the Automation credential used in this runbook. This credential allows you to authenticate to Azure. " | ||
| } | ||
| }, | ||
| "userName": { | ||
| "type": "string", | ||
| "metadata": { | ||
| "description": "The username for the Azure Automation credential." | ||
| } | ||
| }, | ||
| "password": { | ||
| "type": "string", | ||
| "metadata": { | ||
| "description": "The password for the Azure Automation credential." | ||
| } | ||
| }, | ||
| "jobId": { | ||
| "type": "string", | ||
| "metadata": { | ||
| "description": "The GUID for the runbook job to be started." | ||
| } | ||
| } | ||
| }, | ||
| "variables": { | ||
| "runbookName": "Get-AzureVMTutorial", | ||
| "scriptUri": "https://raw.githubusercontent.com/azureautomation/resources/master/automation-packs/101-get-vm-tutorial/Get-AzureVMTutorial.ps1", | ||
| "runbookDescription": "Authenticates to Azure and lists all the Azure V1 VMs", | ||
| "sku": "Free" | ||
| }, | ||
| "resources": [ | ||
| { | ||
| "name": "[parameters('accountName')]", | ||
| "type": "Microsoft.Automation/automationAccounts", | ||
| "apiVersion": "2015-01-01-preview", | ||
| "location": "[parameters('regionId')]", | ||
| "dependsOn": [], | ||
| "tags": {}, | ||
| "properties": { | ||
| "sku": { | ||
| "name": "[variables('sku')]" | ||
| } | ||
| }, | ||
| "resources": [ | ||
| { | ||
| "name": "[variables('runbookName')]", | ||
| "type": "runbooks", | ||
| "apiVersion": "2015-01-01-preview", | ||
| "location": "[parameters('regionId')]", | ||
| "dependsOn": [ | ||
| "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]" | ||
| ], | ||
| "tags": {}, | ||
| "properties": { | ||
| "runbookType": "Script", | ||
| "logProgress": "false", | ||
| "logVerbose": "false", | ||
| "description": "[variables('runbookDescription')]", | ||
| "publishContentLink": { | ||
| "uri": "[variables('scriptUri')]", | ||
| "version": "1.0.0.0" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "name": "[parameters('credentialName')]", | ||
| "type": "credentials", | ||
| "apiVersion": "2015-01-01-preview", | ||
| "location": "[parameters('regionId')]", | ||
| "dependsOn": [ | ||
| "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]" | ||
| ], | ||
| "tags": {}, | ||
| "properties": { | ||
| "userName": "[parameters('userName')]", | ||
| "password": "[parameters('password')]" | ||
| } | ||
| }, | ||
| { | ||
| "name": "[parameters('jobId')]", | ||
| "type": "jobs", | ||
| "apiVersion": "2015-01-01-preview", | ||
| "location": "[parameters('regionId')]", | ||
| "dependsOn": [ | ||
| "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]", | ||
| "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/',variables('runbookName'))]" | ||
| ], | ||
| "tags": { | ||
| "key": "value" | ||
| }, | ||
| "properties": { | ||
| "runbook": { | ||
| "name": "[variables('runbookName')]" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "outputs": {} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "itemDisplayName": "Create Azure Automation Runbook to retrieve Azure VMs", | ||
| "description": "This template creates an Azure Automation runbook that retrieves Azure V1 VMs and a credential to authenticate to Azure. It then starts the runbook job.", | ||
| "summary": "This template creates an Azure Automation runbook and credential. It then starts the runbook job.", | ||
| "githubUsername": "epc2101", | ||
| "dateUpdated": "2015-06-16" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This url should be updated to this repos url once the PR is merged