Ask Your Question
0

how to convert this derdanne/nfs puppet code to hiera?

asked 2017-07-31 17:14:41 -0500

gene gravatar image

updated 2017-08-07 09:24:51 -0500

I have installed the derdanne/nfs module and have the following code that is working:

   class { '::nfs':
            #ensure          => absent,
            server_enabled  => true,
            nfs_v4          => false,
            client_enabled  => true,
            nfs_v4_client   => false,
            #nfs_v4_export_root => '/',
    }

    nfs::server::export { '/localview-ssf01':
            clients => '192.168.40.0/23(rw,root_squash) 192.168.44.0/24(rw,root_squash) 172.16.239.0/24(rw,root_squash)'
    }

I would really like to move most of that to hiera to node yaml file. I didn't see an example of nfsv3 exports for hiera in the module doc and i'm relatively new at hiera. Below is what is currently in my node.yaml file. This isn't the entire file, just the nfs relevant sections. There is some other network and sudo related stuff above it which is working ok:

classes:
  - nfs
nfs::server::enabled: true
nfs::client::enabled: true
nfs::nfs_v4: false
nfs::nfs_v4_client: false
nfs::server::export: 
    '/localview-ssf01':
      'clients' : '192.168.40.0/23(rw,root_squash) 192.168.44.0/24(rw,root_squash) 172.16.239.0/24(rw,root_squash)'

I think the part that isn't working is where i'm trying to define the file system to export from this server. If anyone can show me an nfsv3 example of this I would be most appreciative. I'm not getting any errors from the puppet run but /etc/exports isn't getting populated with the entry either. It does get populated when I run the puppet code above.

Gene


With Henrik's (thanks!) answer to my original question, I've done the following, which seems to be working:

class profile::buildserver::nfsexports {

        #notify {"In profile::buildserver::nfsexprots -- exportname    = $exportname":}
        #notify {"In profile::buildserver::nfsexprots -- exportclients = $exportclients":}

        $exportname     = lookup(profile::buildserver::nfsexports::exportname)
        $exportclients  = lookup(profile::buildserver::nfsexports::exportclients)

        $server_enabled = lookup(nfs::server::enabled,Boolean,'first',false )
        $client_enabled = lookup(nfs::client::enabled,Boolean,'first',true )
        $nfs_v4         = lookup(nfs::v4,Boolean,'first',false )
        $nfs_v4_client  = lookup(nfs::v4_client,Boolean,'first',false )

        class { '::nfs':
               server_enabled  => $server_enabled,
               nfs_v4          => $nfs_v4,
               client_enabled  => $client_enabled,
               nfs_v4_client   => $nfs_v4_client,
        }
        if ($server_enabled) and ($exportname) and ($exportclients) {
                nfs::server::export { $exportname:
                        clients => $exportclients
        }
    }
}

Here is the yaml file:

nfs::server::enabled: true
nfs::client::enabled: true
nfs::nfs_v4: false
nfs::nfs_v4_client: false


profile::buildserver::nfsexports::exportname: '/localview-ssf01'
profile::buildserver::nfsexports::exportclients: '192.168.40.0/23(rw,root_squash) 192.168.44.0/24(rw,root_squash) 172.16.239.0/24(rw,root_squash)'

I tried initially to do it the way shown below. Seems like it should work but I am getting this error when i do so and I couldn't figure out how to get past it (or really what it was trying to tell me....:

class:

class profile::buildserver::nfsexports {

        $exportname     = lookup(profile::buildserver::nfsexports::exportname)
        $exportclients  = lookup(profile::buildserver::nfsexports::exportclients)

        include nfs
        nfs::server::export { $exportname:
                 clients => $exportclients
        }
}

Warning: /Stage[main]/Profile::Buildserver::Nfsexports/Nfs::Server::Export[/localview-ssf01]/Nfs::Functions::Create_export[/localview-ssf01]/Concat::Fragment[/localview-ssf01]/Concat_fragment[/localview-ssf01]: Target Concat_file with path of /etc/exports not found in the catalog
edit retag flag offensive close merge delete

Comments

Change the variables to be class parameters - then they are automatically looked up via APL

Henrik Lindberg gravatar imageHenrik Lindberg ( 2017-08-09 04:50:25 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-08-02 10:26:37 -0500

Henrik Lindberg gravatar image

Automatic Parameter Lookup (APL) only works with classes. The nfs::server::export is a resource. If you want to give the parameters via hiera, your code needs to call lookup() for the keys you are interested in (like the 'title', and the 'clients). Alternatively, define another class that takes those two parameters (via APL), and have it declare the resource.

edit flag offensive delete link more

Comments

Thanks for the clarification. I think I'll try defining another class to take the parameter via APL and declare the resource as you suggest. When I get it working, i'll post it here in case it helps anyone else (or me 6 months from now :-) )

gene gravatar imagegene ( 2017-08-03 12:31:01 -0500 )edit

I added to my original question above what I was able to get working (based upon Henrik's answer). I still need to figure out how to do this with a hash in the yaml as I have at least one case where I want to define multiple nfs exports. My code above isn't scalable to more than one.

gene gravatar imagegene ( 2017-08-07 09:27:26 -0500 )edit

for APL to work, it needs to be pointed at a class, however, if you pass a hash/array of config into your wrapper class, and it calls the define for each piece of the array/hash, you can still send that into a single entrypoint

DarylW gravatar imageDarylW ( 2017-08-07 15:06:48 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-07-31 17:14:41 -0500

Seen: 52 times

Last updated: Aug 07