summaryrefslogtreecommitdiffstats
path: root/fuel/build/f_resolvconf/puppet/modules/opnfv/manifests/resolver.pp
blob: 44f36a2373adaac7897b4407529234f8b218bd50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# stefan.k.berg@ericsson.com
# jonas.bjurel@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# Class: opnfv::resolver
#
# Add resolver content passed through astute.yaml into resolv.conf
# depending on the role
#
# Suitable yaml content:
# <begin>
# opnfv:
#  dns:
#    compute:
#    - 100.100.100.2
#    - 100.100.100.3
#    controller:
#    - 100.100.100.102
#    - 100.100.100.104
# <end>
#
#
#

class opnfv::resolver()
{
  if $::fuel_settings['role'] {
    if $::fuel_settings['role']  == 'primary-controller' {
      $role = 'controller'
    } else {
      $role = $::fuel_settings['role']
    }

    if ($::fuel_settings['opnfv']
        and $::fuel_settings['opnfv']['dns']
        and $::fuel_settings['opnfv']['dns'][$role]) {
      $nameservers=$::fuel_settings['opnfv']['dns'][$role]

      file { '/etc/resolv.conf':
            owner   => root,
            group   => root,
            mode    => '0644',
            content => template('opnfv/resolv.conf.erb'),
      }

      # /etc/resolv.conf is re-generated at each boot by resolvconf, so we
      # need to store there as well.

      case $::operatingsystem {
        'ubuntu': {
          file { '/etc/resolvconf/resolv.conf.d/head':
            owner   => root,
            group   => root,
            mode    => '0644',
            content => template('opnfv/resolv.conf.erb'),
          }
        }
        'centos': {
          exec { 'for file in ifcfg-eth*; do grep -q -F "PEERDNS=" $file || echo "PEERDNS=no" >> $file; done ':
            provider => 'shell',
            cwd      => '/etc/sysconfig/network-scripts',
          }
        }
      }
    }
  }
}