LoginSignup
12
13

More than 5 years have passed since last update.

DSCを試してみる

Posted at

最近 windows server を扱うようになり、管理も面倒になってきたので重い腰を上げて面倒な設定の簡略化を図る。
Linuxに関しては今まで puppet / shef / ansible / opsworks などを扱ってきたが、windows に関してはそれらの製品を使う前にとりあえず windows に標準である DSC を利用してみることに。

1.構成

サーバーから変更をクライアントノードにプッシュする
サーバー : 10.0.0.1
クライアントノード : 10.0.0.2
OS : windows server 2012
PowerShell : 4.0

  • windows server 2012 (Not R2) では DSC が使用できる PowerShell 4.0 ではないのでアップグレードする

Windows Management Framework 4.0

  • 今回使用する Module を配置
$env:ProgramFiles\WindowsPowerShell\Modules

PowerShell Version 4 において、DSC は x64 のみの対応のため、
C:\Program Files (x86)\WindowsPowerShell\Modules
は参照しない

xNetworking Module

2. 準備

1.サーバーからの設定変更を受け入れる(ノード側作業)

DSC を利用するには、DSC サーバーとノードがお互いにリモート処理できる必要があるのでサーバを許可

Set-Item wsman:\localhost\Client\TrustedHosts -Value 10.0.0.1 -Force

2.LCM設定の確認(ノード側作業)

プッシュ型であることを確認

Get-DscLocalConfigurationManager 

3.設定変更(サーバー側)

作業例

FireWall Rule の変更
ICMP echo を反応させる
Module 配置済み(サーバー/ノード両方に必要)

PowerShell ISEを起動

Windows PowerShell(powershell.exe)を管理者モードで起動した状態で「ise」と入力すれば起動

Configuration を作成

Configuration: 任意のConfiguration名
Node: 反映対象ノード
Resource: 処理内容

configuration Add_FirewallRuleToExistingGroupICMP
{ 
    param  
    ( 
        [string[]]$nodeName
    ) 

    Import-DSCResource -ModuleName xNetworking 

    Node $NodeName 
    { 
        xFirewall Firewall
        { 
            Name = "MyFirewallRule" 
            DisplayName = "ファイルとプリンターの共有 (エコー要求 - ICMPv4 受信)" 
            Ensure = "Present" 
            Access = "Allow" 
            State = "Enabled" 
        } 
   } 
}

構成ファイル.mofの生成 = Configuration(コンパイルのような処理)を実行
オプション指定をしないと、カレントディレクトリ配下に Configuration 名のフォルダが作成され、その配下にファイルが生成

$outputPath = "C:Add_FirewallRuleDSC" 
Add_FirewallRuleToExistingGroupICMP -OutputPath $outputPath -nodeName 10.0.0.2

プッシュ型で適用に使うのが、Start-DSCConfiguration コマンドレット
このコマンドレットの"-Path"パラメーターに.mofを生成したフォルダーを指定すると、
フォルダーの中にある.mofファイル名のノードに対してサーバーから接続し、適用を試みる

Start-DscConfiguration -Path $outputPath -Wait -Verbose 

下記のように特にエラーが表示されなければOK

DSC1.PNG

次作業予定
GPOもDSCからいじりたい
(PolicyFileEditor とか使う必要がありそう)

12
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
13