-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
plugin function is executed within an if block that evaluates to false #2181
Comments
The issue here is not that the plugin is executed... this error is happening while the template is parsed, before any of the logic is evaluated. |
Ok. I didn't understand the difference between "parsing the template" and "executing the Am I correct that this means there is no way to use some external way to create a gomplate config file, which may or may not define plugins, and then only execute a plugin if it exists, similar to datasources? |
The reason I suppose it would be possible to create a new way of executing plugins, where plugins were referenced by name rather than as a keyword. But that would be contrary to the main purpose of plugins, which is to provide a very simple way to add functionality to gomplate. Can you give me some more concrete reasoning on why you feel this is necessary? What's the exact use-case? |
First, thanks very much for your time and for considering this. My motivation is to create a config file that can access values the same way regardless of which cloud provider the file is used with. Currently AWS and OpenStack, soon also GCP. I've tried a few approaches to this. For now, I have solved this problem by templating both the gomplate config file and the templated config file using ansible first, so that only the cloud provider-specific plugin functions are present. The approach that raised this issue was like this:
# gomplate config file for AWS
datasources:
awsSecret:
url: 'aws+sm:'
awsAppConfig:
url: 'aws+smp:'
awsVmMetadata:
url: 'aws+imds:'
# gomplate config file for OpenStack
datasources:
openstackVmMetadata:
url: 'http://169.254.169.254/openstack/2018-08-27/meta_data.json'
plugins:
openstackSecret:
cmd: '/opt/gomplate/barbican.sh' # e.g. bash script like 'openstack secret get "$1" -p -f value'
pipe: false
timeout: '5s'
openstackAppConfig:
cmd: '/opt/gomplate/swift.sh'
pipe: false
timeout: '5s' Then in a config file, for example:
On an AWS EC2 instance, with the AWS gomplate config file, the templated config file gave the 'openstackSecret not defined' error. |
Hrm interesting... it seems to me the right way to approach this would be to have a datasource for Barbican. That being said, it's a fairly big lift and not something I have the time to work on any time soon. From the Also an alternative to using In general though, I see the dilemma. One alternative you might consider, since these really are datasource-like things, is to pull the data you need from OpenStack out-of-band and store in a local json file. It should be possible then to arrange the template such that you don't need to call |
This issue is stale because it has been open for 60 days with no If it's still relevant, one of the following will remove the stale
|
This may be the intended behaviour, but it was surprising to me.
I expected that anything within an if block would not be executed when the
pipeline
evaluated toempty
.The plugin function
pluginThatIsNotDefined
does not exist, and I expected that it would not be executed (see below).if this is intended, please document it somewhere.
From the go template doc:
Command:
Output:
The text was updated successfully, but these errors were encountered: