This article is Part 8 in a 9-Part series about POSHOrigin, a PowerShell module that aims to assist you in managing your Infrastructure via custom PowerShell DSC resources.
- Part 1 - POSHOrigin - Summary
- Part 2 - POSHOrigin - Installation
- Part 3 - POSHOrigin - Configuration File
- Part 4 - POSHOrigin - Defaults File
- Part 5 - POSHOrigin - Load, Test, and Execute Configurations
- Part 6 - POSHOrigin - Sharing Configurations
- Part 7 - POSHOrigin - Credential Resolvers
- Part 8 - POSHOrigin - Examples <<
- Part 9 - POSHOrigin - Wrapping Up
Examples
Creating a VMware VM using the POSHOrigin_vSphere DSC module
This will create a VMware VM called serverxyz, join it to an Active Directory domain, install the Chef client on it, then assign and execute a Chef run list.
my_vm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
resource 'POSHOrigin_vSphere:vm' 'serverxyz' @{
ensure = 'present'
description = 'Test VM'
vCenter = 'vcenter01.mydomain.com'
datacenter = 'datacenter01'
cluster = 'cluster01'
vmTemplate = 'W2K12_R2_Std'
customizationSpec = 'W2K12_R2'
powerOnAfterCreation = $true
totalvCPU = 2
coresPerSocket = 1
vRAM = 4
initialDatastore = 'datastore01'
networks = @{
portGroup = 'VLAN_500'
ipAssignment = 'Static'
ipAddress = '192.168.195.254'
subnetMask = '255.255.255.0'
defaultGateway = '192.168.195.1'
dnsServers = @('192.168.50.50','192.168.50.60')
}
disks = @(
@{
name = 'Hard disk 1'
sizeGB = 50
type = 'flat'
format = 'Thick'
volumeName = 'C'
volumeLabel = 'NOS'
blockSize = 4096
}
)
vCenterCredentials = Get-POSHOriginSecret 'pscredential' @{
username = '[email protected]'
password = '<your password here>'
}
guestCredentials = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = '<your password here>'
}
domainJoinCredentials = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = '<your password here>'
}
provisioners = @(
@{
name = 'DomainJoin'
options = @{
domain = 'mydomain.com'
oupath = 'ou=servers, dc=mydomain, dc=com'
}
}
@{
name = 'Chef'
options = @{
nodeName = 'serverxyz.mydomain.com'
url = 'https://chefsvr.mydomain.com/organizations/myorg'
source = '<URL to Chef MSI file>'
validatorKey = '<URL to organization validator .pem file>'
cert = '<URL to issuing CA .crt file>'
runList = @(
@{ role = 'base::setup_base' }
@{ recipe = 'myapp::default' }
)
environment = 'dev'
attributes = @{
'myapp.prop1' = 42
'myapp.prop2' = 'something'
}
}
}
)
}
Creating a NetScaler VIP using the POSHOrigin_NetScaler DSC module
This will create a Citrix NetScaler load balancer server instance pointing to the IP of the VM we just created (192.168.195.254), as well as a VIP with an IP of 192.168.100.100.
my_ns_resources.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
resource 'POSHOrigin_NetScaler:LBServer' 'serverxyz' @{
Ensure = 'Present'
NetScalerFQDN = 'mynetscaler.mydomain.com'
IPAddress = '192.168.195.254'
Comments = 'This is a comment'
TrafficDomainId = 1
State = 'ENABLED'
Credential = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = '<your password here>'
}
}
resource 'POSHOrigin_NetScaler:LBVirtualServer' 'lbserverxyz' @{
Ensure = 'Present'
NetScalerFQDN = 'mynetscaler.mydomain.com'
Comments = 'This is a comment'
IPAddress = '192.168.100.100'
Port = 80
ServiceType = 'HTTP'
LBMethod = 'ROUNDROBIN'
State = 'ENABLED'
Credential = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = 'K33p1t53cr3tK33p1t5@f3'
}
}
Creating a DNS A record using the POSHOrigin_ActiveDirectoryDNS DSC module
This will create an A record in DNS called web01.mydomain.local that points to the IP of the VM we just created (10.45.195.254).
my_dns_record.ps1
1
2
3
4
5
6
7
8
9
10
resource 'ActiveDirectoryDNS:ARecord' 'web01' @{
ZoneName = 'mydomain.local'
IpAddress = '10.45.195.254'
DnsServer = 'dc01.mydomain.com'
CreatePtr = $true
Credential = Get-POSHOriginSecret 'pscredential' @{
username = 'mydomain\administrator'
password = 'K33p1t53cr3tK33p1t5@f3'
}
}
Using all three resources in the same file
Here is an example of combined all resources into a single file as well as extracting some of the configurations into defaults files.
my_app_env.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
resource 'POSHOrigin_vSphere:VM' 'serverxyz' @{
defaults = '.\my_vm_defaults.psd1'
totalvCPU = 2
coresPerSocket = 1
vRAM = 4
networks = @{
portGroup = 'VLAN_500'
ipAssignment = 'Static'
ipAddress = '192.168.100.100'
subnetMask = '255.255.255.0'
defaultGateway = '192.168.100.1'
dnsServers = @('192.168.50.50','192.168.50.60')
}
vCenterCredentials = Get-POSHOriginSecret 'pscredential' @{
username = '[email protected]'
password = '<your password here>'
}
guestCredentials = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = '<your password here>'
}
domainJoinCredentials = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = '<your password here>'
}
provisioners = @(
@{
name = 'DomainJoin'
options = @{
domain = 'mydomain.com'
oupath = 'ou=servers, dc=mydomain, dc=com'
}
}
@{
name = 'Chef'
options = @{
nodeName = 'vm01.mydomain.com'
url = 'https://chefsvr.mydomain.com/organizations/myorg'
source = '<URL to Chef MSI file>'
validatorKey = '<URL to organization validator .pem file>'
cert = '<URL to issuing CA .crt file>'
runList = @(
@{ role = 'base::setup_base' }
@{ recipe = 'myapp::default' }
)
environment = 'prod'
attributes = @{
'myapp.prop1' = 42
'myapp.prop2' = 'something'
}
}
}
)
}
resource 'POSHOrigin_NetScaler:LBServer' 'serverxyz' @{
defaults = '.\my_ns_defaults.psd1'
ipAddress = '192.168.100.100'
comments = 'This is a comment'
trafficDomainId = 1
state = 'ENABLED'
credential = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = 'K33p1t53cr3tK33p1t5@f3'
}
}
resource 'POSHOrigin_NetScaler:LBVirtualServer' 'lbserverxyz' @{
defaults = '.\my_ns_defaults.psd1'
comments = 'This is a comment'
ipAddress = '192.168.100.101'
port = 80
serviceType = 'HTTP'
lbMethod = 'ROUNDROBIN'
state = 'ENABLED'
credential = Get-POSHOriginSecret 'pscredential' @{
username = 'administrator'
password = 'K33p1t53cr3tK33p1t5@f3'
}
}
resource 'POSHOrigin_ActiveDirectoryDNS:ARecord' 'web01' @{
defaults = '.\my_vm_defaults.psd1'
ipAddress = '10.45.195.254'
credential = Get-POSHOriginSecret 'pscredential' @{
username = 'mydomain\administrator'
password = 'K33p1t53cr3tK33p1t5@f3'
}
}
Cheers