Persistently create a new Apache VirtualHost alongside Foreman

Say I want the Foreman Server to host some configuration files and expose those through HTTP using a non default port (e.g 8080), what’s the best way to do it persistently?
Whenever I edit apache config files, it gets overwritten every time the server restarts.

With foreman-installer this can be done in a sort of hacky way by using custom-hiera.yaml. Note that this is untested and there may be typos.

# add additional Puppet classes, but merge them with the existing ones
lookup_options:
  classes:
    merge: unique

# Actually include the class. You can also include others here like apache::mod::status
classes:
  - apache::vhosts

# Define the vhost - see apache/manifests/vhost.pp for parameters
# https://forge.puppet.com/puppetlabs/apache/reference#apachevhost
apache::vhosts::vhosts:
  my-vhost.example.com:
    docroot: /var/www/html
    port: 8080
1 Like

Thanks a lot! This works perfectly on both new and existing foreman installations!
For Ubuntu systems…here’s the file you need to edit: /etc/foreman-installer/custom-hiera.yaml

Hi, @ekohl
I’m trying something similar - I have domain already defined in Foreman, but I’d like to extend it so I’d be able to send DNS notifications to DNS slave. In custom-hiera.yaml I’ve added these lines:

lookup_options:
  classes:
    merge: unique

classes:
  - dns::zones

dns::zones:
  sub.domain.tld:
    dns_notify: "yes"
    also_notify:
      - 172.16.1.10

this obviously work on a new domain, but not on existing:

2021-08-16 23:58:36 [NOTICE] [configure] Starting system configuration.
  The total number of configuration tasks may increase during the run.
  Observe logs or specify --verbose-log-level to see individual configuration tasks.
2021-08-16 23:58:42 [ERROR ] [configure] Evaluation Error: Error while evaluating a Method call, Could not find class ::dns::zones for smart-proxy-2.sub.domain.tld (file: /usr/share/gems/gems/kafo-6.1.2/modules/kaf                           o_configure/manifests/init.pp, line: 16, column: 39) on node smart-proxy-2.sub.domain.tld
2021-08-16 23:58:42 [NOTICE] [configure] System configuration has finished.
2021-08-16 23:58:42 [NOTICE] [post] Executing hooks in group post

any ideas what problem might be ?

Thanks

I missed this because the topic was marked as solved. It’s better to open a new one and reference this topic.