Puppet Class: psick::proxy

Defined in:
manifests/proxy.pp

Overview

Configures proxy settings on different package managers

Parameters:

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

    If to add or remove the proxy configuration

  • configure_gem (Boolean) (defaults to: true)

    Configure proxy for gem

  • configure_puppet_gem (Boolean) (defaults to: true)

    Configure proxy for puppet gem

  • configure_pip (Boolean) (defaults to: true)

    Configure proxy for pip

  • configure_system (Boolean) (defaults to: true)

    Export proxy global vars on startup script

  • configure_repo (Boolean) (defaults to: true)

    Configure proxy on package repos

  • proxy_server (Optional[Hash]) (defaults to: $psick::servers['proxy'])

    Hash with the proxy server data. Default is based on psick::proxy_server

  • manage (Boolean) (defaults to: $psick::manage)

    If to actually manage any resource in this class. If false no resource is managed. Default value is taken from main psick class.

  • noop_manage (Boolean) (defaults to: $psick::noop_manage)

    If to use the noop() function for all the resources provided by this class. If this is true the noop function is called with $noop_value argument. This overrides any other noop setting (either set on client’s puppet.conf or by noop() function in main psick class). Default from psick class.

  • noop_value (Boolean) (defaults to: $psick::noop_value)

    The value to pass to noop() function if noop_manage is true. It applies to all the resources (and classes) declared in this class If true: noop metaparamenter is set to true, resources are not applied If false: noop metaparameter is set to false, and any eventual noop setting is overridden: resources are always applied. Default from psick class.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'manifests/proxy.pp', line 24

class psick::proxy (
  Enum['present','absent'] $ensure = 'present',
  Boolean $configure_gem           = true,
  Boolean $configure_puppet_gem    = true,
  Boolean $configure_pip           = true,
  Boolean $configure_system        = true,
  Boolean $configure_repo          = true,
  Optional[Hash] $proxy_server     = $psick::servers['proxy'],

  Boolean $manage                  = $psick::manage,
  Boolean $noop_manage             = $psick::noop_manage,
  Boolean $noop_value              = $psick::noop_value,
) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }

    if !empty($proxy_server) {
      if !empty($proxy_server['user']) and !empty($proxy_server['password']) {
        $proxy_credentials = "${proxy_server['user']}:${proxy_server['password']}@"
      } else {
        $proxy_credentials = ''
      }
      $proxy_url = "${proxy_server['scheme']}://${proxy_credentials}${proxy_server['host']}:${proxy_server['port']}"
    } else {
      $proxy_url = ''
    }

    if $configure_gem and !empty($proxy_server) {
      ini_setting { 'proxy_gem':
        ensure            => $ensure,
        path              => '/etc/gemrc',
        key_val_separator => ': ',
        setting           => 'gem',
        value             => "-p ${proxy_url}",
      }
    }
    if $configure_puppet_gem and !empty($proxy_server) {
      file { '/opt/puppetlabs/puppet/etc':
        ensure => directory,
      }
      ini_setting { 'proxy_puppet_gem':
        ensure            => $ensure,
        path              => '/opt/puppetlabs/puppet/etc/gemrc',
        key_val_separator => ': ',
        setting           => 'gem',
        value             => "-p ${proxy_url}",
      }
    }
    if $configure_pip and !empty($proxy_server) {
      ini_setting { 'proxy_pip':
        ensure            => $ensure,
        path              => '/etc/pip.conf',
        key_val_separator => '=',
        section           => 'global',
        setting           => 'proxy',
        value             => "${proxy_server['host']}:${proxy_server['port']}",
      }
    }
    if $configure_system and $proxy_server != {} {
      psick::profile::script { 'proxy':
        ensure  => $ensure,
        content => epp('psick/proxy/proxy.sh.epp'),
        # Template has to be evaluated here: it uses local scope vars
      }
    }
    if $configure_repo and !empty($proxy_server) {
      case $facts['os']['family'] {
        'RedHat': {
          ini_setting { 'proxy_yum':
            ensure            => $ensure,
            path              => '/etc/yum.conf',
            key_val_separator => '=',
            section           => 'main',
            setting           => 'proxy',
            value             => "${proxy_server[scheme]}://${proxy_server['host']}:${proxy_server['port']}",
          }
          if 'user' in $proxy_server and 'password' in $proxy_server {
            ini_setting { 'proxy_user_yum':
              ensure            => $ensure,
              path              => '/etc/yum.conf',
              key_val_separator => '=',
              section           => 'main',
              setting           => 'proxy_username',
              value             => $proxy_server['user'],
            }
            ini_setting { 'proxy_password_yum':
              ensure            => $ensure,
              path              => '/etc/yum.conf',
              key_val_separator => '=',
              section           => 'main',
              setting           => 'proxy_password',
              value             => $proxy_server['password'],
            }
          }
        }
        'Debian': {
          file { '/etc/apt/apt.conf.d/80proxy':
            ensure  => $ensure,
            content => epp('psick/proxy/proxy.apt.epp'),
          }
        }
        default: {
          notify { 'Proxy':
            message => "No proxy configuration available for ${facts['os']['family']} repos",
          }
        }
      }
    }
  }
}