Ask Your Question
0

unable to iterate filesystem in puppet

asked 2015-03-31 12:46:42 -0500

Chutki gravatar image

Hi,

I want to create file system according the block devices available in disk

below manifests I tried to create file system

 class fs_creation{

 $tmpa = split($blockdevices, ',')
  $tmpb = delete($tmp1, 'sda')
  $tmpc = prefix($tmp2, '/dev/')
  $count = size($tmpc)

  $pdisk = [$tmpc]

 $mountpoint = ["01","02"]

   filesystem { $pdisk :
    ensure  => present,
    fs_type => 'ext4',
    options => '-b 4096',
  }

   file { "/opt/hd/db/data/${mountpoint}" :
    ensure  => directory,
    owner   => '497',
    group   => '497',
    mode    => '0755',
    require => Filesystem[$pdisk],
  }
}

It is creating pv like sdb,sdc but unable to create like "/opt/hd/db/data/01 and /opt/hd/db/data/02", its taking as single string below is o/p

Notify[/dev/sdb]/message: current_value absent, should be /dev/sdb (noop)
Notify[/dev/sdc]/message: current_value absent, should be /dev/sdc (noop)
Notice: /Stage[main]/fs_creation/File[/opt/hd/db/data/0102]/ensure: current_value absent, should be directory (noop)

I want o/p like

/dev/sdb 
mount => "/opt/hd/db/01"
/dev/sdc
mount => "/opt/hd/db/02"

So if block devices are sdb,sdc,sdd,sde the, i want to create file system as

  /dev/sdb 
    mount => "/opt/hd/db/01"
  /dev/sdc
    mount => "/opt/hd/db/02"
/dev/sdd 
  mount => "/opt/hd/db/03"
/dev/sde
  mount => "/opt/hd/db/04"

I am unable to iterate file system directory 01,02,03,..... according to availabe block devices.

I tried inline_template but not very sure of what ruby need to pass, also template will not work here since I want to pass iterate value to variable to create file system.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2015-03-31 18:45:57 -0500

GregLarkin gravatar image

Your $mountpoint variable is converted into a concatenated string in your file resource, which make sense since you are interpolating it into a string.

I think you need to look into using an iterator ( https://docs.puppetlabs.com/reference... ) in combination with a defined type so you can walk your list of devices, convert their names into the other forms you need and eventually feed that to your filesystem and file resources.

Note that you will have to enable the future parser to get iterators working.

edit flag offensive delete link more

Comments

I don't think each iteration work since the mount should iterate according to blockdevice count. I am trying below in puppet $tmp = size(blockdevice) $mount = 0 Loop $tmp < $mount { $mount + =1 } so $mount var update in file resource as I mentioned my eg,also will not exceed blockdevice count

Chutki gravatar imageChutki ( 2015-04-05 12:25:27 -0500 )edit

Not sure whether it is possbile in puppet

Chutki gravatar imageChutki ( 2015-04-05 12:30:49 -0500 )edit

You won't be able to write a loop like that in standard Puppet DSL. You may be able to solve the problem with an iterator (Puppet future parser), an inline template or a custom parser function, though.

GregLarkin gravatar imageGregLarkin ( 2015-04-05 22:35:20 -0500 )edit
0

answered 2015-04-15 04:48:43 -0500

Chutki gravatar image

I referred below URL and it woked - https://ttboj.wordpress.com/2013/11/1...

edit flag offensive delete link more

Comments

Please share your code here, if you would. It may be helpful to someone else in the future.

GregLarkin gravatar imageGregLarkin ( 2015-04-15 21:20:33 -0500 )edit
0

answered 2015-04-06 22:01:01 -0500

rnelson0 gravatar image

updated 2015-04-06 22:02:35 -0500

Perhaps you should create a defined type and feed it to create_resources with a hash or the output of hiera_hash to populate the necessary information. While that's not an iterator, it's a strong state definition (vs. an ambiguous "depends on some string" state definition), separates your code from your data, and can be updated via a configuration database easily (hiera mysql backend, for instance).

Hiera:

fs_with_mountpoints:
  '/dev/sdb':
    mountpoint: '/opt/hd/db/01'
  '/dev/sdc':
    mountpoint: '/opt/hd/db/02'
  '/dev/sdd':
    mountpoint: '/opt/hd/db/03'
  '/dev/sde':
    mountpoint: '/opt/hd/db/04'

Defined type, in your class's manifests:

define fs_with_mountpoint (
  $pdisk = $title,
  $mountpoint,
) {
  filesystem { $pdisk :
    ensure  => present,
    fs_type => 'ext4',
    options => '-b 4096',
  }

   file { "/opt/hd/db/data/${mountpoint}" :
    ensure  => directory,
    owner   => '497',
    group   => '497',
    mode    => '0755',
    require => Filesystem[$pdisk],
  }
}

Node definition, in your profile/node's manifest (profile preferred):

$fs_with_mountpoints = hiera_hash('fs_with_mountpoints')
create_resources('fs_with_montpoint', $fs_with_mountpoints)
edit flag offensive delete link more

Comments

but I want to iterate according to blockdevice count

Chutki gravatar imageChutki ( 2015-04-15 04:43:09 -0500 )edit

I understand that, but my concern is that you are not building an accurate state model. Your model collapses if, upon boot, one of the drives fails to be detected for any reason. You could end up mounting /dev/sde at /opt/hd/db/03 because /dev/sdd died. Would your application be okay with that?

rnelson0 gravatar imagernelson0 ( 2015-04-16 06:30:13 -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

Stats

Asked: 2015-03-31 12:46:42 -0500

Seen: 334 times

Last updated: Apr 15 '15