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

Puppet: Change file on readonly filesystem

· 52CE 我爱测

I'd like to use puppet to manage files on read-only filesystems. So I need to remount the filesystem read-write before modification, and read only afterwards. I made two exec resources : exec { 'mount rw': command => "/sbin/mount…

问题原文

原帖链接 · mooky · CC BY-SA 4.0

I'd like to use puppet to manage files on read-only filesystems. So I need to remount the filesystem read-write before modification, and read only afterwards.

I made two exec resources :

exec { 'mount rw':
  command => "/sbin/mount -uw /",
  refreshonly => true,
}
exec { 'mount ro':
  command => "/sbin/mount -ur /",
  refreshonly => true,
}

Obviously, I want them to be called by my file, only if the file is modified.

file { '/root/puppettest':
  content => template('mfs/puppettest'),
  require => Exec['mount rw'],
  notify  => Exec['mount ro'],
}

My problem : mount rw is never executed, as require is not considered as a refresh.

How can I do something like this ?

已采纳解答

原帖链接 · bodgit · CC BY-SA 4.0

You can try using the transition module to accomplish this.

Something like:

transition { 'mount rw':
  resource   => Exec['mount rw'],
  attributes => { refreshonly => false },
  prior_to   => File['/root/puppettest'],
}

This should then flip the refreshonly attribute from true to false (and therefore make your first exec resource unconditionally run if the file needs to be changed.

The problem you have is that if the filesystem is mounted read-write and the files match what Puppet expects, it will never mount the filesystem read-only again. So you could probably just use the mount resource and use the transition resource to change the options attribute, something like:

file { '/root/puppettest':
  content => ...
  before  => Mount['/'],
}

transition { 'remount / rw':
  resource   => Mount['/'],
  attributes => { options => 'rw,...' },
  prior_to   => File['/root/pupppettest'],
}

mount { '/':
  ... # Rest of the options skipped for brevity
  options  => 'ro,...',
  remounts => true,
}

You're then modelling the intended state of the system.

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

资料来源与适用范围

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

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

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