If statement in manifest file for creating replica domain controller

asked 2018-11-10 02:01:42 -0600

dragan979 gravatar image

I'm using pupppet enterprise 2018, i installed this module:

https://forge.puppet.com/puppetlabs/dsc

I created dsc class which creates first domain controller belllow code i put in init.pp and assigned class dsc to windows node via Puppet web console, code below works fine.

class dsc{

file {
 ['c:/NTDS']:
  ensure => directory
}

dsc_windowsfeature  {'dns':
            dsc_ensure => 'Present',
            dsc_name => 'DNS',
        }

dsc_windowsfeature  { 'addsinstall':
            dsc_ensure => 'Present',
            dsc_name => 'AD-Domain-Services',
        }

dsc_windowsfeature  {'addstools':


           dsc_ensure => 'Present',
            dsc_name => 'RSAT-ADDS',
        }

dsc_windowsfeature  {'addnstools':
            dsc_ensure => 'Present',
            dsc_name => 'RSAT-DNS-Server',
        }
dsc_xaddomain   { 'firstdc':
     subscribe => Dsc_windowsfeature['addsinstall'],
            dsc_domainname => 'ad.contoso.com',
 dsc_domainadministratorcredential => {
           'user' => 'pagent',
           'password' => Sensitive(lookup('password'))
 },
     dsc_safemodeadministratorpassword   => {
 'user' => 'pagent',
 'password' => 'password' => Sensitive(lookup('password'))
            },
            dsc_databasepath => 'c:\NTDS',
            dsc_logpath => 'c:\NTDS',
       }
reboot {'dsc_reboot':
 message => 'DSC has requested a reboot',
when => pending,
}

}

this code will add additional domain controller, i put this code in separate file, addc.pp

class  addc {


{
     ['c:/NTDS']:
      ensure => directory
    }

dsc_windowsfeature  {'dns':
            dsc_ensure => 'Present',
            dsc_name => 'DNS',
        }

dsc_windowsfeature  { 'addsinstall':
        dsc_ensure => 'Present',
        dsc_name => 'AD-Domain-Services',
    }

dsc_windowsfeature  {'addstools':


       dsc_ensure => 'Present',
        dsc_name => 'RSAT-ADDS',
    }

dsc_windowsfeature  {'addnstools':
            dsc_ensure => 'Present',
            dsc_name => 'RSAT-DNS-Server',
        }

dsc_xwaitforaddomain {'DscForestWait': 

   dsc_domainname => ad.contoso.com, 
   dsc_domainusercredential=> cred,
   dsc_retrycount => 5,
   dsc_retryintervalsec => 5,
   subscribe => Dsc_windowsfeature['addsinstall'],
}
dsc_xaddomaincontroller {'ReplicaDC': 

   dsc_domainname => ad.contoso.com, 
   dsc_domainsdministratorcredential => $DomainCreds, 
   dsc_safemodeadministratorpassword => $SafeModeAdminCreds,
   dsc_databasepath => "C:\NTDS",
   dsc_logpath => "C:\NTDS",
   dsc_sysvolpath => "C:\SYSVOL",
   subscribe => Dsc_xwaitforaddomaind['DscForestWait'],
    }

}

Is it possible, in init.pp to put statemet to check: if c:\ntds exists and it's not empty run code in addc.pp file (in addc class), otherwise run only dsc class (init.pp)

edit retag flag offensive close merge delete