44f36a2373adaac7897b4407529234f8b218bd50
[genesis.git] / fuel / build / f_resolvconf / puppet / modules / opnfv / manifests / resolver.pp
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Class: opnfv::resolver
12 #
13 # Add resolver content passed through astute.yaml into resolv.conf
14 # depending on the role
15 #
16 # Suitable yaml content:
17 # <begin>
18 # opnfv:
19 #  dns:
20 #    compute:
21 #    - 100.100.100.2
22 #    - 100.100.100.3
23 #    controller:
24 #    - 100.100.100.102
25 #    - 100.100.100.104
26 # <end>
27 #
28 #
29 #
30
31 class opnfv::resolver()
32 {
33   if $::fuel_settings['role'] {
34     if $::fuel_settings['role']  == 'primary-controller' {
35       $role = 'controller'
36     } else {
37       $role = $::fuel_settings['role']
38     }
39
40     if ($::fuel_settings['opnfv']
41         and $::fuel_settings['opnfv']['dns']
42         and $::fuel_settings['opnfv']['dns'][$role]) {
43       $nameservers=$::fuel_settings['opnfv']['dns'][$role]
44
45       file { '/etc/resolv.conf':
46             owner   => root,
47             group   => root,
48             mode    => '0644',
49             content => template('opnfv/resolv.conf.erb'),
50       }
51
52       # /etc/resolv.conf is re-generated at each boot by resolvconf, so we
53       # need to store there as well.
54
55       case $::operatingsystem {
56         'ubuntu': {
57           file { '/etc/resolvconf/resolv.conf.d/head':
58             owner   => root,
59             group   => root,
60             mode    => '0644',
61             content => template('opnfv/resolv.conf.erb'),
62           }
63         }
64         'centos': {
65           exec { 'for file in ifcfg-eth*; do grep -q -F "PEERDNS=" $file || echo "PEERDNS=no" >> $file; done ':
66             provider => 'shell',
67             cwd      => '/etc/sysconfig/network-scripts',
68           }
69         }
70       }
71     }
72   }
73 }