Suppose I have a product which I want to install on a non SSD drive, if exists. Otherwise, I want it to go on the drive C.
For example, the following configuration is supposed to install the Sql Server 2016 in the default location:
Configuration DevWorkstation
{
Import-DscResource –ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName SqlServerDsc
node localhost
{
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
SqlSetup 'InstallDefaultInstance'
{
InstanceName = 'MSSQLSERVER'
Features = 'SQLENGINE,SSMS'
SQLCollation = 'SQL_Latin1_General_CP1_CI_AS'
SourcePath = '\\fileserver\installs\en_sql_server_2016_developer_with_service_pack_1_x64_dvd_9548071'
SQLSysAdminAccounts = @('Administrators')
DependsOn = '[WindowsFeature]NetFramework45'
}
}
}
However, I would like to check first if there is a non SSD drive and if present install it there.
As I understand it, I cannot use Powershell code, because that code runs during compilation. I need it to run during the configuration.
How do I do it?
Using the Azure Automation DSC pull server you cannot really do this. As you mention, the compilation of the DSC file occurs on the Automation server and it has no details of the server it is going to be applied to, so it cannot factor that in. At the time of compilation, you will provide a drive for the installation to occur on, and that is what will get used. This is where DSC Pull servers fall down compared to something like Chef or Puppet, where these tools do have information on the client machines and can use this at compile time.
There's not really a way around this using the automation server, other than using a consistent drive letter and then when you build your Azure VM making sure that this drive is configured the way you want it (SSD or not).
Another option is instead of using the automation server, you can use the Azure VM DSC extension to push the DSC files to the VM and apply. If you do this you lose all the benefits of centralised management and reporting for DSC, but your DSC file is compiled on the server it is going to run on, so can take into account local variables. See here for more details on the DSC extension.