microsoft / PowerShell-DSC-for-Linux

PowerShell Desired State Configuration - for Linux
Other
338 stars 131 forks source link

Failure happens when LCM is processing configuration #19

Closed datenteiler closed 9 years ago

datenteiler commented 9 years ago

First: I have installed OMI server and PSDSC in April this year on my Raspberry Pi 2 with Raspbian (Debian Wheezy) and everything worked fine from my Win 8.1 box.

Today I have reinstalled the Raspi with Raspbian and I have downloaded and compiled the new OMI package and PSDSC:

su root
mkdir /root/downloads
cd /root/downloads
wget https://collaboration.opengroup.org/omi/documents/32721/omi-1.0.8-1.tar.gz
tar -xvf omi-1.0.8-1.tar.gz
cd omi-1.0.8/
sed -i "s/IX86/$(uname -m)/g" buildtool
sed -i "s/i686/$(uname -m)/g" buildtool
./configure && make 
./output/install
 [...]
 Successfully installed under: ///opt/omi-1.0.8

Then I installed PSDSC:

cd /root/downloads
wget https://github.com/MSFTOSSMgmt/WPSDSCLinux/releases/download/V1.0.0-320/PSDSC.tar
tar -xvf PSDSC.tar
mv ./dsc/* ./
./configure && make
make reg

I started the OMI server with:

/opt/omi-1.0.8/bin/omiserver -d

Then I tried to start my first configuration from my Win8.1 box which worked perfectly in April. Before I have exchanged the nx Module in %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules with the new one: https://github.com/MSFTOSSMgmt/WPSDSCLinux/releases/download/V1.0.0-320/nx.zip

$username = "root"
$hostname = "10.42.0.14"
$port = 5985

$Cred = Get-Credential -UserName root -Message "Enter root password"
$CimOptions = New-CimSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck 
$cimSession = New-CimSession -Credential $Cred -ComputerName $hostname -Port $port -Authentication Basic -SessionOption $CimOptions
$cimSession

Id : 1 Name : CimSession1 InstanceId : 03517cd4-5cd8-499c-9818-602b7ad34a6c ComputerName : 10.42.0.14 Protocol : WSMAN

Configuration HalloWelt
{
param (
    [String]$ComputerName,
    [String]$Filename,
    [String]$Message
)
    Import-DscResource -ModuleName nx
    node $ComputerName
    {
    nxFile Welt
        {
            Ensure = "Present"
            Type = "File"
            DestinationPath = "/root/$Filename"
            Contents=" Welt!"
        }
    nxScript Hallo {
                TestScript = ''
                SetScript  = @'
#!/bin/bash
exit 0
'@
                GetScript  = @"
#!/bin/bash
echo $Message            
cat /root/$Filename 
rm /root/$Filename
exit 0
"@
        }
    }
}
$null = md C:\dscconfig -ErrorAction SilentlyContinue 
HalloWelt -ComputerName 10.42.0.14 -Message "Hallo" -Filename "Welt" -OutputPath:"C:\dscconfig"
Start-DscConfiguration -CimSession:$cimSession -Path:"C:\dscconfig" -Wait

Failed to apply the configuration. These resources produced errors: [nxFile]Welt, [nxScript]Hallo. Detailed error information can be found in the log file.

In dsc.log I found this:

This event indicates that failure happens when LCM is processing the configuration. ErrorId is 1. ErrorDetail is The SendConfigurationApply function did not succeed.. ResourceId is [nxFile]Welt and SourceInfo is C:\Users\christian\SkyDrive\PowerShell\DSC\HalloWelt.ps1::11::5::nxFile. ErrorMessage is A general error occurred, not covered by a more specific error code.. 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Displaying messages from the engine: WMI channel 1 ResourceID: [nxScript]Hallo Message : [raspberrypi]: LCM: [ Start Resource ] [[nxScript]Hallo]
1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Getting a registration instance for MSFT_nxScriptResource 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Moving the resource [nxScript]Hallo of class MSFT_nxScriptResource to desired state. 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Method Exec_WMIv2Provider started with parameters Class name: MSFT_nxScriptResource Resource ID: [nxScript]Hallo Flags: 0 Execution Mode: 192 DSC resource Namespace: null 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Executing operations for WMIv2 DSC resource MSFT_nxScriptResource with resource name [nxScript]Hallo 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Invoking session and getting result for namespace root/Microsoft/DesiredStateConfiguration, classname MSFT_nxScriptResource for method TestTargetResource 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Displaying messages from the engine: WMI channel 1 ResourceID: [nxScript]Hallo Message : [raspberrypi]: LCM: [ Start Test ] [[nxScript]Hallo]
1965/07/20 06:18:49: ERROR: null(0): EventId=1 Priority=ERROR Job : This event indicates that failure happens when LCM is processing the configuration. ErrorId is 1. ErrorDetail is The SendConfigurationApply function did not succeed.. ResourceId is [nxScript]Hallo and SourceInfo is C:\Users\christian\SkyDrive\PowerShell\DSC\HalloWelt.ps1::18::5::nxScript. ErrorMessage is A general error occurred, not covered by a more specific error code.. 1965/07/20 06:18:49: ERROR: null(0): EventId=1 Priority=ERROR Job : DSC Engine Error : Error Message Failed to apply the configuration. These resources produced errors: [nxFile]Welt, [nxScript]Hallo. Detailed error information can be found in the log file. Error Code : 1 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Deleting file from /opt/omi-1.0.8/etc/dsc/configuration/Pending.mof 1965/07/20 06:18:49: INFO: null(0): EventId=3 Priority=INFO Job : Method CallSetConfiguration ended successfully

I have no idea, what went wrong.

bielawb commented 9 years ago

My suggestion: try to run omniserver interactively and see if you get any feedback from it. It helped me few times in the past to identify root cause. Messages from service, logs, -Verbose were usually not very helpful.

KrisBash commented 9 years ago

A null value/empty string for testscript is going to be problematic. The testscript is executed every time you do a start-dscconfiguration. Admittedly the error could be handled better, but I suspect that's the issue. The returncode of the testscript execution tells the agent whether or not the SetScript needs to be run.

datenteiler commented 9 years ago

Thank you very much for your help. I tried a simpler configuration:

$username = "root"
$hostname = "10.42.0.14"
$port = 5985

$Cred = Get-Credential -UserName root -Message "Enter root password"
$CimOptions = New-CimSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck 
$cimSession = New-CimSession -Credential $Cred -ComputerName $hostname -Port $port -Authentication Basic -SessionOption $CimOptions
$cimSession

Configuration MyDSCDemo
{
    Import-DSCResource -Module nx
    Node "10.42.0.14"{
        nxFile myTestFile2
        {
            Ensure = "Present"
            Type = "File"
            DestinationPath = "/root/dsctest2"
            Contents="This is my new DSC Test!"
        }
    }
}

MyDSCDemo -OutputPath:"C:\temp"

Start-DscConfiguration -CimSession:$cimSession -Path:"C:\temp" -Verbose -Wait

This time I started the omiserver interactively and get the following error messeage:

root@raspberrypi:~# /opt/omi-1.0.8/bin/omiserver 
python: can't open file '/opt/omi//lib/Scripts/client.py': [Errno 2] No such file or directory
error on socket: (104) "Connection reset by peer"
unable to read value

The path to "client.py" is wrong. How can I correct this?

bielawb commented 9 years ago

Make sure to define OMI_HOME=/opt/omi-1.0.8 (I believe that is the default value if you install from sources).

datenteiler commented 9 years ago

Thank you very much Bartek. That was the point. I missed

export OMI_HOME=/opt/omi-1.0.8/

before starting omiserver. It's working now. :-)