Ask Your Question
2

How to create an apache vhost in hiera when using puppetlabs/apache

asked 2013-06-07 12:48:45 -0500

jerrac gravatar image

updated 2013-06-09 16:03:26 -0500

ramindk gravatar image

I've installed the http://forge.puppetlabs.com/puppetlabs/apache module, and I'm trying to set up a vhost on my node. My vm.alpha.lab.json file looks like:

{
  "classes": [
    "apache",
    "apache::mod::php",
    "ntp"
  ],
  "apache::vhost::priority": "10",
  "apache::vhost::vhost_name": "vm.alpha.lab",
  "apache::vhost::port": "80",
  "apache::vhost::docroot": "/var/www"
}

From the docs say, I should be able to set the apache::vhost's params like that. Unfortunately, I get an error when trying to apply the manifest.

Jun 7 06:20:05 ubuntu-server-12042-x64-vbox4210-nocm puppet-agent[16942]: Could not retrieve catalog from remote server: Error ...

(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-06-07 13:58:17 -0500

llowder gravatar image

updated 2013-10-07 10:52:23 -0500

The apache::vhost is not a class, it is a defined type. Databinding currently only works with classes.

If you want to pull this data from hiera, create a hash of hashes and use creste_resources().

mymodule::my_vhosts:
  host1:
    priority: "10"
    vhost_name": "vm.alpha.lab"
    port": "80"
    docroot": "/var/www1"
  host2:
    priority: "10"
    vhost_name": "vm.beta.lab"
    port": "80"
    docroot": "/var/www2"
  host3:
    priority": "10"
    vhost_name": "vm.charlie.lab"
    port": "80"
    docroot": "/var/www3"

If you also want to use databindings, you will need to create a wrapper class of some sort that takes the hash of hashes as a parameter.

edit flag offensive delete link more

Comments

Ah, that would explain why it doesn't work. Know of any good apache modules that do let you use hiera?

jerrac gravatar imagejerrac ( 2013-06-07 15:02:50 -0500 )edit

The puppetlabs-apache module *does* let you use hiera. What it does not do is import a complete server composition from hiera. I suggest you make a wrapper class that calls ...(more)

supercow gravatar imagesupercow ( 2013-06-09 11:57:37 -0500 )edit

So, I tried using create_resources() in my node definition, but it keeps saying it can't find the vhost template file. The template location is defined in an apache::params ...(more)

jerrac gravatar imagejerrac ( 2013-06-10 14:28:59 -0500 )edit

Make sure you are using the newest version of the module. I don't know off hand about your other question, I'll have to check the code and get ...(more)

llowder gravatar imagellowder ( 2013-06-10 15:03:42 -0500 )edit

Very interesting thread. @jerrac - would it be possible to update your posting with actual working configuration for the puppetlabs/apache + hierra ?

bohdan.m gravatar imagebohdan.m ( 2013-08-12 13:20:50 -0500 )edit
2

answered 2013-10-04 06:59:43 -0500

jon_proulx gravatar image

This is really a follow on to the very help full suggestion by Llowder, but too long to fit as a comment. First a syntax note, hashes in yaml don't have comas so hiera should be:

 mymodule::my_vhosts:
      host1:
        priority: "10"
        vhost_name: "vm.alpha.lab"
        port: "80"
        docroot: "/var/www1"
      host2:
        priority: "10"
        vhost_name: "vm.beta.lab"
        port: "80"
        docroot: "/var/www2"
      host3:
        priority: "10"
        vhost_name: "vm.charlie.lab"
        port: "80"
        docroot: "/var/www3"

wrapper is simple, so simple it would be really nice if the module provided one:

class mymodule (
  $vhosts, #hash of vhosts to create, required
  )
{
  create_resources(apache::vhost, $vhosts)
}
edit flag offensive delete link more

Comments

Requiring vhost is probably a bad idea in case you don't have any. See my question here, https://ask.puppetlabs.com/question/1380/problems-creating-hiera-hashes-for-create_resources/

ramindk gravatar imageramindk ( 2013-10-04 12:16:31 -0500 )edit

Sorry about that.. I thought I had removed al the commas when I copied and pasted the data. I'll get that fixed.

llowder gravatar imagellowder ( 2013-10-07 10:51:50 -0500 )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

2 followers

Stats

Asked: 2013-06-07 12:48:45 -0500

Seen: 9,342 times

Last updated: Oct 07 '13