PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/articles/automation/automation-dsc-getting-started.md

https://gitlab.com/yeah568/azure-content
Markdown | 292 lines | 180 code | 112 blank | 0 comment | 0 complexity | 123f77261ad74968e999da7c42a5af48 MD5 | raw file
  1. <properties
  2. pageTitle="Getting started with Azure Automation DSC"
  3. description="Explanation and examples of the most common tasks in Azure Automation Desired State Configuration (DSC)"
  4. services="automation"
  5. documentationCenter="na"
  6. authors="eslesar"
  7. manager="dongill"
  8. editor="tysonn"/>
  9. <tags
  10. ms.service="automation"
  11. ms.devlang="na"
  12. ms.topic="article"
  13. ms.tgt_pltfrm="powershell"
  14. ms.workload="na"
  15. ms.date="06/06/2016"
  16. ms.author="magoedte;eslesar"/>
  17. # Getting started with Azure Automation DSC
  18. This topic explains how to do the most common tasks with Azure Automation Desired State Configuration (DSC), such as creating, importing, and compiling configurations, onboarding machines to
  19. manage, and viewing reports. For an overview of what Azure Automation DSC is, see [Azure Automation DSC Overview](automation-dsc-overview.md). For DSC documentation, see
  20. [Windows PowerShell Desired State Configuration Overview](Windows PowerShell Desired State Configuration Overview).
  21. This topic provides a step-by-step guide to using Azure Automation DSC. If you want a sample environment that is already set up without following the steps described in this topic,
  22. you can use the ARM template at https://github.com/azureautomation/automation-packs/tree/master/102-sample-automation-setup. This template sets up a completed Azure Automation DSC
  23. environment, including an Azure VM that is managed by Azure Automation DSC.
  24. ## Prerequisites
  25. To complete the examples in this topic, the following are required:
  26. - An Azure Automation account. For instructions on creating an Azure Automation Run As account, see [Azure Run As Account](automation-sec-configure-azure-runas-account.md).
  27. - An Azure Resource Manager VM (not Classic) running Windows Server 2008 R2 or later. For instructions on creating a VM, see
  28. [Create your first Windows virtual machine in the Azure portal](../virtual-machines/virtual-machines-windows-hero-tutorial.md)
  29. ## Creating a DSC configuration
  30. We will create a simple [DSC configuration](https://msdn.microsoft.com/powershell/dsc/configurations) that ensures either the presence or absence of the **Web-Server** Windows Feature (IIS),
  31. depending on how you assign nodes.
  32. 1. Start the Windows PowerShell ISE (or any text editor).
  33. 2. Type the following text:
  34. ```powershell
  35. configuration TestConfig
  36. {
  37. Node WebServer
  38. {
  39. WindowsFeature IIS
  40. {
  41. Ensure = 'Present'
  42. Name = 'Web-Server'
  43. IncludeAllSubFeature = $true
  44. }
  45. }
  46. Node NotWebServer
  47. {
  48. WindowsFeature IIS
  49. {
  50. Ensure = 'Absent'
  51. Name = 'Web-Server'
  52. }
  53. }
  54. }
  55. ```
  56. 3. Save the file as `TestConfig.ps1`.
  57. This configuration calls one resource in each node block, the [WindowsFeature resource](https://msdn.microsoft.com/powershell/dsc/windowsfeatureresource), that ensures either the presence
  58. or absence of the **Web-Server** feature.
  59. ## Importing a configuration into Azure Automation
  60. Next, we'll import the configuration into the Automation account.
  61. 1. Sign in to the [Azure portal](https://portal.azure.com).
  62. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  63. 3. On the **Automation account** blade, click **DSC Configurations**.
  64. 4. On the **DSC Configurations** blade, click **Add a configuration**.
  65. 5. On the **Import Configuration** blade, browse to the `TestConfig.ps1` file on your computer.
  66. ![Screenshot of the **Import Configuration** blade](./media/automation-dsc-getting-started/AddConfig.png)
  67. 6. Click **OK**.
  68. ## Viewing a configuration in Azure Automation
  69. After you have imported a configuration, you can view it in the Azure portal.
  70. 1. Sign in to the [Azure portal](https://portal.azure.com).
  71. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  72. 3. On the **Automation account** blade, click **DSC Configurations**
  73. 4. On the **DSC Configurations blade, click **TestConfig** (this is the name of the configuration you imported in the previous procedure).
  74. 5. On the **TestConfig Configuration** blade, click **View configuration source**.
  75. ![Screenshot of the TestConfig configuration blade](./media/automation-dsc-getting-started/ViewConfigSource.png)
  76. A **TestConfig Configuration source** blade opens, displaying the PowerShell code for the configuration.
  77. ## Compiling a configuration in Azure Automation
  78. Before you can apply a desired state to a node, a DSC configuration defining that state must be compiled into one or more node configurations (MOF document), and placed on the Automation DSC
  79. Pull Server. For a more detailed description of compiling configurations in Azure Automation DSC, see [Compiling configurations in Azure Automation DSC](automation-dsc-compile.md).
  80. For more information about compiling configurations, see [DSC Configurations](https://msdn.microsoft.com/PowerShell/DSC/configurations).
  81. 1. Sign in to the [Azure portal](https://portal.azure.com).
  82. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  83. 3. On the **Automation account** blade, click **DSC Configurations**
  84. 4. On the **DSC Configurations blade, click **TestConfig** (the name of the previously imported configuration).
  85. 5. On the **TestConfig Configuration** blade, click **Compile**, and then click **Yes**. This starts a compilation job.
  86. ![Screenshot of the TestConfig configuration blade highlighting compile button](./media/automation-dsc-getting-started/CompileConfig.png)
  87. > [AZURE.NOTE] When you compile a configuration in Azure Automation, it automatically deploys any created node configuration MOFs to the pull server.
  88. ## Viewing a compilation job
  89. After you start a compilation, you can view it in the **Compilation jobs** tile in the **Configuration** blade. The **Compilation jobs** tile shows currently running, completed, and
  90. failed jobs. When you open a compilation job blade, it shows information about that job including any errors or warnings encountered, input parameters used in the configuration, and
  91. compilation logs.
  92. 1. Sign in to the [Azure portal](https://portal.azure.com).
  93. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  94. 3. On the **Automation account** blade, click **DSC Configurations**.
  95. 4. On the **DSC Configurations blade, click **TestConfig** (the name of the previously imported configuration).
  96. 5. On the **Compilation jobs** tile of the **TestConfig Configuration** blade, click on any of the jobs listed. A **Compilation Job** blade opens, labeled with the date that the
  97. compilation job was started.
  98. ![Screenshot of the Compilation Job blade](./media/automation-dsc-getting-started/CompilationJob.png)
  99. 6. Click on any tile in the **Compilation Job** blade to see further details about the job.
  100. ## Viewing node configurations
  101. Successful completion of a compilation job creates one or more new node configurations. A node configuration is a MOF document that is deployed to the pull server and ready to be pulled and
  102. applied by one or more nodes. You can view the node configurations in your Automation account in the **DSC Node Configurations** blade. A node configuration has a name with the form
  103. *ConfigurationName*.*NodeName*.
  104. 1. Sign in to the [Azure portal](https://portal.azure.com).
  105. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  106. 3. On the **Automation account** blade, click **DSC Node Configurations**.
  107. ![Screenshot of the DSC Node Configurations blade](./media/automation-dsc-getting-started/NodeConfigs.png)
  108. ## Onboarding an Azure VM for management with Azure Automation DSC
  109. You can use Azure Automation DSC to manage Azure VMs (both Classic and Resource Manager), on-premises VMs, Linux machines, AWS VMs, and on-premises physical machines. In this topic,
  110. we cover how to onboard only Azure Resource Manager VMs. For information about onboarding other types of machines, see
  111. [Onboarding machines for management by Azure Automation DSC](automation-dsc-onboarding.md).
  112. ### To onboard an Azure Resource Manager VM for management by Azure Automation DSC
  113. 1. Sign in to the [Azure portal](https://portal.azure.com).
  114. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  115. 3. On the **Automation account** blade, click **DSC Nodes**.
  116. 4. In the **DSC Nodes** blade, click **Add Azure VM**.
  117. ![Screenshot of the DSC Nodes blade highlighting the Add Azure VM button](./media/automation-dsc-getting-started/OnboardVM.png)
  118. 5. In the **Add Azure VMs** blade, click **Select virtual machines to onboard**.
  119. 6. In the **Select VMs** blade, select the VM you want to onboard, and click **OK**.
  120. >[AZURE.IMPORTANT] This must be an Azure Resource Manager VM running Windows Server 2008 R2 or later.
  121. 7. In the **Add Azure VMs** blade, click **Configure registration data**.
  122. 8. In the **Registration** blade, enter the name of the node configuration you want to apply to the VM in the **Node Configuration Name** box. This must exactly match the name
  123. of a node configuration in the Automation account. Providing a name at this point is optional. You can change the assigned node configuration after onboarding the node.
  124. Check **Reboot Node if Needed**, and then click **OK**.
  125. ![Screenshot of the Registration blade](./media/automation-dsc-getting-started/RegisterVM.png)
  126. The node configuration you specified will be applied to the VM at intervals specified by the **Configuration Mode Frequency**,
  127. and the VM will check for updates to the node configuration at intervals specified by the **Refresh Frequency**. For more information about how these values are used, see
  128. [Configuring the Local Configuration Manager](https://msdn.microsoft.com/PowerShell/DSC/metaConfig).
  129. 9. In the **Add Azure VMs** blade, click **Create**.
  130. Azure will start the process of onboarding the VM. When it is complete, the VM will show up in the **DSC Nodes** blade in the Automation account.
  131. ## Viewing the list of DSC nodes
  132. You can view the list of all machines that have been onboarded for management in your Automation account in the **DSC Nodes** blade.
  133. 1. Sign in to the [Azure portal](https://portal.azure.com).
  134. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  135. 3. On the **Automation account** blade, click **DSC Nodes**.
  136. ## Viewing reports for DSC nodes
  137. Each time Azure Automation DSC performs a consistency check on a managed node, the node sends a status report back to the pull server. You can view these reports on the blade
  138. for that node.
  139. 1. Sign in to the [Azure portal](https://portal.azure.com).
  140. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  141. 3. On the **Automation account** blade, click **DSC Nodes**.
  142. 4. On the **Reports** tile, click on any of the reports in the list.
  143. ![Screenshot of the Report blade](./media/automation-dsc-getting-started/NodeReport.png)
  144. On the blade for an individual report, you can see the following status information for the corresponding consistency check:
  145. - The report status--whether the node is "Compliant", the configuration "Failed", or the node is "Not Compliant" (when the node is in **applyandmonitor** mode and the machine is not in the
  146. desired state).
  147. - The start time for the consistency check.
  148. - The total runtime for the consistency check.
  149. - The type of consistency check.
  150. - Any errors, including the error code and error message.
  151. - Any DSC resources used in the configuration, and the state of each resource (whether the node is in the desired state for that resource)--you can click on each resource to get more
  152. detailed information for that resource.
  153. - The name, IP address, and configuration mode of the node.
  154. You can also click **View raw report** to see the actual data that the node sends to the server. For more information about using that data, see
  155. [Using a DSC report server](https://msdn.microsoft.com/powershell/dsc/reportserver).
  156. It can take some time after a node is onboarded before the first report is available. You might need to wait up to 30 minutes for the first report after you onboard a node.
  157. ## Reassigning a node to a different node configuration
  158. You can assign a node to use a different node configuration than the one you initially assigned.
  159. 1. Sign in to the [Azure portal](https://portal.azure.com).
  160. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  161. 3. On the **Automation account** blade, click **DSC Nodes**.
  162. 4. On the **DSC Nodes** blade, click on the name of the node you want to reassign.
  163. 5. On the blade for that node, click **Assign node**.
  164. ![Screenshot of the Node blade highlighting the Assign Node button](./media/automation-dsc-getting-started/AssignNode.png)
  165. 6. On the **Assign Node Configuration** blade, select the node configuration to which you want to assign the node, and then click **OK**.
  166. ![Screenshot of the Assign Node Configuration blade](./media/automation-dsc-getting-started/AssignNodeConfig.png)
  167. ## Unregistering a node
  168. If you no longer want a node to be managed by Azure Automation DSC, you can unregister it.
  169. 1. Sign in to the [Azure portal](https://portal.azure.com).
  170. 2. On the Hub menu, click **All resources** and then the name of your Automation account.
  171. 3. On the **Automation account** blade, click **DSC Nodes**.
  172. 4. On the **DSC Nodes** blade, click on the name of the node you want to reassign.
  173. 5. On the blade for that node, click **Unregister**.
  174. ![Screenshot of the Node blade highlighting the Unregister button](./media/automation-dsc-getting-started/UnregisterNode.png)
  175. ## Related Articles
  176. * [Azure Automation DSC overview](automation-dsc-overview.md)
  177. * [Onboarding machines for management by Azure Automation DSC](automation-dsc-onboarding.md)
  178. * [Windows PowerShell Desired State Configuration Overview](https://msdn.microsoft.com/powershell/dsc/overview)
  179. * [Azure Automation DSC cmdlets](https://msdn.microsoft.com/library/mt244122.aspx)
  180. * [Azure Automation DSC pricing](https://azure.microsoft.com/pricing/details/automation/)