Skip to content

Instantly share code, notes, and snippets.

@bielawb bielawb/DSCDemo.ps1
Created Aug 31, 2014

Embed
What would you like to do?
Linux DSC:
configuration LinuxDscDemo {
param (
[string]$ComputerName
)
Import-DscResource -Module nx
Node $ComputerName {
nxUser LinuxDsc {
UserName = 'LinuxDSC'
Ensure = 'Present'
}
nxGroup Dsc {
GroupName = 'DSC'
Members = 'bielawb', 'LinuxDSC'
DependsOn = '[nxUser]LinuxDsc'
}
nxFile TestFile {
DestinationPath = '/tmp/demo'
Contents = "Testowy plik tekstowy...`n"
Owner = 'bielawb'
Group = 'DSC'
DependsOn = '[nxGroup]Dsc'
Mode = '660'
}
nxService http {
Name = 'sshd'
Controller = 'init'
State = 'Running'
Enabled = $true
}
nxScript SimpleScript {
TestScript = @'
#!/usr/bin/python
import os, sys
from datetime import datetime
file = '/tmp/script'
if not os.path.exists(file):
sys.exit(1)
mtime = os.stat(file)[8]
diff = datetime.now() - datetime.fromtimestamp(mtime)
if diff.seconds > 300:
sys.exit(1)
sys.exit(0)
'@
GetScript = @'
#!/usr/bin/python
import os, sys
from datetime import datetime
file = '/tmp/script'
if not os.path.exists(file):
print 'Missing...'
sys.exit(0)
mtime = os.stat(file)[8]
diff = datetime.now() - datetime.fromtimestamp(mtime)
if diff.seconds > 300:
print 'Too old'
sys.exit(0)
print 'Fine!'
sys.exit(0)
'@
SetScript = @'
#!/usr/bin/python
from datetime import datetime
file = '/tmp/script'
with open(file, 'a') as fileHandle:
fileHandle.write("last modified: %s\n" % str(datetime.now()))
'@
User = 'root'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.