Ask Your Question

Create an IIS website only if the directory doesn't exist

asked 2014-09-01 10:10:49 -0600

marcusdempsey gravatar image


I'm new to using puppet, so forgive me if this is a simple solution, but I've had a look around and haven't found the answer. I'm using puppet with the opentable/IIS module and would like to create an IIS website but only if the website directory doesn't currently exist.

The code I have below will create the website, however it will also re-create the website each time, which I don't want to happen. What I would like is something like below, if the path doesn't exist, create.

$name = "websitename"
$sitepath = "c:\inetpub\wwwroot\website"

if ($sitepath doesnt exist) {
  iis::manage_site { "$environment$name":
    site_path     => $sitepath,
    port          => '80',
    host_header   => $url,
    app_pool      => "$environment$name",

Can anyone point me in the right direction?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-09-02 07:11:14 -0600

marcusdempsey gravatar image

Fixed it by adding in the following:

  $SiteExists = "Test-Path $sitepath"

  if ($SiteExists in ['false']) {
    iis::manage_site { "$environment$bede_domain":
      ensure        => installed,
      site_path     => $sitepath,
      port          => '80',
      app_pool      => "$environment$bede_domain",
edit flag offensive delete link more


I'm not sure I understand how this works. $SiteExists is a string literal, so the conditional will always be false.

mapa3m gravatar imagemapa3m ( 2014-09-02 07:14:39 -0600 )edit

answered 2014-09-02 06:34:58 -0600

mapa3m gravatar image

iis::manage_site is supposed to handle this internally. If it's not happening, then there is either an issue with the puppet-iis module, or with the particulars of your deployment. Puppet-iis seems to be heavily reliant on PowerShell, perhaps something is causing an issue with it?

edit flag offensive delete link more


The reason I would like to add a check is because we deploy a number of website versions in that location (each having a different subfolder), and I only want puppet to create the website once - if the sitepath doesn't initially exist. I really dont want to modify the existing module.

marcusdempsey gravatar imagemarcusdempsey ( 2014-09-02 06:54:18 -0600 )edit

I'm not sure there's a way to properly implement this in Puppet. iis::manage_site doesn't support "refreshonly". I suppose it's possible to patch the module and add that parameter

mapa3m gravatar imagemapa3m ( 2014-09-02 07:15:25 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2014-09-01 10:10:49 -0600

Seen: 2,787 times

Last updated: Sep 02 '14