Configure An Inventory Host Web Service For A Reverse Proxy

This runbook explains how to update an inventory so a host web service is available through the repository’s reverse proxy setup.

Scope

This runbook covers required updates in:

It also includes the required DNS deployment, certificate generation, and certificate staging steps.

Prerequisites

Traffic follows this path:

Client -> rproxy-0:443 -> rproxy-1:80 (or rproxy-2:80) -> service_host:service_port

1) Update Inventory Host Groups And CNAME Entries

Edit inventory/<inventory_name>/inventory.ini and set pihole_cname_entries on the target service host. Use the site’s public name as domain and the frontend proxy’s DNS name as target.

Example:

[baremetal]
ecube-2 pihole_cname_entries='[{"domain": "rosie.refol.us", "target": "rproxy-0.refol.us"}]'

[cname]
ecube-2

Both the host variable and [cname] membership are required. The DNS playbook selects hosts in cname and reads their pihole_cname_entries values.

Keep the host in its existing application and infrastructure groups. For a VM, set the variable on its existing entry under [vms] instead of adding it to [baremetal].

Also ensure the reverse proxy and certificate groups are defined:

[rproxy_main]
rproxy-0

[rproxy_primary]
rproxy-1

[rproxy_secondary]
rproxy-2

[rproxy:children]
rproxy_main
rproxy_primary
rproxy_secondary

[certs]
rproxy-0

Notes:

2) Verify The Service Host IP Address

Edit roles/global/vars/main.yml and verify global_ip_addresses contains the service host.

Example of an existing entry:

global_ip_addresses:
  ecube-2: 192.168.90.196

Keep the rest of the map intact. For a new host, add an available address in the appropriate subnet and verify it is not already assigned. Do not change an existing host’s address just to match this example.

3) Update The Inventory Site Configuration

For a host-specific site, edit inventory/<inventory_name>/host_vars/<service_host>.yml. If the inventory already defines sites in shared vars, update that list instead.

Example:

rproxy_setup_sites:
  - server_name: rosie.refol.us
    port: 8000
    proxy_pass: "http://{{ global_ip_addresses['ecube-2'] }}"
    allow_list:
      - 192.168.0.0/24
      - 192.168.2.0/24
    restricted: false
    use_oauth2: false
    enable: true

Settings:

Setting Values Default Setting Description
pihole_cname_entries List of domain and target mappings Required for CNAME deployment Host variable in the inventory file. Maps the site name to the frontend proxy’s DNS name.
rproxy_setup_sites List of site mappings Required for selected service hosts Defines the sites to deploy.
server_name Site DNS name Required Must match the CNAME domain, client-facing URL, and TLS certificate.
port Service listening port Required Port reached by the backend proxies.
proxy_pass Upstream URL without the service port Required Service address, including http:// or https://. The template appends :<port>.
allow_list IP addresses or CIDR ranges Required when restricted: true; otherwise unused Additional frontend allow rules. The template also includes built-in LAN allow rules.
restricted true, false false Enables frontend IP restrictions and HTTP Basic authentication using the existing .htpasswd file.
use_oauth2 true, false false when omitted by the configuration task Enables the separate OAuth2 integration. Leave disabled for this runbook.
enable true, false Set explicitly Creates or removes the site’s sites-enabled link.
rproxy_setup_cloudflare_only true, false true Role-level frontend restriction to Cloudflare and built-in LAN ranges, separate from restricted.
certs_staging true, false false Uses the Let’s Encrypt staging service when enabled. Staging certificates are not publicly trusted.
certs_home Directory path /data/letsencrypt Certbot certificate storage on the certificate host.
certs_stage Directory path /data/certs Destination for staged certificate files used by nginx in the default configuration.

Notes:

4) Deploy DNS And Reverse Proxy Changes

Deploy the target host’s CNAME entries:

ansible-playbook -i inventory/<inventory_name>/inventory.ini playbooks/dns/add_cname_entry.yml --limit <service_host> -u ansible

For the example above, replace <service_host> with ecube-2.

If the proxy infrastructure has not already been set up, run:

ansible-playbook -i inventory/<inventory_name>/inventory.ini playbooks/rproxy/deploy_rproxy.yml -u ansible

Deploy the selected host’s site configuration to every reverse proxy:

ansible-playbook -i inventory/<inventory_name>/inventory.ini playbooks/rproxy/config_rproxy.yml --limit <service_host> -u ansible

Notes:

5) Generate And Stage The Certificate

Generate certificates using the target inventory, then stage them for nginx:

ansible-playbook -i inventory/<inventory_name>/inventory.ini playbooks/certs/generate_certs.yml -u ansible
ansible-playbook -i inventory/<inventory_name>/inventory.ini playbooks/certs/stage_certs.yml -u ansible

Notes:

6) Validate

Inventory and host selection checks:

ansible-inventory -i inventory/<inventory_name>/inventory.ini --graph cname
ansible-inventory -i inventory/<inventory_name>/inventory.ini --graph rproxy
ansible-inventory -i inventory/<inventory_name>/inventory.ini --graph certs
ansible-playbook -i inventory/<inventory_name>/inventory.ini playbooks/rproxy/config_rproxy.yml --limit <service_host> --list-hosts
ansible-playbook -i inventory/<inventory_name>/inventory.ini playbooks/rproxy/config_rproxy.yml --syntax-check

Run nginx validation on all proxy hosts:

ansible rproxy -i inventory/<inventory_name>/inventory.ini -m ansible.builtin.command -a 'nginx -t' -b -u ansible

From a client using Pi-hole, verify the local CNAME. From an allowed client network, check HTTPS:

dig <server_name> CNAME
curl -I https://<server_name>

Behavior checks:

Troubleshooting