Title: Message Title
Paul Were commented on PUP-9323
Re: Resolve Deferred values on demand instead of at catalog read time
We also have T-Mobile raise this issue on Deferred Action. T-Mobile is engaged in leveraging Deferred Action as described below and at this point, they don't have any alternative options. Here is what they have described. Please review and advise. I am getting unexpected behavior from a deferred function, specifically, it seems to be running earlier in the catalog apply process than I expect. I have a repo of user_scripts that I sync out to a host with a vcsrepo resource. These scripts need to get uploaded into our MaaS controller only if they don't exist yet or if the script gets updated in its repo (and synced to the host). I am using a deferred function to calculate the sha256 of the file on disk so that my maas_node_script provider can compare the current file on disk with the one in its DB to determine if it needs to be updated or not. I have a requirement on the vcsrepo but the function runs before the repo has cloned, causing failures on a fresh run, or requiring multiple runs to apply the script changes if they already exist. I expect the function to run at the time the resource is evaluated in the catalog on the agent but it seems to be running before it should. OS: rhel 8.3 puppet agent version: 6.21.1 puppet pe version: 2019.8.5 sample code:
$h =
Unknown macro: { 'scripts_dir' => '/root/user_scripts', 'user_scripts_branch' => 'master', 'user_scripts' => [ Unknown macro}
, Unknown macro: { 'name' => '00-prework', 'file' => '00-prework.sh' } , ] }
clone scripts repo vcsrepo { $h['scripts_dir']: ensure => 'latest', provider => git, source => "https://gitlab:${token}@gitlab.com/user_scripts.git", revision => $h['user_scripts_branch'], trust_server_cert => true, } $h['user_scripts'].each |$i,$k,$script_path="${h['scripts_dir']}/${k['file']}"|
Unknown macro: { maas_node_script Unknown macro}
}
lib/puppet/functions/tmo_maas_controller/file_sha256.rb Puppet::Functions.create_function(:'tmo_maas_controller::file_sha256') do dispatch :get_sha do param 'String', :file_and_path end def get_sha(file_and_path) # file should exist if File.exist?(file_and_path) script_contents = File.read(file_and_path)&.strip else raise(Puppet::Error, "file=>#{file_and_path}< does not exist") # <-- I always get this error and a failed catalog apply if the repo hasnt been cloned yet (so far requires a manual clone) end # file should containe some text if script_contents.nil? || script_contents.empty? raise(Puppet::Error, "file=>#{file_and_path}< does not have any contents") end #