大网数据广告活动
服务器运维问答

Puppet, changing multiple properties file with augeas

· 52CE 我爱测

I'm using puppet and augeas tool quite a lot to configure property files. My latest requirement is to apply the same fixed set of changes to quite a long list of property files. So, I would like to do it in one run, and not to wr…

问题原文

原帖链接 · bioShark · CC BY-SA 3.0

I'm using puppet and augeas tool quite a lot to configure property files. My latest requirement is to apply the same fixed set of changes to quite a long list of property files. So, I would like to do it in one run, and not to write an augeas for each property file.

Example:

  augeas { 'change_name_whatever':
    lens    => 'a_customized_lens',
    incl    => "$path/file1.properties", 
    changes => $change_set,
  }
  augeas { 'change_name_whatever':
    lens    => 'a_customized_lens',
    incl    => "$path/file2.properties", 
    changes => $change_set,
  }
etc...

I would like to use:

  augeas { 'change_name_whatever':
    lens    => 'a_customized_lens',
    incl    => "[list of files to change], 
    changes => $change_set,
  }

but it's not possible since augeas needs to pre-load the file.

Since I am using puppet 3.8, I can't use foreach type of looping. I saw that in puppet 4 you can declare a list of files, and then loop on them and do your thing. Which is cool... but doesn't work in puppet 3.

So, do I have any other solution then copy/pasting the same code many times?

cheers.

已采纳解答

原帖链接 · raphink · CC BY-SA 3.0

The best option to achieve that is to create a defined resource type:

define customized::filetype ($change_set) {
 augeas { "customized filetype ${title}":
    lens    => 'a_customized_lens',
    incl    => $name, 
    changes => $change_set,
  }
}

and then use it with an array in the title:

customized::filetype { [
  "$path/file1.properties",
  "$path/file2.properties"
  ]:
  change_set => $change_set,
}

You could even (and I'd recommend it) abstract the change set as key/value parameters in the defined resource type. For example:

define customized::filetype ($key, $value) {
 augeas { "customized filetype ${title}":
    lens    => 'a_customized_lens',
    incl    => $name, 
    changes => "set ${key} ${value}",
  }
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。