Defined Type: nginx::resource::map

Defined in:
manifests/resource/map.pp

Summary

Create a new mapping entry for NGINX

Overview

Examples:

basic map with two mappings

nginx::resource::map { 'backend_pool':
  ensure    => present,
  hostnames => true,
  default   => 'ny-pool-1',
  string    => '$http_host',
  mappings  => {
    '*.nyc.example.com' => 'ny-pool-1',
    '*.sf.example.com'  => 'sf-pool-1',
  }
}

Preserving input of order of mappings

nginx::resource::map { 'backend_pool':
  ...
  mappings  => [
    { 'key' => '*.sf.example.com', 'value' => 'sf-pool-1' },
    { 'key' => '*.nyc.example.com', 'value' => 'ny-pool-1' },
  ]
}

Using external include

nginx::resource::map { 'redirections':
   include_files => [ '/etc/nginx/conf.d/redirections.map']
}

Hiera usage

nginx::string_mappings:
  client_network:
    ensure: present
    hostnames: true
    default: 'ny-pool-1'
    string: $http_host
    mappings:
      '*.nyc.example.com': 'ny-pool-1'
      '*.sf.example.com': 'sf-pool-1'

Hiera usage: preserving input of order of mappings:

nginx::string_mappings:
  client_network:
    ...
    mappings:
      - key: '*.sf.example.com'
        value: 'sf-pool-1'
      - key: '*.nyc.example.com'
        value: 'ny-pool-1'

Parameters:

  • ensure (Enum['absent', 'present']) (defaults to: 'present')

    Enables or disables the specified location

  • default (Optional[String]) (defaults to: undef)

    Sets the resulting value if the source values fails to match any of the variants.

  • string (String[2])

    Source string or variable to provide mapping for

  • mappings (Nginx::StringMappings) (defaults to: [])

    Hash of map lookup keys and resultant values

  • hostnames (Boolean) (defaults to: false)

    Indicates that source values can be hostnames with a prefix or suffix mask.

  • include_files (Array[String]) (defaults to: [])

    An array of external files to include

  • context (Enum['http', 'stream']) (defaults to: 'http')

    Specify if mapping is for http or stream context



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'manifests/resource/map.pp', line 66

define nginx::resource::map (
  String[2] $string,
  Nginx::StringMappings $mappings = [],
  Optional[String] $default         = undef,
  Enum['absent', 'present'] $ensure = 'present',
  Array[String] $include_files      = [],
  Boolean $hostnames                = false,
  Enum['http', 'stream'] $context   = 'http',
) {
  if ! defined(Class['nginx']) {
    fail('You must include the nginx base class before using any defined resources')
  }

  $root_group = $nginx::root_group

  $conf_dir   = $context ? {
    'stream' => "${nginx::conf_dir}/conf.stream.d",
    'http'   => "${nginx::conf_dir}/conf.d",
  }

  $ensure_real = $ensure ? {
    'absent' => absent,
    default  => 'file',
  }

  file { "${conf_dir}/${name}-map.conf":
    ensure  => $ensure_real,
    owner   => 'root',
    group   => $root_group,
    mode    => $nginx::global_mode,
    content => epp('nginx/conf.d/map.epp', {
        'default'       => $default,
        'hostnames'     => $hostnames,
        'include_files' => $include_files,
        'mappings'      => $mappings,
        'name'          => $name,
        'string'        => $string,
    }),
    notify  => Class['nginx::service'],
    tag     => 'nginx_config_file',
  }
}