问题原文
原帖链接 · 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
