注記
Azure Automation State Configurationは 2027 年 9 月 30 日に廃止されます。その日までに Azure Machine Configuration に移行してください。 詳細については、blog の投稿に関するお知らせを参照してください。 Azure Machine Configuration サービスは、DSC 拡張機能、Azure Automation State Configuration、および顧客からのフィードバックから最も一般的に要求される機能を組み合わせたものです。 Azureマシン構成には、Arc 対応サーバーを介したハイブリッド マシンのサポートも含まれています。
重要
[追加]、[構成の作成]、[ギャラリー] のナビゲーション リンクは、2025 年 3 月 31 日にポータルから削除されます。
注意事項
Azure Automation DSC for Linux は、2023 年 9 月 30 日に廃止されました。 詳しくは、お知らせをご覧ください。
Azure Automation State Configurationを使用すると、サーバーの構成を指定し、それらのサーバーが時間の経過と同時に指定された状態であることを確認できます。
- AZURE AUTOMATION DSC によって管理される VM をオンボードする
- Azure Automationに構成をアップロードする
- 構成をノードの構成としてコンパイルする
- ノードの構成を管理対象ノードに割り当てる
- 管理対象ノードの準拠状態を確認する
このチュートリアルでは、IIS を VM に確実にインストールする簡単な DSC 構成を使います。
前提条件
注記
Windows Server 2008、2008 R2、2012、および 2012 R2 はサポート終了 (EOS) に達しました。 使用状況を確認し、それに応じて OS のアップグレードと移行を計画します。 詳細については、サポート終了に関する情報を参照してください。
Windows Server 2016、2019、2022、または 2025 へのインプレース アップグレードを実行します。
- Azure Automation アカウント。 Automation アカウントとその要件の詳細については、「Automation アカウントの認証の概要」を参照してください。
- 2008 R2 以降Windows Server実行されているAzure Resource Manager VM (クラシックではない)。 VM の作成手順については、「Azure ポータルで最初のWindows仮想マシンを作成するを参照してください。
- Azure PowerShell モジュール バージョン 3.6 以降。 バージョンを確認するには、
Get-Module -ListAvailable Azを実行します。 アップグレードする必要がある場合は、「install Azure PowerShell moduleを参照してください。 - Desired State Configuration (DSC) に関する知識。 DSC の詳細については、「Windows PowerShell Desired State Configuration の概要を参照してください。
部分構成のサポート
Azure Automation State Configurationでは、部分的な構成の使用がサポートされています。 このシナリオでは、DSC は複数の構成を個別に管理するように構成され、各構成はAzure Automationから取得されます。 ただし、ノードに割り当てることができる構成はAutomation アカウントあたり 1 つだけです。 つまり、1 つのノードに 2 つの構成を使っている場合は、2 つの Automation アカウントが必要です。
プル サービスから部分構成を登録する方法の詳細については、部分構成に関するドキュメントを参照してください。
コードとしての構成を使用し、チームが連携してサーバーを共同で管理する方法の詳細については、「CI/CD パイプラインでの DSC のロールについて」を参照してください。
Azureにサインインする
Connect-AzAccount コマンドレットを使用してAzure サブスクリプションにサインインし、画面の指示に従います。
Connect-AzAccount
構成を作成してAzure Automationにアップロードする
テキスト エディターで次のように入力し、TestConfig.ps1 としてローカルに保存します。
configuration TestConfig {
Node WebServer {
WindowsFeature IIS {
Ensure = 'Present'
Name = 'Web-Server'
IncludeAllSubFeature = $true
}
}
}
注記
Azure Automationの構成名は、100 文字以下に制限する必要があります。
DSC リソースを提供するモジュールを複数インポートする必要があるより高度なシナリオでは、ご自分の構成にモジュールごとに Import-DscResource 行があることを確認してください。
Import-AzAutomationDscConfiguration コマンドレットを呼び出して、構成を Automation アカウントにアップロードします。
$importAzAutomationDscConfigurationSplat = @{
SourcePath = 'C:\DscConfigs\TestConfig.ps1'
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
Published = $true
}
Import-AzAutomationDscConfiguration @importAzAutomationDscConfigurationSplat
構成をノードの構成としてコンパイルする
ノードに DSC 構成を割り当てるには、先に DSC 構成をノードの構成としてコンパイルする必要があります。 「DSC 構成」を参照してください。
Start-AzAutomationDscCompilationJob コマンドレットを呼び出して、TestConfig 構成を、Automation アカウントの TestConfig.WebServer というノード構成に コンパイルします。
$startAzAutomationDscCompilationJobSplat = @{
ConfigurationName = 'TestConfig'
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
}
Start-AzAutomationDscCompilationJob @startAzAutomationDscCompilationJobSplat
State Configurationによって管理される VM を登録する
Azure Automation State Configurationを使用して、Azure VM (クラシックとResource Managerの両方)、オンプレミス VM、Linux マシン、AWS VM、オンプレミスの物理マシンを管理できます。 この記事では、Azure Resource Manager VM のみを登録する方法について説明します。 他の種類のマシンの登録については、「 Azure Automation State Configuration による管理用コンピューターのオンボード」を参照してください。
Register-AzAutomationDscNode コマンドレットを呼び出して、マネージド ノードとしてAzure Automation State Configurationに VM を登録します。
$registerAzAutomationDscNodeSplat = @{
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
AzureVMName = 'DscVm'
}
Register-AzAutomationDscNode @registerAzAutomationDscNodeSplat
構成モードの設定を指定する
Register-AzAutomationDscNode コマンドレットを使用して、VM を管理対象ノードとして登録し、構成のプロパティを指定します。 たとえば、ApplyOnly プロパティの値として ConfigurationMode を指定することにより、マシンの状態を 1 回だけ適用するように指定できます。 State Configurationでは、初期チェック後に構成の適用は試行されません。
$registerAzAutomationDscNodeSplat = @{
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
AzureVMName = 'DscVm'
ConfigurationMode = 'ApplyOnly'
}
Register-AzAutomationDscNode @registerAzAutomationDscNodeSplat```
You can also specify how often DSC checks the configuration state by using the
`ConfigurationModeFrequencyMins` property. For more information about DSC configuration settings,
see [Configuring the Local Configuration Manager][05].
```powershell
# Run a DSC check every 60 minutes
$registerAzAutomationDscNodeSplat = @{
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
AzureVMName = 'DscVm'
ConfigurationModeFrequencyMins = 60
}
Register-AzAutomationDscNode @registerAzAutomationDscNodeSplat```
## Assign a node configuration to a managed node
Now we can assign the compiled node configuration to the VM we want to configure.
```powershell
# Get the ID of the DSC node
$getAzAutomationDscNodeSplat = @{
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
Name = 'DscVm'
}
$node = Get-AzAutomationDscNode @getAzAutomationDscNodeSplat
# Assign the node configuration to the DSC node
$setAzAutomationDscNodeSplat = @{
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
NodeConfigurationName = 'TestConfig.WebServer'
NodeId = $node.Id
}
Set-AzAutomationDscNode @setAzAutomationDscNodeSplat
これにより、TestConfig.WebServer という名前のノード構成が、登録済みの DSC ノード DscVm に割り当てられます。
既定では、DSC ノードはノード構成に準拠していることを 30 分ごとにチェックされます。 コンプライアンス チェック間隔を変更する方法については、「
管理対象ノードの準拠状態を確認する
Get-AzAutomationDscNodeReport コマンドレットを使用して、管理対象ノードの準拠状態に関するレポートを取得できます。
# Get the ID of the DSC node
$getAzAutomationDscNodeSplat = @{
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
Name = 'DscVm'
}
$node = Get-AzAutomationDscNode @getAzAutomationDscNodeSplat
# Get an array of status reports for the DSC node
$getAzAutomationDscNodeReportSplat = @{
ResourceGroupName = 'MyResourceGroup'
AutomationAccountName = 'myAutomationAccount'
NodeId = $node.Id
}
$reports = Get-AzAutomationDscNodeReport @getAzAutomationDscNodeReportSplat
# Display the most recent report
$reports[0]
次のステップ
- 開始するには、「get started with Azure Automation State Configurationを参照してください。
- ノードを有効にする方法については、「Enable Azure Automation State Configurationを参照してください。
- ターゲット ノードに割り当てることができるように DSC 構成をコンパイルする方法については、「Azure Automation State Configuration の
Compile DSC 構成」を参照してください。 - 継続的デプロイパイプラインにおける Azure Automation State Configuration の使用例については、Chocolatey の継続的デプロイのセットアップを参照してください。
- 価格については、「Azure Automation State Configuration pricing」を参照してください。
- PowerShell コマンドレットのリファレンスについては、「Az.Automation」をご覧ください。
- Azure Automation State Configurationを使用したマシンの望ましい状態への構成に関連する問題のトラブルシューティングについては、「Azure Automation State Configurationの問題を参照してください。