nfs share with puppet

=================================================
[root@server ~]# puppet module search nfs
Notice: Searching https://forgeapi.puppetlabs.com
NAME DESCRIPTION AUTHOR KEYWORDS
derdanne-nfs Installs and configures NFS server and clients @derdanne nfs nfs4 exports mount mfc
=================================================
[root@server ~]# puppet module install derdanne-nfs
Notice: Preparing to install into /etc/puppet/modules …
Notice: Downloading from https://forgeapi.puppetlabs.com
Notice: Installing — do not interrupt …
/etc/puppet/modules
└─┬ derdanne-nfs (v1.0.1)
├── puppetlabs-concat (v2.2.0)
└── puppetlabs-stdlib (v4.13.1)
=================================================
Classes
Public Classes
nfs: Main class, includes all other classes
Public Defines
nfs::client::mount: Handles all mounts on a nfs client.
nfs::server::export: Handles all nfs exports on a nfs server.
Private Classes
nfs::client: Includes all relevant classes for configuring as a client.
nfs::client::config: Handles the configuration files.
nfs::client::package: Handles the packages.
nfs::client::service: Handles the services.
nfs::server: Includes all relevant classes for configuring as a server.
nfs::server::config: Handles the configuration files.
nfs::server::package: Handles the packages.
nfs::server::service: Handles the services.
nfs::params: Includes all os specific parameters.
Private Defines
nfs::bindmount: Creates the bindmounts of nfs 3 exports.
nfs::nfsv4_bindmount: Creates the bindmounts of nfs 4 exports.
nfs::create_export: Creates the nfs exports.
nfs::mkdir: Creates directories recursive.
=================================================
[root@server ~]# vim /etc/puppet/manifests/site.pp
hiera_include(“classes”)

node default {
include role
}

#### writing role for user creation #####

case $role { ‘users’ : {
include users
}
}

###### writing role for ftpserver #######

case $role { ‘ftpserver’ : {
include vsftpd
}
}
####### writing role for nfs-server ######

case $role { ‘nfsserver’ : {
include nfs
}
}
============= Agent-side=========================
[root@agent ~]# vim /etc/facter/facts.d/role.txt
role=nfsserver
=================================================
[root@agent ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/var/lib/puppet/lib/puppet/type/concat_file.rb]/ensure: defined content as ‘{md5}238aaff4f2f93d3604b396040dec665c’
Notice: /File[/var/lib/puppet/lib/puppet/type/concat_fragment.rb]/ensure: defined content as ‘{md5}3a54716cef8d0a066415b7c4ec7c24a0’
Info: Loading facts
Info: Caching catalog for agent.puppet.com
Info: Applying configuration version ‘1478717929’
Notice: Finished catalog run in 2.51 seconds
==================================================
Server-Side
=================================================
[root@server ~]# vim /etc/puppet/modules/role/manifests/nfsserver.pp
class role::nfsserver {
include profile::nfsserver
}

[root@server ~]# puppet apply /etc/puppet/modules/role/manifests/nfsserver.pp –noop
Notice: Compiled catalog for server.puppet.com in environment production in 0.02 seconds
Notice: Finished catalog run in 0.02 seconds
=================================================
[root@server ~]# vim /etc/puppet/modules/profile/manifests/nfsserver.pp
class profile::nfsserver {
include nfs::server::config
}
[root@server ~]# puppet apply /etc/puppet/modules/profile/manifests/nfsserver.pp –noop
Notice: Compiled catalog for server.puppet.com in environment production in 0.01 seconds
Notice: Finished catalog run in 0.05 seconds
==================================================
[root@server ~]# vim /etc/puppet/hieradata/roles/nfsserver.yaml

classes:
– ‘profile::nfsserver’
==================================================
Agent-side

[root@agent ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1025/vsftpd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 956/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2058/master
tcp6 0 0 :::22 :::* LISTEN 956/sshd

[root@agent ~]# service nfs status
Redirecting to /bin/systemctl status nfs.service
● nfs.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)

[root@agent ~]# rpm -qa nfs*
==================================================
[root@agent ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for agent.puppet.com
Info: Applying configuration version ‘1478717929’
Notice: /Stage[main]/Nfs::Server::Config/Concat[/etc/exports]/File[/etc/exports]/content:
— /etc/exports 2013-06-07 10:31:32.000000000 -0400
+++ /tmp/puppet-file20161109-2297-jfypro 2016-11-09 14:12:52.218967374 -0500
@@ -0,0 +1 @@
+# This file is configured through the nfs::server puppet module

Info: Computing checksum on file /etc/exports
Info: /Stage[main]/Nfs::Server::Config/Concat[/etc/exports]/File[/etc/exports]: Filebucketed /etc/exports to puppet with sum d41d8cd98f00b204e9800998ecf8427e
Notice: /Stage[main]/Nfs::Server::Config/Concat[/etc/exports]/File[/etc/exports]/content: content changed ‘{md5}d41d8cd98f00b204e9800998ecf8427e’ to ‘{md5}bd50ca34b8bbe7d98df508372520094e’
Notice: Finished catalog run in 0.49 seconds

======= We can write pass data directly though hiera file as follows============

[root@server ~]# vim /etc/puppet/hieradata/roles/nfsserver.yaml

classes:
   -nfs
nfs::server_enabled: true
nfs::client_enabled : false
nfs::nfs_v4: true
nfs::nfs_v4_idmap_domain: ‘example.com’
nfs::nfs_v4_export_root: ‘/share’
nfs::nfs_v4_export_root_clients: ‘192.168.0.0/24(rw,fsid=root,insecure,no_subtree_check,async,no_root_squash)’
nfs::nfs_exports_global:
/var/www: {}
/var/smb: {}

================ Agent -Side ===================

[root@agent ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for agent.puppet.com
Info: Applying configuration version ‘1478720454’
Notice: /Stage[main]/Nfs::Server::Package/Package[nfs-utils]/ensure: created
Info: /Stage[main]/Nfs::Server::Package/Package[nfs-utils]: Scheduling refresh of Service[nfs-server.service]
Notice: /Stage[main]/Nfs::Server::Package/Package[nfs4-acl-tools]/ensure: created
Info: /Stage[main]/Nfs::Server::Package/Package[nfs4-acl-tools]: Scheduling refresh of Service[nfs-server.service]
Notice: Augeas[/etc/idmapd.conf](provider=augeas):
— /etc/idmapd.conf 2015-11-20 10:10:46.000000000 -0500
+++ /etc/idmapd.conf.augnew 2016-11-09 14:44:10.806911388 -0500
@@ -15,6 +15,7 @@
# must be included in the list!
#Local-Realms =

+Domain=puppet.com
[Mapping]

#Nobody-User = nobody

Notice: /Stage[main]/Nfs::Server::Config/Augeas[/etc/idmapd.conf]/returns: executed successfully
Info: /Stage[main]/Nfs::Server::Config/Augeas[/etc/idmapd.conf]: Scheduling refresh of Service[nfs-server.service]
Info: /Stage[main]/Nfs::Server::Config/Augeas[/etc/idmapd.conf]: Scheduling refresh of Service[nfs-idmap.service]
Notice: /Stage[main]/Nfs::Server::Config/File[/share]/ensure: created
Notice: /Stage[main]/Nfs::Server::Config/Concat[/etc/exports]/File[/etc/exports]/content:
— /etc/exports 2016-11-09 14:12:52.359967370 -0500
+++ /tmp/puppet-file20161109-3334-1bjicfs 2016-11-09 14:44:10.889911386 -0500
@@ -1 +1,2 @@
# This file is configured through the nfs::server puppet module
+/share 192.168.0.0/24(rw,fsid=root,insecure,no_subtree_check,async,no_root_squash)

Info: Computing checksum on file /etc/exports
Info: /Stage[main]/Nfs::Server::Config/Concat[/etc/exports]/File[/etc/exports]: Filebucketed /etc/exports to puppet with sum bd50ca34b8bbe7d98df508372520094e
Notice: /Stage[main]/Nfs::Server::Config/Concat[/etc/exports]/File[/etc/exports]/content: content changed ‘{md5}bd50ca34b8bbe7d98df508372520094e’ to ‘{md5}285dc362b0dfe93e9dad6d77858b3667’
Info: Concat[/etc/exports]: Scheduling refresh of Service[nfs-server.service]
Info: Concat[/etc/exports]: Scheduling refresh of Service[nfs-idmap.service]
Notice: /Stage[main]/Nfs::Server::Service/Service[nfs-idmap.service]/ensure: ensure changed ‘stopped’ to ‘running’
Info: /Stage[main]/Nfs::Server::Service/Service[nfs-idmap.service]: Unscheduling refresh on Service[nfs-idmap.service]
Notice: /Stage[main]/Nfs::Server::Service/Service[nfs-server.service]/ensure: ensure changed ‘stopped’ to ‘running’
Info: /Stage[main]/Nfs::Server::Service/Service[nfs-server.service]: Unscheduling refresh on Service[nfs-server.service]
Notice: Finished catalog run in 53.06 seconds
[root@agent ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for agent.puppet.com
Info: Applying configuration version ‘1478720454’
Notice: Augeas[/etc/idmapd.conf](provider=augeas):
— /etc/idmapd.conf 2016-11-09 14:44:10.846911387 -0500
+++ /etc/idmapd.conf.augnew 2016-11-09 14:47:01.247906309 -0500
@@ -15,7 +15,7 @@
# must be included in the list!
#Local-Realms =

-Domain=puppet.com
+Domain=example.com
[Mapping]

#Nobody-User = nobody

Notice: /Stage[main]/Nfs::Server::Config/Augeas[/etc/idmapd.conf]/returns: executed successfully
Info: /Stage[main]/Nfs::Server::Config/Augeas[/etc/idmapd.conf]: Scheduling refresh of Service[nfs-server.service]
Info: /Stage[main]/Nfs::Server::Config/Augeas[/etc/idmapd.conf]: Scheduling refresh of Service[nfs-idmap.service]
Notice: /Stage[main]/Nfs::Server::Service/Service[nfs-idmap.service]: Triggered ‘refresh’ from 1 events
Notice: /Stage[main]/Nfs::Server::Service/Service[nfs-server.service]: Triggered ‘refresh’ from 1 events
Notice: Finished catalog run in 0.46 seconds

[root@agent ~]# exportfs
/share 192.168.0.0/24

[root@agent ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3617/rpcbind
tcp 0 0 0.0.0.0:52912 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 4554/rpc.mountd
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1025/vsftpd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 956/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2058/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:50471 0.0.0.0:* LISTEN 3833/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 3617/rpcbind
tcp6 0 0 :::20048 :::* LISTEN 4554/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 956/sshd
tcp6 0 0 :::53464 :::* LISTEN –
tcp6 0 0 :::48734 :::* LISTEN 3833/rpc.statd
tcp6 0 0 :::2049 :::* LISTEN –

[root@agent ~]# service nfs status
Redirecting to /bin/systemctl status nfs.service
● nfs-server.service – NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Active: active (exited) since Wed 2016-11-09 14:47:01 EST; 1min 31s ago
Process: 4549 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
Process: 4546 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
Process: 4545 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
Process: 4556 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 4555 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 4556 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service

Nov 09 14:47:01 agent.puppet.com systemd[1]: Starting NFS server and services…
Nov 09 14:47:01 agent.puppet.com systemd[1]: Started NFS server and services.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s