Skip to content

Commit 98f8e35

Browse files
committed
Adding Azure Automation 101 deployment template
1 parent c4debf5 commit 98f8e35

File tree

6 files changed

+238
-0
lines changed

6 files changed

+238
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
#Connect to your Azure account
3+
Add-AzureAccount
4+
5+
#Select your subscription if you have more than one
6+
#Select-AzureSubscription -SubscriptionName "My Subscription Name"
7+
8+
#Create a GUID for the job
9+
$JobGUID = [System.Guid]::NewGuid().toString()
10+
11+
#Use Azure resource Manager to deploy template
12+
Switch-AzureMode -Name AzureResourceManager
13+
14+
#Set the parameter values for the template
15+
$Params = @{
16+
"accountName" = "MyAccount" ;
17+
"jobId" = $JobGUID;
18+
"regionId" = "Japan East";
19+
"credentialName" = "DefaultAzureCredential";
20+
"userName" = "MyUserName";
21+
"password" = "MyPassword"
22+
}
23+
24+
$TemplateURI = "https://raw.githubusercontent.com/azureautomation/resources/master/automation-packs/101-get-vm-tutorial/deployAutomationResources.json"
25+
26+
New-AzureResourceGroupDeployment -TemplateParameterObject $Params -ResourceGroupName "MyResourceGroup" -TemplateUri $TemplateURI
27+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Create VM tutorial runbook, Automation credential, and start a job
2+
3+
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.
4+
5+
It contains a sample script, Deploy-ThroughARM, that you can use to get you started with the deployment.
6+
7+
##Resources Deployed
8+
###Automation Account
9+
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.
10+
11+
###Runbook
12+
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.
13+
14+
###Credential
15+
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/").
16+
17+
###Job
18+
A job will be triggered once the other resources are deployed. The job needs a unique GUID as the jobName. You can use this to identify the job later in your script and to retrieve the job output.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<#
2+
.DESCRIPTION
3+
An example runbook which prints out the first 10 Azure VMs in your subscription (ordered alphabetically).
4+
For more information about how this runbook authenticates to your Azure subscription, see our documentation here: http://aka.ms/fxu3mn
5+
6+
.NOTES
7+
AUTHOR: Azure Automation Team
8+
LASTEDIT: Mar 27, 2015
9+
#>
10+
workflow Get-AzureVMTutorial
11+
{
12+
#The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
13+
$CredentialAssetName = 'DefaultAzureCredential'
14+
15+
#Get the credential with the above name from the Automation Asset store
16+
$Cred = Get-AutomationPSCredential -Name $CredentialAssetName
17+
if(!$Cred) {
18+
Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
19+
}
20+
21+
#Connect to your Azure Account
22+
$Account = Add-AzureAccount -Credential $Cred
23+
if(!$Account) {
24+
Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct."
25+
}
26+
27+
#TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used.
28+
#Select-AzureSubscription -SubscriptionName "TODO: your Azure subscription name here"
29+
30+
#Get all the VMs you have in your Azure subscription
31+
$VMs = Get-AzureVM
32+
33+
#Print out up to 10 of those VMs
34+
if(!$VMs) {
35+
Write-Output "No VMs were found in your subscription."
36+
} else {
37+
Write-Output $VMs[0..9]
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"accountName": {
3+
"value": "MyAutomationAccount"
4+
},
5+
"jobId": {
6+
"value": "e6abf1fd-6311-4442-ac1a-22aae3cacdae"
7+
},
8+
"regionId": {
9+
"value": "East US 2"
10+
},
11+
"credentialName": {
12+
"value": "DefaultAzureCredential"
13+
},
14+
"userName": {
15+
"value": "MyAzureADUser"
16+
},
17+
"password": {
18+
"value": "MyAzureADPassword"
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"$schema": "http://schemas.microsoft.org/azure/deploymentTemplate?api-version=2015-01-01-preview#",
3+
"contentVersion": "1.0",
4+
"parameters": {
5+
"accountName": {
6+
"type": "string",
7+
"metadata": {
8+
"description": "The name of the Azure Automation account to deploy to."
9+
}
10+
},
11+
"regionId": {
12+
"type": "string",
13+
"allowedValues": ["Japan East", "East US 2","West Europe", "Southeast Asia", "South Central US"],
14+
"metadata": {
15+
"description": "The region to deploy the Automation account in."
16+
}
17+
},
18+
"credentialName": {
19+
"type": "string",
20+
"metadata": {
21+
"description": "DefaultAzureCredential is the name of the Automation credential used in this runbook. This credential allows you to authenticate to Azure. "
22+
}
23+
},
24+
"userName": {
25+
"type": "string",
26+
"metadata": {
27+
"description": "The username for the Azure Automation credential."
28+
}
29+
},
30+
"password": {
31+
"type": "string",
32+
"metadata": {
33+
"description": "The password for the Azure Automation credential."
34+
}
35+
},
36+
"jobId": {
37+
"type": "string",
38+
"metadata": {
39+
"description": "The GUID for the runbook job to be started."
40+
}
41+
}
42+
},
43+
"variables": {
44+
"runbookName": "Get-AzureVMTutorial",
45+
"scriptUri": "https://raw.githubusercontent.com/azureautomation/resources/master/automation-packs/101-get-vm-tutorial/Get-AzureVMTutorial.ps1",
46+
"runbookDescription": "Authenticates to Azure and lists all the Azure V1 VMs",
47+
"sku": "Free" //Pricing for Automation account. Either Free or Paid.
48+
},
49+
"resources": [
50+
{
51+
"name": "[parameters('accountName')]",
52+
"type": "Microsoft.Automation/automationAccounts",
53+
"apiVersion": "2015-01-01-preview",
54+
"location": "[parameters('regionId')]",
55+
"dependsOn": [
56+
],
57+
"tags": {
58+
59+
},
60+
"properties": {
61+
"sku": {
62+
"name": "[variables('sku')]"
63+
}
64+
},
65+
"resources": [
66+
{
67+
"name": "[variables('runbookName')]",
68+
"type": "runbooks",
69+
"apiVersion": "2015-01-01-preview",
70+
"location": "[parameters('regionId')]",
71+
"dependsOn": [
72+
"[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
73+
],
74+
"tags": {
75+
},
76+
"properties": {
77+
"runbookType": "Script",
78+
"logProgress": "false",
79+
"logVerbose": "false",
80+
"description": "[variables('runbookDescription')]",
81+
"publishContentLink": {
82+
"uri": "[variables('scriptUri')]",
83+
"version": "1.0.0.0"
84+
}
85+
}
86+
},
87+
{
88+
"name": "[parameters('credentialName')]",
89+
"type": "credentials",
90+
"apiVersion": "2015-01-01-preview",
91+
"location": "[parameters('regionId')]",
92+
"dependsOn": [
93+
"[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
94+
],
95+
"tags": {
96+
},
97+
"properties": {
98+
"userName": "[parameters('userName')]",
99+
"password": "[parameters('password')]",
100+
//"description": "[parameters('credentialDescription')]"
101+
}
102+
},
103+
{
104+
"name": "[parameters('jobId')]",
105+
"type": "jobs",
106+
"apiVersion": "2015-01-01-preview",
107+
"location": "[parameters('regionId')]",
108+
"dependsOn": [
109+
"[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]",
110+
"[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/',variables('runbookName'))]"
111+
],
112+
"tags": {
113+
"key": "value"
114+
},
115+
"properties": {
116+
"runbook": {
117+
"name": "[variables('runbookName')]"
118+
}
119+
}
120+
}
121+
122+
]
123+
}
124+
],
125+
"outputs": {
126+
}
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"itemDisplayName": "Create Azure Automation Runbook to retrieve Azure VMs",
3+
"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.",
4+
"summary": "This template creates an Azure Automation runbook and credential. It then starts the runbook job.",
5+
"githubUsername": "elcooper",
6+
"dateUpdated": "2015-06-15"
7+
}

0 commit comments

Comments
 (0)