Linux AdminïŒããã¯Windowsçšã®ãPuppetãã«é¢ããèšäºã§ãããLinuxçšã®DSCã®ããŒã¿çãæ¢ã«ãããŸãã
ãããã¯ã®å¯Ÿè±¡è
ïŒææ°ã®PowerShell 5.0ã«ã€ããŠã¯äœããããŸãããWindowsServer 2012 R2ã®ãããã¯ã¹ãããã®ã¿å©çšå¯èœã§ããåæ
2013幎ãWindows Server 2012 R2ã®ãªãªãŒã¹ã«äŒŽããMicrosoftã¯Powershell Desired State ConfigurationïŒDSCïŒã®å°å
¥ãçºè¡šããŸããã
ãã®æç¹ã§ãLinuxçšã®é¡äŒŒã®ã·ã¹ãã ãäœãããã®ãïŒäŸãã°ããã§ã«è¿°ã¹ãPuppetãªã©ïŒãå€å°æ³åããŸããã ãããã£ãŠãææ¡ãããæ©èœã¯ãå®å
šã«èªååãããã·ã¹ãã æ§æã«ã¯äžååã ãšæãããŸããã Powershell 5.0ãšæ°ããDSCæ©èœã«ã€ããŠã®æè¿ã®å ±åã ããããã®ãã¯ãããžãŒã«åã³æ³šæãæãããã«ä¿ããŸããã
ç解ããããã«ãç§ã¯ããç°¡åãªã¿ã¹ã¯ãæãã€ããŸããïŒ
- ç§ãã¡ãéçºããASP.NETã¢ããªã±ãŒã·ã§ã³ãèªåã®ãµãŒããŒã«åå¥ã«ã€ã³ã¹ããŒã«ãããç¹å®ã®ã¯ã©ã€ã¢ã³ãããããšããŸãã IISã«å ããŠãMS SQL Serverãå¿
èŠã§ãããŸãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ããã€ãã®èšå®ãè¡ããããã€ãã®éèŠãªãŠãŒãã£ãªãã£ãã€ã³ã¹ããŒã«ããå¿
èŠããããŸãã
æ°ããã€ã³ã¹ããŒã«ãããWindows Server 2012 R2ã§å¿
èŠãªãã¹ãŠãå®è¡ããã€ã³ã¹ããŒã«ããã³æ§ææé ã®ä»£ããã«ãæ§æã¹ã¯ãªãããçºè¡ããããšã¯ã§ããŸããïŒ
ãã®èšäºãããããç解ããããã«ãMicrosoftããã°ïŒ
http://habrahabr.ru/company/microsoft/blog/253497/ïŒã®èª¬æãæåã«èªãã§
ãã ãã ã
éå§äœçœ®
å
ã
ããµãŒããŒã¯ã©ããã®ãã¹ãã£ã³ã°ãããã€ããŒãã泚æããããšæ³å®ãããŠããŸããã Windows Server 2012 R2ãã€ã³ã¹ããŒã«ãããŠããã管çè
ãã¹ã¯ãŒããšãµãŒããŒã®IPã¢ãã¬ã¹ãå«ãã¢ã©ãŒãã衚瀺ãããŸããã
ãããŠã次ã®äŸã®ããã«ã1ã€ã®ã³ãã³ããå
¥åããŸãã
makemagic -server new.example.com
ãã°ãããããšãã·ã¹ãã ã䜿çšããæºåãæŽããŸãã
æ®å¿µãªãããããã¯ãŸã äžå¯èœã§ãã ããããè¯ããã¥ãŒã¹ããããŸã-Windows Server 2016ã®æ¬¡ã®ããŒãžã§ã³ã«ãªããŸãããã®èšäºãæžããŠããéã以äžã«èª¬æããæ§æã¯ïŒãã¡ãããæŽæ°ããã°ã©ã ãã€ã³ã¹ããŒã«ããã«ïŒã€ã³ã¹ããŒã«ãããTechnical Preview 3ã®ã¿ã«é©çšãããŸãã
ãµãŒããŒ
䜿çšå¯èœãªçµ±åæŽæ°ããã°ã©ã ãå«ãWindows Server 2012 R2ã®ã€ã¡ãŒãžãããå Žåã¯ããã®ã»ã¯ã·ã§ã³ãã¹ãããããŠãã ãããçŸåšã®ããŒãžã§ã³ïŒ2012 R2ïŒã§ã¯ãæŽæ°ãã§ãŒã³ã«åé¡ããããŸãã
- ç§ãããããšããæåã®ã¿ã¹ã¯ã®1ã€ã¯ãã¿ã€ã ãŸãŒã³ã®ç¢ºèª/èšå®ã§ããã ãããè¡ãã«ã¯ãææ°ã®ã¿ã€ã ãŸãŒã³æŽæ°ããã°ã©ã ãã€ã³ã¹ããŒã«ããå¿
èŠããããŸãã
- KB2919355ã®å€§èŠæš¡ãªæŽæ°ãå¿
èŠãªããããã®æŽæ°ã¯ã€ã³ã¹ããŒã«ãããŸããã
- ããã¯ãç§ã®å ŽåãKB2975061ã®æŽæ°ãåžæããŠããŸãã
ãããã®æŽæ°ã¯ãæ°ããã€ã³ã¹ããŒã«ãããã·ã¹ãã ã«Windows Updateãä»ããŠã€ã³ã¹ããŒã«ããããšã¯ã§ããŸããã
ãããã£ãŠã2ã€ã®ãªãã·ã§ã³ããããŸãã1ïŒWindows Updateãä»ããŠãã¹ãŠã®æŽæ°ããã°ã©ã ãã€ã³ã¹ããŒã«ããŸãããæéãããããŸãïŒãã®ããã»ã¹ã¯åŸã§å®äºã§ããŸãïŒããŸãã¯2ïŒæãå¿
èŠãªãã®ã®ã¿ãé
眮ããŸãã
2çªç®ã®ã±ãŒã¹ã§ã¯ããããè¡ããŸããRDPãä»ããŠãµãŒããŒã«æ¥ç¶ããææ Œãããæš©éã§Powershellã³ã³ãœãŒã«ãå®è¡ããå¿
èŠãªæŽæ°ãçŽæ¥ãªã³ã¯çµç±ã§ããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããŸãã
Invoke-WebRequest -Uri http://download.microsoft.com/download/3/9/7/3971FEA1-C483-409E-BF13-219F8A6E907E/Windows8.1-KB2975061-x64.msu -OutFile .\Downloads\Windows8.1-KB2975061-x64.msu .\Downloads\Windows8.1-KB2975061-x64.msu /quiet /norestart Invoke-WebRequest -Uri http://download.microsoft.com/download/2/5/6/256CCCFB-5341-4A8D-A277-8A81B21A1E35/Windows8.1-KB2919355-x64.msu -OutFile .\Downloads\Windows8.1-KB2919355-x64.msu .\Downloads\Windows8.1-KB2919355-x64.msu /quiet /promtrestart
åèµ·ååŸããµãŒããŒã¯æ§æãåä¿¡ããæºåãæŽããŸãã
Windows Server 2016 TP3ã¯ããã«DSCãè©Šãæºåãã§ããŠããããšãæãåºããŸãã
管çã³ã³ãã¥ãŒã¿ãŒ
éèŠïŒãããã£ãŠãåã®ã»ã¯ã·ã§ã³ãã¹ãããã§ããŸãïŒäœ¿çšå¯èœãªæ¹æ³ã§ãã®æ§æäŸããã¹ãããã«ã¯ãMS SQL Server 2014ã€ã¡ãŒãžããµãŒããŒã«æ¥ç¶ããExpress EditionãéžæããŠRïŒãšããŠæ¥ç¶ããŸãããã§ã«Windows 10ã«ã¢ããã°ã¬ãŒããããŠãŒã¶ãŒã倱æãããå¿
èŠããããŸãããã®ã·ã¹ãã ã§äœæãããæ§æã䜿çšã§ããªã埮åŠãªéãããããŸãã Powershell 5.0ãã€ã³ã¹ããŒã«ãããŠãŒã¶ãŒã«ãåãããšãåœãŠã¯ãŸããŸãã
æ§æã®äœæãšé©çšã¯ãWindows 8.1ã§å®è¡ãããŸããã PowershellããŒãžã§ã³ïŒ
PS C:\Users\nelsh> $PSVersionTable Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.34209 BuildVersion 6.3.9600.17400 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} PSRemotingProtocolVersion 2.2
ããããããã§ããŸã ååã§ã¯ãããŸããã 管çè
ã®ã³ã³ãã¥ãŒã¿ãŒã§ãPowershell Remotingãæå¹ã«ããå¿
èŠããããŸãïŒãµãŒããŒã§ã2ã€ã®æŽæ°ããã°ã©ã ãã€ã³ã¹ããŒã«ããåŸãPSRemotingã¯æ¢ã«æå¹ã«ãªã£ãŠããŸãïŒã ããã¯ãææ Œãããæš©éã§Powershellã³ã³ãœãŒã«ã§å®è¡ãããŸãã
Enable-PSRemoting -Force
ããã«ã管çè
ã®ã³ã³ãã¥ãŒã¿ãŒããä»ã®ã³ã³ãã¥ãŒã¿ãŒãžã®æ¥ç¶ãèš±å¯ããå¿
èŠããããŸãïŒïŒïŒã
Set-Item WSMan:\localhost\Client\TrustedHosts -Value *
䟿å®äžãäœæãããµãŒããŒã®IPã¢ãã¬ã¹ãå«ãè¡ã
hosts
è¿œå ããŸããã
<ip-address> cs1.example.com
ãµã³ãã«ã®ãœãŒã¹ã³ãŒãã¯Githubã§å
¥æã§ããŸãïŒ
https :
//github.com/nelsh/DSC-WS2012R2æåã®æ§æ
ããã¯ãDSC-W2012R2.ps1ãã¡ã€ã«ã®æåã®ããŒãžã§ã³ã®ã¹ã¯ãªãŒã³ã·ã§ããã§ãïŒäŸ¿å®äžãDSC-W2012R2-First.ps1ãšããååã§ãªããžããªã«ãããŸãïŒã
- 1ã21è¡-DSCW2012R2ãšåŒã°ããæ§æèªäœã
- ãã®äžã®3è¡ç®ãã7è¡ç®ã§ããã©ã¡ãŒã¿ãŒã1ã€ã ãã«ãªãããšãéç¥ããŸã-ãµãŒããŒåã®é
åã§ãã
- 8è¡ç®ã§ãå¿
èŠãªPowerShellã¢ãžã¥ãŒã«ãæ¥ç¶ããŸã
- 10ã20è¡-æ§æã§äœ¿çšããããªãœãŒã¹ã®ãªã¹ãã ç§ãã¡ã®å Žåããã¹ã¯ãªããããªãœãŒã¹ã¯1ã€ãããªããããããå°ãäœããªã£ãŠããŸãã
- 23-25è¡-æé ã®1ã€ã¯ãŠãŒã¶ãŒãè¿œå ããããšãªã®ã§ããŠãŒã¶ãŒã®ãã¹ã¯ãŒããäœæããå¿
èŠããããŸãã æå·åãåŠçããªãããã«ããã¹ã¯ãŒããå¹³æã§æ§æã«ä¿åããããšãèš±å¯ããŸãã
- 27è¡ç®-æ§æã®äœæã ãã®ã¹ã¯ãªãããå®è¡ããçµæããã¡ã€ã«DSCW2012R2 \ cs1.example.com.mofãäœæãããŸã-ã³ã³ãã€ã«æžã¿ã®æ§æã®ãããªãã®ã§ãã
- 29ã31è¡-cs1.example.comãšããååã®ãµãŒããŒãžã®æ§æã®ã¢ããªã±ãŒã·ã§ã³ãéå§ããŸãã ãµãŒããŒã«ã¢ã¯ã»ã¹ããããã®ãŠãŒã¶ãŒåãšãã¹ã¯ãŒããèŠæ±ããããã®æšæºãŠã£ã³ããŠãæåã«è¡šç€ºãããŸãã
- 33è¡ç®ããããµãŒããŒã®ãã¢ãåæã«ã»ããã¢ããããäŸã
ãªãœãŒã¹ã«æ»ã-Powershell DSCã«ã¯12ã®çµã¿èŸŒã¿ãªãœãŒã¹ããããŸãã ãããã®ã»ãšãã©ïŒãŸãã¯12åäž11åïŒã¯åçŽã§ç解ãããããã®ã§ãã ããããã·ã¹ãã ãå®å
šã«æ§æããã«ã¯ãæããã«ååã§ã¯ãããŸããã Microsoftã¯ãå¿
èŠãªãªãœãŒã¹ãç¬èªã«äœæããããšããå§ãããŸãã ããããæ£çŽãªãšãããä»ã§ãããã«å¯ŸåŠããããšããç¹å¥ãªæ¬²æ±ã¯ãããŸããã
ãã ããæåã«äŒã£ããšãã¯ã
ã¹ã¯ãªãããªãœãŒã¹ã«æ³šæãæããŸããã§ããã äŸãããã«è©³ããèŠãŠã¿ãŸãããã
Script First { TestScript = { if ( "Test script content" ) { $true } else { $false } } SetScript = { "Set script content" } GetScript = { return @{ Result = "Result for GetScript" GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } }
ããã¯ãäœãããªãæãç°¡åãªãªãã·ã§ã³ã§ãã ä»çµã¿ïŒ
- æ§æãé©çšããã«ã¯ãStart-DSCConfigurationã³ãã³ããåŒã³åºããŸãïŒ29è¡ç®ïŒã
- ã¹ã¯ãªããã¯ããªãœãŒã¹ã®ãªã¹ããåŠçäžã«ãScript FirstããªãœãŒã¹ã«å°éãããšãæåã«TestScriptå€æ°ããã³ãŒããåŒã³åºããŸãã ãã®äŸã§ã¯ãåžžã«$ trueãè¿ããŸãã
- ãããã圌ã$ falseãè¿ããå ŽåãSetScriptå€æ°ããã³ãŒããåŒã³åºãããŸãã
Powershellã³ãŒãã¯ãããã®å€æ°ã«å«ããããšãã§ããŸã-ã¹ã±ãŒã«ã¯ç©ºæ³ã«ã®ã¿äŸåããŸãã çæ³çã«ã¯ãTestSciptã®ã³ãŒãã¯ãSetScriptã³ãŒãã§è¡ããããã¹ãŠã®èšå®ãæ£ããããšã確èªããå¿
èŠããããŸãã
æåã®æ§æãå®è¡ããŠã¿ãŸãããïŒå€ãç¿æ
£ãšããŠãFar Managerããå§ããŸãïŒã
powershell.exe -ExecutionPolicy RemoteSigned .\DSC-WS2012R2.ps1
ãšã©ãŒãªãã§å®äºããŸããã
管çè
ã®ã³ã³ãã¥ãŒã¿ãŒããã¹ãã£ã³ãéå§ããæ¹æ³ã説æããªãããã«ããµãŒããŒã«ã¢ã¯ã»ã¹ããŠããã€ãã®ã³ãã³ããå®è¡ããŸããã
æåïŒ
Test-DSCConfiguration
æ§æã確èªããŸãã æåŸã®ã¡ãã»ãŒãžïŒé»è²ã®ããã¹ãã®åŸïŒã«æ³šæããŠãã ãã-Trueã ã€ãŸã èšå®ããã§ãã¯ããããšã©ãŒã¯æ€åºãããŸããã§ããã
次ã®ã³ãã³ãïŒ
Get-DSCConfiguration
çŸåšã®æ§æã«é¢ãã詳现ã
Get-DSCConfiguration
ãŸãã ãã®ã¹ã¯ãªãŒã³ã·ã§ããã§ãã¹ã¯ãªãããã¡ãŒã¹ãããªãœãŒã¹ã®ã³ãŒãããã§ãã¯ããŠããããäœããã©ãã«ããã®ããç解ããã ãã§ååã§ãã
ãã®ç¬éãç§ã¯ããããããã¹ãŠãããŸãããããšã«æ°ã¥ããŸããã
ã ããã ã«ç§»ããŸããã...
é«åºŠãªæ§æ
ããŒãã®æ§æã«å®éã®ã¿ã¹ã¯ãè¿œå ãå§ããŸãã
æåã«ç¢ºèªãããã®ã¯ãã³ã³ãã¥ãŒã¿ãŒåãšã¡ã€ã³ã®DNSãµãã£ãã¯ã¹ã§ãã DNSãŸãŒã³ã§ãã®ã³ã³ãã¥ãŒã¿ãŒã®ååãcs1.example.comã®å Žåãååã¯cs1ãdnsãµãã£ãã¯ã¹ã¯example.comã§ã
ååããå§ããŸãããã æåã«ãã®ã³ãŒããæžããŸããïŒ
$shortName = $Server.Split(".")[0].ToLower() Script ComputerName { SetScript = { Rename-Computer -NewName $shortName } GetScript = { return @{ Result = $env:computerName GetScript = $GetScript.Trim(); SetScript = $SetScript.Trim(); TestScript = $TestScript.Trim() } } TestScript = { $env:computerName.ToLower() -eq $shortName } }
ããããããã¯æ©èœããŸããã SetScriptãGetScriptãããã³TestScriptã¯ãã¹ã³ãŒãå€ã®å€æ°ã«ã€ããŠã¯äœãç¥ããŸããã è¡ã®æžåŒèšå®ã䜿çšããŠã®ã¿è»¢éã§ããŸãã ãã®ããã«ïŒ
$shortName = $Server.Split(".")[0].ToLower() Script ComputerName { SetScript = ({ Rename-Computer -NewName "{0}" } -f @($shortName)) GetScript = { return @{ Result = $env:computerName GetScript = $GetScript.Trim(); SetScript = $SetScript.Trim(); TestScript = $TestScript.Trim() } } TestScript = ({ $env:computerName.ToLower() -eq "{0}" } -f @($shortName)) }
dnsãµãã£ãã¯ã¹ã®æ€èšŒã«ããããã¹ãŠãããã·ã³ãã«ã§ããããšãå€æããŸãããããã¯ã¬ãžã¹ããªå
ã®ãã©ã¡ãŒã¿ãŒãªã®ã§ãæšæºã®ã¬ãžã¹ããªãªãœãŒã¹ã䜿çšããŸãã
Registry PrimaryDomainSuffix { Key = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\" ValueName = "NV Domain" Ensure = "Present" ValueData = "example.com" ValueType = "String" }
å®éšäžã«æŽæ°ãèªåçã«èšå®ãããªãããã«ãWindows Updateãæ§æããŸãã å©çšå¯èœãªã¢ããããŒãã®éç¥ã®ã¿ãåãåããŸãïŒ
Script WindowsUpdateSettings { SetScript = { $WUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings $WUSettings.NotificationLevel=2 $WUSettings.IncludeRecommendedUpdates=$true $WUSettings.Save() } GetScript = { return @{ Result = '' GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = { $WUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings; $WUSettings.NotificationLevel -eq 2 -and $WUSettings.IncludeRecommendedUpdates -eq $true } }
ããã€ãã®éèŠãªæŽæ°ãååŸããããã§ãã¿ã€ã ãŸãŒã³ãèšå®ããŸã
次ã«éèŠãªãã©ã¡ãŒã¿ãŒã¯ã¿ã€ã ãŸãŒã³ã§ãã ãããŠããªãã¢ã¹ã¯ã¯ã®æéããã¹ãŠã®äººã«é©ããŠããããã§ã¯ãªããšææ¡ããã®ã§ããïŒ ã©ãããããïŒ
ãããã£ãŠãæåã®åé¡ïŒWindows Updateãä»ããåå¥ã®æŽæ°ã®ããã®çµã¿èŸŒã¿ã®ã€ã³ã¹ããŒã«ããŒã«ã¯ãªãããã§ãã 幞ããªããšã«ããã®åé¡ã解決ããå°ããªãŠãŒãã£ãªãã£ããããŸãã
ãŠãŒãã£ãªãã£ã®ãã£ã¬ã¯ããªãäœæããŸãã
$abcUpdatePath = "C:\UTILS\ABC-Update" $abcUpdateZip = Join-Path $abcUpdatePath "ABC-Update.zip" File AbcUpdateDir { Ensure = "present" DestinationPath = $abcUpdatePath Type = "Directory" }
ããŠã³ããŒãïŒ
Script AbcUpdateDownload { DependsOn = "[File]AbcUpdateDir" SetScript = ({ Invoke-WebRequest -Uri http://abc-deploy.com/Files/ABC-Update.zip -OutFile {0} } -f @($abcUpdateZip)) GetScript = { return @{ Result = $TestScript GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = ({ Test-Path {0} } -f @($abcUpdateZip)) }
çµã¿èŸŒã¿ã®ã¢ãŒã«ã€ããªãœãŒã¹ã䜿çšããŠè§£åããŸãã
Archive AbcUpdateUnpack { Ensure = "Present" DependsOn = "[Script]AbcUpdateDownload" Path = $abcUpdateZip Destination = $abcUpdatePath }
éå§ããã¿ã€ã ãŸãŒã³ã®æŽæ°ã«å ããŠãããã«.NET FrameworkãããŒãžã§ã³4.5.2ã«æŽæ°ããŸãã
Script AbcUpdateNet452Install { DependsOn = "[Archive]AbcUpdateUnpack" SetScript = { C:\UTILS\ABC-Update\ABC-Update.exe /a:install /k:2934520 } GetScript = { return @{ Result = if ( Get-HotFix -Id KB2934520 -ErrorAction SilentlyContinue ) { "KB2934520: Installed" } else { "KB2934520: Not Found" } GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = { if ( Get-HotFix -Id KB2934520 -ErrorAction SilentlyContinue ) { $true } else { $false } } } Script AbcUpdateTimeZoneInstall { DependsOn = "[Archive]AbcUpdateUnpack" SetScript = { C:\UTILS\ABC-Update\ABC-Update.exe /a:install /k:3013410 } GetScript = { return @{ Result = if ( Get-HotFix -Id KB3013410 -ErrorAction SilentlyContinue ) { "KB3013410: Installed" } else { "KB3013410: Not Found" } GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = { if ( Get-HotFix -Id KB3013410 -ErrorAction SilentlyContinue ) { $true } else { $false } } }
æåŸã«ã¿ã€ã ãŸãŒã³ã«å°éããŸããã ç§åŠçãªçªé²ã®æ¹æ³ã«ãã£ãŠãç§ã¯ãã€ã«ã«æ¹ã®è¿ãã®æé垯ãéžã³ãŸããã
ç§ã¯ãã®ãªãã·ã§ã³ãèŠã€ããŸããïŒtzutil.exeã³ãã³ãã©ã€ã³ãŠãŒãã£ãªãã£ã䜿çšããŠã®ã¿ã¿ã€ã ãŸãŒã³ãå€æŽããPowershellã䜿çšããŠã®ã¿ãã§ãã¯ã§ããŸãã ãã ãããã®ã±ãŒã¹ã¯ç¹å¥ã§ããã€ã³ã¹ããŒã«äžã«ã1ã€ã®å€ãåã¢ãžã¢æ±éšæšæºæãã䜿çšããããŸã£ããç°ãªãããã·ã¢TZ 7æšæºæãããã§ãã¯ãããŸãã
Script TimeZoneSettings { SetScript = { tzutil.exe /s "North Asia East Standard Time" } GetScript = { return @{ Result = [System.TimeZone]::CurrentTimeZone.StandardName GetScript = $GetScript.Trim(); SetScript = $SetScript.Trim(); TestScript = $TestScript.Trim() } } TestScript = { [System.TimeZone]::CurrentTimeZone.StandardName -eq "Russia TZ 7 Standard Time" } }
ãã·ã¢ã®ãã¹ãŠã®ã¿ã€ã ãŸãŒã³ã§ãã®ãããªçœå®³ã®ããã§ãã
Windowsã³ã³ããŒãã³ã
ãããã䜿çšãããšããã¹ãŠãéåžžã«ã·ã³ãã«ã§ãã€ã³ã¿ãŒãããäžã®éåžžã«å€ãã®äŸããããŸãã Windows管çè
ã¯ã³ã³ããŒãã³ãã®ã€ã³ã¹ããŒã«ãšåé€ã®ã¿ãè¡ã£ãŠããããã«æããããããããŸããã æ§æã®æåã®2ã€ã®WindowsFeatureãªãœãŒã¹ã®ã¿ïŒ
WindowsFeature offFSSMB1 { Ensure = "Absent" Name = "FS-SMB1" } WindowsFeature WebAspNet45 { Ensure = "Present" Name = "Web-Asp-Net45" IncludeAllSubFeature = $True }
æåã®å Žåãã³ã³ããŒãã³ãã¯åé€ããã2çªç®ã®å Žåããã¹ãŠã®äŸåé¢ä¿ãšãšãã«ã€ã³ã¹ããŒã«ãããŸãã
ããã±ãŒãžã®ã€ã³ã¹ããŒã«
Far Managerã®äŸã«ã€ããŠã ãŸããæ¢ç¥ã®æ¹æ³ã§ããã±ãŒãžãããŠã³ããŒãããå¿
èŠããããŸãã
Script FarDownLoad { SetScript = { Invoke-WebRequest -Uri http://www.farmanager.com/files/Far30b4400.x64.20150709.msi -OutFile C:\Users\Public\Downloads\Far30b4400.x64.20150709.msi } GetScript = { return @{ Result = Test-Path C:\Users\Public\Downloads\Far30b4400.x64.20150709.msi GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = { Test-Path C:\Users\Public\Downloads\Far30b4400.x64.20150709.msi } }
ãªãœãŒã¹ãã©ã¡ãŒã¿ã§ã¯ãããã±ãŒãžã¯ãProductIdãã§ãã ãŸããmsiãã¡ã€ã«ãåæãããããšåããProductIdããå ±åããããã°ã©ã ãããããã§ãã å
ã«é²ã¿ãŸããããã®ãã©ã¡ãŒã¿ãŒã䜿çšããã«æ§æãããã«é©çšããããšããŸãããããšã©ãŒããã¹ãã«ãProductIdããšæ£ãããNameããèŠã€ãããŸããã ãªãœãŒã¹ã®èª¬æã¯æ¬¡ã®ãšããã§ãã
Package FarInstall { Ensure = "Present" DependsOn = "[Script]FarDownLoad" Name = "Far Manager 3 x64" ProductId = 'E5512F32-B7C1-48E3-B6AF-E5F962F99ED6' Path = "C:\Users\Public\Downloads\Far30b4400.x64.20150709.msi" Arguments = '' LogPath = "C:\Users\Public\Downloads\FarInstall.log" }
ãŠãŒã¶ãŒãšæš©å©
åé¡ã®å£°æã«ãããšããµãŒããŒã¯é¡§å®¢ã®ç®¡çäžã«ãããŸãããããã§ããç¶ç¶ççµ±åãµãŒããŒã䜿çšããŠWebã¢ããªã±ãŒã·ã§ã³ãæŽæ°ã§ããããšãèªããŸããã Jenkins CIã䜿çšããŸãïŒã¡ãªã¿ã«ããã®äžã®ãã¹ãŠã®ã¿ã¹ã¯ã¯Powershellã«ãå®è£
ãããŠããŸãïŒã
æå°ããŒãžã§ã³ã§ã¯ãUsersã°ã«ãŒãã«JenkinsãŠãŒã¶ãŒãå¿
èŠã§ãWebã¢ããªã±ãŒã·ã§ã³ãååšãããã£ã¬ã¯ããªãžã®æžã蟌ã¿ã¢ã¯ã»ã¹æš©ããããŸãã
c:\web
ãŸãã
ãŠãŒã¶ãŒã¯æ¬¡ã®æ¹æ³ã§äœæãããŸãã
$JenkinsCredential = New-Object System.Management.Automation.PSCredential(` "Jenkins", ("Pa`$`$w0rd" | ConvertTo-SecureString -asPlainText -Force)` ) User JenkinsUser { UserName = "Jenkins" Ensure = "Present" Password = $JenkinsCredential PasswordChangeNotAllowed = $true PasswordNeverExpires = $true }
æ§æã§æå·åããããã¹ã¯ãŒãã䜿çšããæ¹æ³ããããŸãããç°¡åãªæ¹æ³ã䜿çšããŸãã ãã®å ŽåããŠãŒã¶ãŒãJenkinsãã¯ãã¹ã¯ãŒããPa $$ w0rdãã§äœæãããŸãã
ãã£ã¬ã¯ããªã®äœæã¯éåžžã®æ¹æ³ã§è¡ãããŸãã ãããããã£ã¬ã¯ããªãžã®æš©å©ã®å²ãåœãŠãšæ€èšŒã§ã¯ãããããåãå¿
èŠããããŸããã
$AccessStringTmpl = "NT AUTHORITY\SYSTEM Allow FullControl`nBUILTIN\Administrators Allow FullControl`nBUILTIN\Users Allow ReadAndExecute, Synchronize`nCS1\Jenkins Allow Modify, Synchronize" File DirDweb { Ensure = "present" DestinationPath = "c:\web" Type = "Directory" } Script AclsDweb { DependsOn = "[File]DirDweb" SetScript = { icacls c:\web /reset /t /q takeown.exe /fc:\web /r /a /dy icacls.exe c:\web /inheritance:r icacls.exe c:\web /grant:r "Administrators:(OI)(CI)(F)" "System:(OI)(CI)(F)" "Users:(OI)(CI)(RX)" "Jenkins:(OI)(CI)(M)" /t /q } GetScript = { return @{ Result = (get-acl c:\web).AccessToString GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = ({ (get-acl c:\web).AccessToString -eq "{0}" } -f @($AccessStringTmpl)) }
æãç°¡åãªæ¹æ³ã¯ã
icacls.exe
ã䜿çšããŠæš©å©ãå²ãåœãŠãããš
icacls.exe
ã ãã®å Žåã次ã®é åºã§å®è¡ãããŸãã
- 1è¡ç®ïŒãã¹ãŠã®æš©éããªã»ãããã芪ãã£ã¬ã¯ããªããã®ç¶æ¿ãæå¹ã«ããŸã
- 2çªç®ïŒãã«ãã€ã³ã°ã«ãŒãAdministratorsãææè
ãšããŠå²ãåœãŠãããŸã
- 3çªç®ïŒç¶æ¿ããã£ã³ã»ã«ããããã¹ãŠã®æš©å©ãåé€ãããŸã
- 4çªç®ïŒç®¡çè
ããã³SYSTEMã«å¯Ÿããå®å
šãªæš©éã®å²ãåœãŠããŠãŒã¶ãŒã«å¯Ÿããèªã¿åããJenkinsã«å¯Ÿããå€æŽã
æ€èšŒã«ã¯ãã¡ãœãã
(get-acl c:\web).AccessToString
åä¿¡ããæååã¯ã
$AccessStringTmpl
å€æ°ãšäžèŽããå¿
èŠããããŸãã ã¡ãªã¿ã«ããã®äŸã§ã¯ãšã©ãŒããããŸã-ãµãŒããŒåãCS1ããè¡ã«æ瀺çã«ç€ºãããŠããŸã-ãããŠãå€
$Server.Split(".")[0].ToUpper()
ã«çœ®ãæããŠãã ããã
MS SQL
ãµãŒãããŒãã£ã®ã¢ãžã¥ãŒã«ã䜿çšããªãããšã«ããããšãå°ãåŸæããŸããã MS SQL Serverãã€ã³ã¹ããŒã«ããã³æ§æããããã®ã¢ãžã¥ãŒã«ãæ¢ã«ããããã ããããèªåã€ã³ã¹ããŒã«çšã®æ§æãã¡ã€ã«ããããè©ŠããŠã¿ãããšã«ããŸããã
ãŸããå¥ã®Windowsã³ã³ããŒãã³ããå¿
èŠã§ã-ãWindowsFeature NetFrameworkCoreããªãœãŒã¹ïŒ
WindowsFeature NetFrameworkCore { Ensure = "Present" Name = "Net-Framework-Core" IncludeAllSubFeature = $True }
次ã«ãã€ã³ã¹ããŒã©ãŒã®æ§æãã¡ã€ã«ã¯ãScript MSSQLConfigDownLoadããªãœãŒã¹ã§ãã
Script MSSQLConfigDownLoad { SetScript = { Invoke-WebRequest -Uri https://raw.githubusercontent.com/nelsh/DSC-WS2012R2/master/SQL2014-Setup.ini -OutFile C:\Users\Public\Downloads\SQL2014-Setup.ini } GetScript = { return @{ Result = Test-Path C:\Users\Public\Downloads\SQL2014-Setup.ini GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = { Test-Path C:\Users\Public\Downloads\SQL2014-Setup.ini } }
第äžã«ãMS SQL Server 2014ã®äžéšã®ãšãã£ã·ã§ã³ã®é
åžãããã«ã€ã¡ãŒãžãæ¥ç¶ããããšãèŠããŠããŸããïŒ
Script MSSQL { SetScript = { r:\setup.exe /configurationfile=C:\Users\Public\Downloads\SQL2014-Setup.ini /SAPWD=1q@w3e } GetScript = { return @{ Result = if ( Get-Service -Name "MSSQLSERVER" -ErrorAction SilentlyContinue ) { "Servise MSSQLSERVER is exist" } else { "Servise MSSQLSERVER not found" } GetScript = $GetScript; SetScript = $SetScript; TestScript = $TestScript } } TestScript = { if ( Get-Service -Name "MSSQLSERVER" -ErrorAction SilentlyContinue ) { $true } else { $false } } }
RïŒããšããŠæ¥ç¶ãããŠããExpress Editionãã©ã€ãã䜿çšããŸããã ãã®éçšã§ãããŒã¿ããŒã¹ãšã³ãžã³ãšFullSearchãããã³ç®¡çããŒã«ãã€ã³ã¹ããŒã«ãããŸãã TestScriptã®ãã¹ããæãç°¡åã§ã-MSSQLSERVERãµãŒãã¹ããããã©ããã
...ãããŠããµãŒããŒäžã®ããã»ã¹ã®ãªã¹ããããã€ã³ã¹ããŒã«ãéå§ããããšã«æ°ä»ããŸãã-å®éšãå®äºãããšèŠãªãããšãã§ããããšãæããã«ãªããŸããããããªãã«ã¹ã¿ãã€ãºã¯ç¶æ³ã«ãã£ãŠç°ãªããŸããåäœäžã®ã¢ããªã±ãŒã·ã§ã³ãç·æ¥ã«è¡šç€ºããå¿
èŠãããå Žåãäœããã®æ¹æ³ã§ã¢ããªã±ãŒã·ã§ã³ãååŸããŠã€ã³ã¹ããŒã«ããŸãã
ïŒç·æ¥ãªãã§ïŒèšç»çãªã€ã³ã¹ããŒã«ãããå Žåã¯ããã¡ã€ã¢ãŠã©ãŒã«ãäºåã«æ§æãããŠãŒãã£ãªãã£ïŒç£èŠãããã¯ã¢ããïŒãã€ã³ã¹ããŒã«ã§ããŸãã誰ã§ãç¬èªã®ãªãã·ã§ã³ã䜿çšã§ããŸãã ç§ãã¡ã䜿çšããŠãããã®ãããAWStatsã¯æ倧ã®å°é£ãåŒãèµ·ããå¯èœæ§ããããŸããTestScriptã®ã³ãŒãã¯å°ããªããã°ã©ã ã«äŒŒãŠããŸãããããã解決å¯èœã§ãã
ãããã£ãŠããã®æç¹ã§åæ¢ããããšã«ããŸããã ç§ã®æèŠã§ã¯ã誰ããèªåã®ç¶æ³ã«é©å¿ã§ããè¯ãäŸã§ããããšãããããŸããã
äºåçµæ
ç§ã®æèŠã§ã¯ãDSCã¯Windows Serverã®æ¬¡ã®ããŒãžã§ã³ãåŸ
ããã«æ¡çšããããšãã§ããŸãã
ãã®ãã¯ãããžãŒã¯ããã¡ã€ã³ã€ã³ãã©ã¹ãã©ã¯ãã£ã®ã°ã«ãŒãããªã·ãŒãå®å
šã«çœ®ãæããããšã¯ã§ããŸããããç¹å®ã®å©ç¹ããããŸãã
- æ§æãµãŒããŒã䜿çšããŠãæåã¢ãŒããšèªåã¢ãŒãã®äž¡æ¹ã§äœ¿çšã§ããŸãã
- Active Directoryã®ååšã«é¢ä¿ãªã䜿çšããããšããã°ã«ãŒãããªã·ãŒãšäžç·ã«äœ¿çšããããšãã§ããŸãã
- æ§æãã£ã¬ã¯ããªã¯ããŒãžã§ã³ç®¡çã·ã¹ãã ã«é
眮ã§ããŸãã
- Powershell 5.0ã®ãªãªãŒã¹ã«ãããè¿œå ã¢ãžã¥ãŒã«ã䜿çšãã䟿å©ãªæ¹æ³ãåŸãããŸãã-powershellgallery.comãåç
§ããŠãã ããã ã³ãã¥ããã£ã«ãã£ãŠäœæãããã¢ãžã¥ãŒã«ã¯ãã§ã«å€æ°ãããŸãã ããããããããã®äžã«ã¯æ¢ã«ç§ã®äŸã®ã¹ã¯ãªããã眮ãæããããšãã§ãããã®ããããŸãã
ãã®èšäºã®äŸã§ã¯ãšã©ãŒãçºçããå¯èœæ§ããããããããããå¹æçãªãœãªã¥ãŒã·ã§ã³ãããããšã«æ³šæããŠãã ããã
æåŸã®éèŠãªæ³šæäºé
ïŒç§ãç解ããããã«ãã»ããã¢ããããã»ã¹äžã«å¿
èŠãªåèµ·åã®åé¡ã¯ãæ°ããããŒãžã§ã³ã§ãã£ãŠã解決çã¯ãããŸããã ãããã£ãŠãäžèšã®æ§æã¯2ã€ã®ãã¹ïŒ2012R2ãš2016ã®äž¡æ¹ïŒã§é©çšãããã³ã³ããŒãã³ãã®ã€ã³ã¹ããŒã«ã«ãã£ãŠäžæãããåèµ·åãèŠæ±ãããŸãã 次ã«ãæ§æã®ã¢ããªã±ãŒã·ã§ã³ãå床éå§ããå¿
èŠããããŸãã
䟿å©ãªãªã³ã¯