microsoft / PowerShell-DSC-for-Linux

PowerShell Desired State Configuration - for Linux
Other
339 stars 129 forks source link

wrong path in deb packages #674

Open graf0 opened 4 years ago

graf0 commented 4 years ago

Hello!

When I try to compile to mof dsc resources under powershell 7 linux, I have following error:

ParserError: /home/graf0/test.ps1:1
Line |
   1 |  Configuration ExampleConfiguration
     |                ~~~~~~~~~~~~~~~~~~~~
     | System.Management.Automation.PSArgumentException: No files matching '/etc/opt/omi/conf/dsc/configuration/BaseRegistration/BaseResource.schema.mof' were found.    at
     | Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.GetFileContent(String fullFilePath)    at
     | Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.ParseSchemaMof(String filePath)    at
     | Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.ImportClasses(String path, Tuple`2 moduleInfo, Collection`1 errors, Boolean
     | importInBoxResourcesImplicitly)    at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.Initialize(Collection`1 errors, List`1 modulePathList)    at
     | Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.LoadDefaultCimKeywords(Dictionary`2 functionsToDefine, Collection`1 errors, List`1 modulePathList,
     | Boolean cacheResourcesFromMultipleModuleVersions)    at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.LoadDefaultCimKeywords(Collection`1 errors)
     | at System.Management.Automation.Language.Parser.ConfigurationStatementRule(IEnumerable`1 customAttributes, Token configurationToken)

Files are there - but on linux file names are case sensitive. So we have:

/etc/opt/omi/conf/dsc/configuration/baseregistration/baseresource.schema.mof

Changing this to:

/etc/opt/omi/conf/dsc/configuration/BaseRegistration/BaseResource.schema.mof

seems to solve the problem.

Artalus commented 3 years ago

Still happens with RPM at least in omi-1.6.6-0.ssl_100.ulinux.x64.rpm. Renaming files indeed helps.

a30000931 commented 3 years ago

this is still an issue with: dsc-1.1.1-926.x86_64

had to run this: mv /etc/opt/omi/conf/dsc/configuration/baseregistration /etc/opt/omi/conf/dsc/configuration/BaseRegistration mv /etc/opt/omi/conf/dsc/configuration/BaseRegistration/baseresource.schema.mof /etc/opt/omi/conf/dsc/configuration/BaseRegistration/BaseResource.schema.mof

how hard is it to get case right?

sql-sith commented 3 years ago

Glad to find this - I was really wondering what I was doing wrong and didn't notice the casing at all.

Another workaround is to add lower-case symbolic links that point to the mixed-case names. This seems safer to me than renaming files supplied by the vendor. As far as I can tell, you only need to link one directory and one file:

cd /etc/opt/omi/conf/dsc/configuration
ln -s baseregistration ./BaseRegistration

cd ./baseregistration
ln -s baseresource.schema.mof BaseResource.schema.mof

Not a big difference, but this does work for me, plus, as I already mentioned, I don't have to actually change the MS files. With my luck, I bet MS will fix this in the next release and then I'll be wondering why I can't get through the install package.

gaelcolas commented 3 years ago

Maybe something for @anmenaga to comment on, but in PSDSCv3 the BaseResource have changed to be within the PSDSC module. I also suspect that this was fixed in PSDSCv2.0.5, but I don't know what this OMI package is shipping.

anmenaga commented 3 years ago

This is a de-sync between v2 DSC code in SMA dll/PowerShell and whatever is deploying lower-cased files to /etc/opt/omi/conf/dsc/configuration - casing is hardcoded in v2 DSC code and will break when run on lower-cased files.

v2.0.5 PSDesiredStateConfiguration module on PS Gallery ships with baseregistrations in expected case, so theoretically another workaround that should work with v2.0.5 is to setup DSC_HOME env variable before starting configuration compilation. Something like this (assuming v2.0.5 PSDesiredStateConfiguration module is visible through $env:PSModulePath)

# to get v2.0.5 from PS Gallery run
# Install-Module -Name PSDesiredStateConfiguration -Repository PSGallery -MaximumVersion 2.99
#
$modulebase = Split-Path (Get-Module -ListAvailable -Name PsDesiredStateConfiguration | Select-Object -First 1 | ? {$_.Version -le '2.99'}).Path
$env:DSC_HOME = Join-Path $modulebase "Configuration"
if (Test-Path $env:DSC_HOME) { Write-Verbose -Verbose "Using DSC BaseRegistrations from $env:DSC_HOME" } else { Write-Error "DSC BaseRegistrations not found in $env:DSC_HOME" }
# now start configuration compilation
piotrminkina commented 10 months ago

To work with PowerShell + DSC scripts on Ubuntu Linux, I had to do such patches, after installing OMI.

        echo 'Configuring LD Cache for OMI...'
        echo '/opt/omi/lib' >/etc/ld.so.conf.d/omi.conf
        ldconfig >/dev/null
        ldconfig --print-cache | grep 'libmi\.so' >/dev/null \
            && echo 'OMI libraries are available.' \
            || { echo 'OMI libraries are NOT available!'; return 1; }

        echo 'Fixing default OMI installation...'
        ln --symbolic --force --no-dereference \
            /etc/opt/omi/conf/dsc/configuration/baseregistration/ \
            /etc/opt/omi/conf/dsc/configuration/BaseRegistration
        ln --symbolic --force --no-dereference \
            /etc/opt/omi/conf/dsc/configuration/baseregistration/baseresource.schema.mof \
            /etc/opt/omi/conf/dsc/configuration/BaseRegistration/BaseResource.schema.mof

Scripts from DSC validates nicely in VSCode :)