Filesystem mounting in sequence with puppet

104 views
Skip to first unread message

amogh patel

unread,
Oct 29, 2014, 12:15:45 PM10/29/14
to puppet...@googlegroups.com
Hi Puppet Users,

I've a requirement to create filesystem and mount 10 disks. For that, I've created this define and calling that define with hash. I need to mount these disks in sequence like below:

/dev/sdb1                         917G   72M  870G   1% /data/01
/dev/sdc1                         917G   72M  870G   1% /data/02
/dev/sdd1                         917G   72M  870G   1% /data/03
/dev/sde1                         917G   72M  870G   1% /data/04
/dev/sdf1                         917G   72M  870G   1% /data/05
/dev/sdg1                         917G   72M  870G   1% /data/06
/dev/sdh1                         917G   72M  870G   1% /data/07
/dev/sdi1                         917G   72M  870G   1% /data/08
/dev/sdj1                         917G   72M  870G   1% /data/09
/dev/sdk1                         917G   72M  870G   1% /data/10

But when I run puppet, it mounts in random order. Any suggestions please.

Here is the snippets of my code:

Define:

define base::fsdef (
  $mountpoint,
  $pdisk = $title
) {
  filesystem { $pdisk :
    ensure  => present,
    fs_type => 'ext4',
    options => '-b 4096',
  }
  file { $mountpoint :
    ensure  => directory,
    owner   => 'root',
    group   => 'root,
    mode    => '0755',
    require => Filesystem[$pdisk],
  }
  mount { "fstab_${pdisk}" :
    ensure  => mounted,
    name    => $mountpoint,
    device  => $pdisk,
    fstype  => 'ext4',
    options => 'defaults',
    atboot  => true,
    dump    => '1',
    pass    => '2',
    require => File[$mountpoint]
  }
}

Define call:

  $fs_hash = {
    '/dev/sdb1' => { mountpoint => '/data/01'},
    '/dev/sdc1' => { mountpoint => '/data/02'},
    '/dev/sdd1' => { mountpoint => '/data/03'},
    '/dev/sde1' => { mountpoint => '/data/04'},
    '/dev/sdf1' => { mountpoint => '/data/05'},
    '/dev/sdg1' => { mountpoint => '/data/06'},
    '/dev/sdh1' => { mountpoint => '/data/07'},
    '/dev/sdi1' => { mountpoint => '/data/08'},
    '/dev/sdj1' => { mountpoint => '/data/09'},
    '/dev/sdk1' => { mountpoint => '/data/10'},
   }

  create_resources(base::fsdef, $fs_hash)

jcbollinger

unread,
Oct 30, 2014, 10:05:34 AM10/30/14
to puppet...@googlegroups.com


On Wednesday, October 29, 2014 11:15:45 AM UTC-5, amogh patel wrote:
Hi Puppet Users,

I've a requirement to create filesystem and mount 10 disks. For that, I've created this define and calling that define with hash. I need to mount these disks in sequence like below:


Why does the sequence in which they are mounted matter?  You do know that given the properties you specify, at system boot these filesystems will be mounted in parallel (which is likely to complete in random order), right?

 


Why in the world are you creating a hash in your manifest and passing it to create_resources()?   Ordinary resource declarations are clearer when all the resources and their parameters are statically known.  For instance:

base::fsdef {
   
'/dev/sdb1': mountpoint => '/data/01';
   
'/dev/sdc1': mountpoint => '/data/02', require => Base::Fsdef['/dev/sdb1'];
   
'/dev/sdd1': mountpoint => '/data/03', require => Base::Fsdef['/dev/sdc1'];
   
'/dev/sde1': mountpoint => '/data/04', require => Base::Fsdef['/dev/sdd1'];
   
'/dev/sdf1': mountpoint => '/data/05', require => Base::Fsdef['/dev/sde1'];
   
'/dev/sdg1': mountpoint => '/data/06', require => Base::Fsdef['/dev/sdf1'];
   
'/dev/sdh1': mountpoint => '/data/07', require => Base::Fsdef['/dev/sdg1'];
   
'/dev/sdi1': mountpoint => '/data/08', require => Base::Fsdef['/dev/sdh1'];
   
'/dev/sdj1': mountpoint => '/data/09', require => Base::Fsdef['/dev/sdi1'];
   
'/dev/sdk1': mountpoint => '/data/10', require => Base::Fsdef['/dev/sdj1'];
}

That particular implementation also includes relationship declarations (in the form of require parameters) that will cause Puppet to manage those mounts in the order listed, in case you really do need that.  There are other ways to set up such relationships, too.  Note that this also means that if any of the mount resources fails then Puppet will not manage any of the subsequent ones (another difference from the system's at boot time).


John

amogh patel

unread,
Oct 30, 2014, 1:46:07 PM10/30/14
to puppet...@googlegroups.com
Thanks, John. It did help. I was wondering if we can somehow use an array of these hashes so that we don't have to use require.

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/LAfBVAH-D1g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/587c32e7-a14e-4fc4-9755-5ae67a1a8d4e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
Oct 31, 2014, 9:22:55 AM10/31/14
to puppet...@googlegroups.com


On Thursday, October 30, 2014 12:46:07 PM UTC-5, amogh patel wrote:
Thanks, John. It did help. I was wondering if we can somehow use an array of these hashes so that we don't have to use require.


There are no hashes in my example.  In particular, resource declarations are not hashes, and do not (generally) contain hashes.  The only hashes discussed in this thread so far are your $fs_hash and its contents.

You can avoid using 'require' by using chaining arrows instead.  For example,

base::fsdef { '/dev/sdb1': mountpoint => '/data/01' }
-> base::fsdef { '/dev/sdc1': mountpoint => '/data/02' }
-> base::fsdef { '/dev/sdd1': mountpoint => '/data/03' }
-> base::fsdef { '/dev/sde1': mountpoint => '/data/04' }
-> base::fsdef { '/dev/sdf1': mountpoint => '/data/05' }
-> base::fsdef { '/dev/sdg1': mountpoint => '/data/06' }
-> base::fsdef { '/dev/sdh1': mountpoint => '/data/07' }
-> base::fsdef { '/dev/sdi1': mountpoint => '/data/08' }
-> base::fsdef { '/dev/sdj1': mountpoint => '/data/09' }
-> base::fsdef { '/dev/sdk1': mountpoint => '/data/10' }

That is 100% equivalent to the alternative using the 'require' metaparameter.  You can even mix and match.  You can also add relationships after the fact by applying chaining arrows to resource references:

file { '/tmp/after': ensure => 'file' }
file
{ '/tmp/before': ensure => 'file' }

# this may appear anywhere in the manifest set:
File['/tmp/before'] -> File['/tmp/after']

If your point in wanting to avoid 'require' is that you want an attempt to be made to perform each mount, even if previously-listed ones fail, then we come back around to my previous opening question: why?  Why does the order in which the mounts are applied matter?

Anyway, the Puppet documentation contains a full description of factors affecting resource application order.  You should read and understand the whole thing.

I note in advance that you will find among the docs reference to Puppet's 'ordering' configuration parameter.  You may like the sound of it, but you shouldn't.  If you have bona fide requirements for the order in which resources are applied, then you should declare those requirements explicitly in your manifests (as the docs also say).


John

amogh patel

unread,
Oct 31, 2014, 11:38:18 AM10/31/14
to puppet...@googlegroups.com
Thank you so much John, for taking time and explaining in detail. This really helps new learner like me. :)

Thanks again.

Amogh 

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/LAfBVAH-D1g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages