adding require to if/elseif statement?

11 views
Skip to first unread message

Jason McMahan

unread,
Sep 11, 2018, 8:08:53 AM9/11/18
to Puppet Users
Good day,
I am attempting to add require to an if statement and not sure i am doing it right. Any help would be greatly appreciated.

If the machine is joined to our internal domain it will use a file resource, if external i am using a invoke-webrequest as the file is on azure blob storage.
  

  $file_source = lookup('application.client')

  if $facts['domain'] == 'internal' {
    file { 'sccm_setup':
      path    => 'C:/Windows/ccmsetup/ccmsetup.exe',
      source  => "$file_source /file.exe"
    }
  }
  elsif $facts['domain'] != 'internal' {
    exec { 'client_setup':
      command => 'Invoke-WebRequest "$$file_source/file.exe " -outfile "C:/Windows/dir/file.exe" ',
      provider => powershell,
      creates => 'C:/Windows/dir/file.exe'
    }
  }
 package { 'client_package':
}

Michael Watters

unread,
Sep 11, 2018, 8:27:49 AM9/11/18
to Puppet Users
What you have there looks fine but I would change the elsif to an else statement.

Jason McMahan

unread,
Sep 11, 2018, 9:09:25 AM9/11/18
to Puppet Users
Thanks Michael, 
I think my problem is not syntax but rather the invoke-webrequest is not actually completing before moving to the package resource. Then as the file doesnt exist the run fails.
Back to drawing board.

Appreciate the quick reply.

Michael Watters

unread,
Sep 11, 2018, 9:36:27 AM9/11/18
to Puppet Users
You should be able to add a require => Package['client_package'] parameter to the exec resource to resolve this.  For example:


$file_source = lookup('application.client')

  if $facts['domain'] == 'internal' {
   file { 'sccm_setup':
     path    => 'C:/Windows/ccmsetup/ccmsetup.exe',
     source  => "$file_source /file.exe"
   }
 }
 else {
   exec { 'client_setup':
     command => 'Invoke-WebRequest "$$file_source/file.exe " -outfile "C:/Windows/dir/file.exe" ',
     provider => powershell,
     creates => 'C:/Windows/dir/file.exe'
     
require => Package['client_package'],
   }
 }
package { 'client_package':
}

Jason McMahan

unread,
Sep 11, 2018, 12:29:48 PM9/11/18
to Puppet Users
Thanks Michael, 
What i ended up having to do was create a separate powershell process then run invoke-webrequest there because start-process allows for -wait.

   exec { 'client_setup':
     command => '(Start-Process powershell -ArgumentList (Invoke-WebRequest "Invoke-WebRequest "$$file_source/file.exe " -outfile C:/Windows/dir/file.exe))',
     provider => powershell,
     creates => 'C:/Windows/dir/file.exe'
     
require => Package['client_package'],
   }
(Start-Process powershell -ArgumentList (Invoke-WebRequest "Invoke-WebRequest "$$file_source/file.exe " -outfile C:/Windows/dir/file.exe))
Reply all
Reply to author
Forward
0 new messages