Recipe problems with order excecution

Hi, I have a recipe called sqlserver_services.rb with 3 blocks and I want those blocks execute in sequence:

#BLOCK1

powershell_script "Enable-ADFeature" do
guard_interpreter :powershell_script
code "Add-WindowsFeature RSAT-AD-PowerShell"
not_if <<-EOF
$checkModule = Get-WindowsFeature RSAT-AD-PowerShell
if ( $checkModule.InstallState -eq "Available" ) { return $false; } else { return $true; }
EOF
end

#BLOCK2

sqlServicesHost =<<-EOF
$services = Get-WmiObject -ComputerName localhost win32_service -ErrorAction Stop | where {  $_.name -like  '*ac*' -and $_.startmode -eq 'auto' -and $_.state -eq 'running'} | ForEach-Object {$_.name.toLower()}

echo $services

EOF

hostServices = powershell_out(sqlServicesHost)

#BLOCK3

hostServices.stdout.each_line do | localService |
localService = localService.chomp
checkUserExist =<<-EOF
Import-Module ActiveDirectory
$username="#{newADUsername}"
$ADUser = Get-ADUser -Filter {SamAccountName -eq $username}
if($ADUser){ echo 1} else {echo 0}
EOF
checkUserExist = powershell_out(checkUserExist)
if ( checkUserExist.stdout.to_i )
print "El usuario existe, se evita configurar, se notificara a cos\n"
cosMessage += "mensaje importante";
next
end
end

When excute the recipe the BLOCK2 and BLOCK3 execute first the BLOCK1 and this functionallity break my logic.

The block3 fails because the block1 doesn't finish. How I ensure execute first the block1?

Hi,

Just wanted to pass this on to you, in case it’s helpful:

It looks like it might address the issue you’re having (although I admit I don’t use any Windows resources
myself, and I don’t have any direct fix for you. Hopefully the above article might help, or maybe someone else will jump in.

Karl

1 Like

Hi, @karlamrhein thanks, it's all I needed.