Skip to content

Instantly share code, notes, and snippets.

@MikaelSmith
Created September 27, 2018 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikaelSmith/024807c1fdb1296a7118a559059d0c6d to your computer and use it in GitHub Desktop.
Save MikaelSmith/024807c1fdb1296a7118a559059d0c6d to your computer and use it in GitHub Desktop.
deferred issue
notify { "hello ${Deferred('pid', [])}": }
notify { "hello ${pid()}": }
file { '/tmp/foo':
ensure => file,
content => Deferred('pid', []),
}
Puppet::Functions.create_function(:pid) do
def pid
Process.pid.to_s
end
end
@MikaelSmith
Copy link
Author

Put pid.rb at foo/lib/puppet/functions/pid.rb. Then run

$ puppet apply foo.pp --modulepath foo
Notice: Compiled catalog for localhost in environment production in 0.04 seconds
Notice: hello Deferred({'name' => 'pid', 'arguments' => []})
Notice: /Stage[main]/Main/Notify[hello Deferred({'name' => 'pid', 'arguments' => []})]/message: defined 'message' as 'hello Deferred({\'name\' => \'pid\', \'arguments\' => []})'
Notice: hello 68774
Notice: /Stage[main]/Main/Notify[hello 68774]/message: defined 'message' as 'hello 68774'
Notice: /Stage[main]/Main/File[/tmp/foo]/ensure: defined content as '{md5}9319e8ccd187e2773282ec8d5a6edc8b'
Notice: Applied catalog in 0.02 seconds
$ cat /tmp/foo
68774

@binford2k
Copy link

If you do it like this, it should work

notify { 'hello notify':
    message => "hello ${Deferred('pid', [])}",
}

@MikaelSmith
Copy link
Author

Still an issue even with that change.

@hlindberg
Copy link

You cannot have Deferred inside of an interpolation and expect that to be resolved on the agent. You need to send the string and the arguments and do a Deferred sprintf or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment