puppetlabs-apache icon indicating copy to clipboard operation
puppetlabs-apache copied to clipboard

Make possible to use custom vhosts via hiera directly

Open sergey-ganchuk opened this issue 2 years ago • 10 comments

Use Case

I was trying to use module via hiera and found that it is impossible to make an custom vhost via hiera.

Describe the Solution You Would Like

It would be great to have ability to create custom vhosts.

Describe Alternatives You've Considered

I had to create wrapper module.

sergey-ganchuk avatar May 03 '23 06:05 sergey-ganchuk

There is apache::vhosts. Is that not enough?

ekohl avatar May 03 '23 10:05 ekohl

not enough if you want to use custom vhost configuration

sergey-ganchuk avatar May 03 '23 10:05 sergey-ganchuk

Why not? You can specify all the parameters you usually have. What can you do with a wrapper that you can't via Hiera? The issue now lacks any information to be useful.

ekohl avatar May 03 '23 10:05 ekohl

There is define apache::vhost::custom It nowere implemented in the code. You can't use it via hiera directly. There are apache2 options that do not exist in apache::vhosts

sergey-ganchuk avatar May 03 '23 10:05 sergey-ganchuk

There is define apache::vhost::custom It nowere implemented in the code. You can't use it via hiera directly.

That's true. You could submit a PR to apache::vhosts to add a parameter.

There are apache2 options that do not exist in apache::vhosts

Again, it helps to be explicit.

ekohl avatar May 03 '23 11:05 ekohl

Hi I was trying to use this apache directive: AuthnProviderAlias ldap

sergey-ganchuk avatar May 04 '23 06:05 sergey-ganchuk

You're right, that should be a feature request (or a pull request).

ekohl avatar May 04 '23 12:05 ekohl

Defined types can be used if you define them via create resources, requires puppetlabs-stdlib to work. The stdlib::manage::create_resources is your friend!

classes:
  - "stdlib::manage"

stdlib::manage::create_resources:
  apache::custom_config:
    myconfigname:
      ensure: present
      filename: "5-settings.conf"
      priority: 5
      owner: root
      group: root
      file_mode: "0644"
      content: |
        ServerSignature Off
        # basically whatever you want.
  apache::vhost::custom:
    mycustomvhost:
        ensure: 'present'
        priority: 25
        verify_config: true
        content: |
          # add your vhost
          # content here
  file:
    /var/www/vhosts:
      ensure: directory
      owner: root
      group: root
      mode: '755'

rolfsrolfs avatar Aug 16 '23 07:08 rolfsrolfs

Defined types can be used if you define them via create resources, requires puppetlabs-stdlib to work. The stdlib::manage::create_resources is your friend!

classes:
  - "stdlib::manage"

stdlib::manage::create_resources:
  apache::custom_config:
    myconfigname:
      ensure: present
      filename: "5-settings.conf"
      priority: 5
      owner: root
      group: root
      file_mode: "0644"
      content: |
        ServerSignature Off
        # basically whatever you want.
  apache::vhost::custom:
    mycustomvhost:
        ensure: 'present'
        priority: 25
        verify_config: true
        content: |
          # add your vhost
          # content here
  file:
    /var/www/vhosts:
      ensure: directory
      owner: root
      group: root
      mode: '755'

Hi @rolfsrolfs, I have tried using puppet apply but somehow I was not able to get through, not sure if I am missing here. The another way I was able to get through is : Hiera

apache::vhost::custom:
  content: |
    Alias /custom /var/www/custom
    <Directory /var/www/custom>
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
    </Directory>

Manifest:

$custom_vhost = lookup('apache::vhost::custom')
create_resources('apache::vhost::custom',
  { 'content' => $custom_vhost }
}

Ramesh7 avatar Sep 12 '23 04:09 Ramesh7

Defined types can be used if you define them via create resources, requires puppetlabs-stdlib to work. The stdlib::manage::create_resources is your friend!

classes:
  - "stdlib::manage"

stdlib::manage::create_resources:
  apache::custom_config:
    myconfigname:
      ensure: present
      filename: "5-settings.conf"
      priority: 5
      owner: root
      group: root
      file_mode: "0644"
      content: |
        ServerSignature Off
        # basically whatever you want.
  apache::vhost::custom:
    mycustomvhost:
        ensure: 'present'
        priority: 25
        verify_config: true
        content: |
          # add your vhost
          # content here
  file:
    /var/www/vhosts:
      ensure: directory
      owner: root
      group: root
      mode: '755'

After some tries was able to generate vhost using hiera as you mentioned in above comments. I think the missing part here is the manifest also needs to include the below class of stdlib :

include stdlib::manage

Once we include we can define any number of resources in hiera and we can get it generate the custom vhost. Thanks @gavindidrichsen for pointers.

@sergey-ganchuk can you please try with this approach, it should work as expected.

Ramesh7 avatar Sep 18 '23 17:09 Ramesh7