Report abuse

apache/manifests/init.pp

class apache::webserver {
  define vhost ($serveralias) {
    notify { "Creating $name with serveralias $serveralias.":; }
  }

  define redirect ($site, $to) {
    notify { "Adding redirect from $name to $to for $site":; }
  }
}

nginx/manifests/init.pp

class nginx::webserver {
  define vhost ($serveralias) {
    notify { "Creating $name with serveralias $serveralias.":; }
  }

  define redirect ($site, $to) {
    notify { "Adding redirect from $name to $to for $site":; }
  }
}

http/manifests/init.pp

class http {
  search $httpdtype
  include webserver

  define site ($serveralias = false) {
    search $httpdtype

    webserver::vhost { "$name":
      serveralias => $serveralias,
    }
  }

  define redirect ($site, $to) {
    search $httpdtype

    webserver::redirect { "$name":
      site => $site,
      to   => $to,
    }
  }
}

sites/manifests/init.pp

class sites::example_com {
  http::site { "www.example.com":
    serveralias => "example.com",
  }

  http::redirect { "/old-file":
    site => "www.example.com",
    to   => "/new-file",
  }
}

First site.pp

node etch {
  $httpdtype = "nginx"

  include http
  include sites::example_com
}

First puppet output

notice: Adding redirect from /old-file to /new-file for www.example.com
notice: //sites::example_com/Http::Redirect[/old-file]/Nginx::Webserver::Redirect[/old-file]/Notify[Adding redirect from /old-file to /new-file for www.example.com]/message: defined 'message' as 'Adding redirect from /old-file to /new-file for www.example.com'
notice: Creating www.example.com with serveralias example.com.
notice: //sites::example_com/Http::Site[www.example.com]/Nginx::Webserver::Vhost[www.example.com]/Notify[Creating www.example.com with serveralias example.com.]/message: defined 'message' as 'Creating www.example.com with serveralias example.com.'
notice: Finished catalog run in 0.04 seconds

Second site.pp

node etch {
  $httpdtype = "apache"

  include http
  include sites::example_com
}

Second puppet output

notice: Adding redirect from /old-file to /new-file for www.example.com
notice: //sites::example_com/Http::Redirect[/old-file]/Apache::Webserver::Redirect[/old-file]/Notify[Adding redirect from /old-file to /new-file for www.example.com]/message: defined 'message' as 'Adding redirect from /old-file to /new-file for www.example.com'
notice: Creating www.example.com with serveralias example.com.
notice: //sites::example_com/Http::Site[www.example.com]/Apache::Webserver::Vhost[www.example.com]/Notify[Creating www.example.com with serveralias example.com.]/message: defined 'message' as 'Creating www.example.com with serveralias example.com.'
notice: Finished catalog run in 0.04 seconds