0

I have few NFS mount points on the same server but different directories. ex:

    x.x.x.x:/stats   /data/stats
    x.x.x.x:/scratch   /data/scratch
    x.x.x.x:/ops   /data/ops    

But when i try to run puppet it adds following to my fstab. (wrong mount assignment)

x.x.x.x:/scratch   /data/stats       nfs     defaults,nodev,nosharecache     0       0
x.x.x.x:/scratch   /data/ops  nfs     defaults,nodev,nosharecache     0       0
x.x.x.x:/scratch   /data/scratch     nfs     defaults,nodev,nosharecache     0       0

It is using the last mount option on all mounted partitions. so i did a little bit of research and found the following bug.

 https://tickets.puppetlabs.com/browse/DOCUMENT-242

Then added nosharecache option, but still no luck. this is my puppet code

class profile::mounts::stats {
  # Hiera lookups
  $location = hiera('profile::mounts::stats::location')
  $location2 = hiera('profile::mounts::stats::location2')
   tag        'new_mount'

 file { '/data/stats':
ensure  => directory,
owner   => 'root',
group   => 'root',
mode    => '0755',
require => File['/data'],
tag     => 'new_mount',
}

  mount { '/data/stats':
ensure  => mounted,
fstype  => 'nfs',
device  => $location,
options => 'defaults,nodev,nosharecache',
require => File['/data/stats'],
tag     => 'new_mount'
}



file { '/data/ops':
  ensure  => directory,
  owner   => 'root',
  group   => 'mail',
  mode    => '0775',
  require => File['/data'],
  tag     => 'new_mount',
}

 mount { '/data/ops':
ensure  => mounted,
fstype  => 'nfs',
device  => $location2,
options => 'defaults,nodev,nosharecache',
require => File['/data/ops'],
tag     => 'new_mount',
}

file { '/data/scratch':
ensure  => directory,
owner   => 'root',
group   => 'mail',
mode    => '0775',
require => File['/data'],
tag     => 'new_mount',
}

 mount { '/data/scratch':
ensure  => mounted,
fstype  => 'nfs',
device  => $location2,
options => 'defaults,nodev,nosharecache',
require => File['/data/scratch'],
tag     => 'new_mount',
}

 }

 }

My hieara lookup is as follows

profile::mounts::stats::location: x.x.x.x:/stats
profile::mounts::stats::location2: x.x.x.x:/scratch

why it is causing some unexpected behavior ?

Tharanga Abeyseela
  • 3,255
  • 4
  • 33
  • 45

1 Answers1

2

I compiled that code and I see a few issues:

You did not include the File['/data'] resource, but I assume you have that somewhere else?

After compiling I see this in the catalog:

$ cat myclass.json | jq '.resources | .[] | select(.type == "Mount") | [.title, .parameters]'
[
  "/data/stats",
  {
    "ensure": "mounted",
    "fstype": "nfs",
    "device": "x.x.x.x:/stats",
    "options": "defaults,nodev,nosharecache",
    "require": "File[/data/stats]",
    "tag": "new_mount"
  }
]
[
  "/data/ops",
  {
    "ensure": "mounted",
    "fstype": "nfs",
    "device": "x.x.x.x:/scratch",
    "options": "defaults,nodev,nosharecache",
    "require": "File[/data/ops]",
    "tag": "new_mount"
  }
]
[
  "/data/scratch",
  {
    "ensure": "mounted",
    "fstype": "nfs",
    "device": "x.x.x.x:/scratch",
    "options": "defaults,nodev,nosharecache",
    "require": "File[/data/scratch]",
    "tag": "new_mount"
  }
]

So you are mounting both /data/ops and /data/scratch on $location2. Is that an oversight? It does not match what you said you were trying to achieve.

Otherwise I can't reproduce what you said you are observing.

Is anything other than Puppet editing the fstab file? Did you try this code on a fresh box?

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
  • Yeah I also have no idea what the difference between desired and actual behavior is from the question, but the best guess is that he is using the wrong variable for the device on that mount resource like you describe. – Matthew Schuchard Jul 12 '17 at 14:47
  • Thanks guys, i managed to fix this issue by adding nosharecache nfs mount option to the root level (require => File['/data'] class, now it is mounting correctly. now need to remove other /etc/fstab incorrect entries and run puppet again :) – Tharanga Abeyseela Jul 12 '17 at 22:52