-
Notifications
You must be signed in to change notification settings - Fork 2.2k
(PUP-3399) autorequire local file sources #8909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -396,6 +396,13 @@ def self.title_patterns | |||||||||||||||||
end | ||||||||||||||||||
# if the resource is a link, make sure the target is created first | ||||||||||||||||||
req << self[:target] if self[:target] | ||||||||||||||||||
# if the resource has a source set, make sure it is created first | ||||||||||||||||||
self[:source]&.each do |src| | ||||||||||||||||||
req << src.delete_prefix('file://') if src.start_with?('file://') | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems on Windows, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or rather, it is, but the path being set as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If puppet/lib/puppet/type/file/source.rb Lines 111 to 118 in 7f41466
irb(main):034:0> Puppet::Util.uri_unescape(Puppet::Util.path_to_uri("/a path").to_s)
=> "file:///a path" Since the source has been normalized, I think you can simply do: irb(main):038:0> Puppet::Util.uri_to_path(URI(Puppet::Util.uri_encode(source)))
=> "/a path" And it will work correctly on all platforms (including Windows). Is there a particular scenario where this comes up frequently? Or just something that would be good to fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "this" being Windows or autorequires for the source attribute? If the latter: we had it come up in one of our (the foreman) modules and I thought it'd be nice to have. Certainly not everyday material. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah the latter, wondering when you'd need to autorequire local sources.
I'm always hesitant to modify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened this because of this hack we have over in The TL;DR version is: We have a different deployment modes:
In either case, the certs need to land in a place where mosquitto can read them (selinux, perms, etc), so we need to copy them from one place to another. Local source seems like the correct way here, but it needs an explicit require, IF the thing is managed by puppet (it might not be). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think a source shouldn't apply if something is ensured absent, but you raise a good point. At first glance, the whole autorequire looks like it's not well designed for ensuring absent. The target relation is not needed either (but probably doesn't hurt in practice). You'd think Finding all ancestors up to the root however is not needed at all and could even introduce problems. Assuming file { ['/path', '/path/sub']::
ensure => absent,
} Yields: # puppet apply test.pp
Notice: Compiled catalog for host.example.com in environment production in 0.01 seconds
Notice: /Stage[main]/Main/File[/tmp/path]: Not removing directory; use 'force' to override
Notice: /Stage[main]/Main/File[/tmp/path]/ensure: removed
Notice: /Stage[main]/Main/File[/tmp/path/sub]: Not removing directory; use 'force' to override
Notice: /Stage[main]/Main/File[/tmp/path/sub]/ensure: removed
Notice: Applied catalog in 0.01 seconds Ok, misleading. So we modify it to: # puppet apply test.pp
Notice: Compiled catalog for host.example.com in environment production in 0.01 seconds
Notice: /Stage[main]/Main/File[/tmp/path]/ensure: removed
Notice: Applied catalog in 0.02 seconds Upon further inspection, this tries to remove the top most directory first. That's actually good. It doesn't list all sub-resources and is probably more efficient. If it then needs to ensure a file within the directory it is actually idempotent: it'll fail because the parent doesn't exist, instead of creating the file and then removing the parent which would cause it fail on the next run. |
||||||||||||||||||
# the source gets translated to file:///D:/source instead of file://D:/source | ||||||||||||||||||
# see https://github.com/puppetlabs/puppet/commit/5fea1dc64829e9c8178937764faccd51131b2a77 | ||||||||||||||||||
req << src.delete_prefix('file:///') if src.start_with?('file:///') && Puppet::Util::Platform.windows? | ||||||||||||||||||
end | ||||||||||||||||||
req | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.