Reputation: 2605
I have created additional files to divide the load on the main puppet file. I want these additional files to return a string in a certain format and have therefore created a function. In multiple files with multiple functions, I want to invoke these functions from the main file and get the results.
util.pp
functions mymodule::retrieveData() >> String {
..
"${results}"
}
main file:
include util.pp
$items = mymodule::retrieveData()
Structure
manifest
- main.pp
- util.pp
The issues:
include util.pp
does not seem to load the file. Error: Could not find class ::util
retrieveData()
to get the String result to store in $items
Upvotes: 1
Views: 968
Reputation: 180201
You have multiple issues, among them:
function
in your function definition.retrieveData.pp
. It follows that each function must go in its own file.manifests/
folder in your module is for files providing definitions of classes and defined types (only). Per the documentation, files providing Puppet-language function definitions go in a sibling of that directory named functions/
.include
statement is for causing classes to be included in the catalog under construction. It is not about source files. If you were trying to declare a class then it would expect you to provide the name of the wanted class, not a file name. In any case, the include
statement has no role in accessing functions, and you should not attempt to use it with them.Overall, declare your function in the correct namespace (apparently done), name its file correspondingly, put the file in the correct location for functions in that namespace, and refer to the function by its correct name and namespace when you call it.
UPDATE:
Since there seems to be some lack of clarity on what the above means, here is a concrete example of it might look:
mymodule/functions/retrieveData.pp:
function mymodule::retrieveData() >> String {
"some data"
}
mymodule/manifests/init.pp:
class mymodule {
$data = mymodule::retrieveData()
notify { "The data are: '${data}'": }
}
Upvotes: 2