Skip to content
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

for dynamic parameters (multi-type) or action-chain publishing allow explicit casting of jinja variables #3515

Open
cognifloyd opened this issue Jun 24, 2017 · 3 comments

Comments

@cognifloyd
Copy link
Member

cognifloyd commented Jun 24, 2017

If I have an workflow parameter like:

example:
  required: true
  type: [integer, string]
  description: "An example parameter"

I don't think st2 can know what to cast the parameter as if I use it in a jinja template.

"{{ example }}" will always be a string, even if I do something like "{{ example | int }}"

In cases where it is not clear what data type something should be, like the above contrived example, If I explicitly run it through a jinja filter that specifies a type, please cast it as that type.

Some parameters can't specify a type because they can have various inputs, but within the context of, say, a particular ansible playbook, I know what type to expect, even if I can't tell ST2 in a schema that this var will be this type. Please allow type casting of jinja templates through either a jinja filter or some kind of new directive.

Finding a way to use the jinja filters will feel cleaner, but I implemented special parsing using directive-like magic strings for INT, AST, and JSON type objects in StackStorm-Exchange/stackstorm-ansible#14. Something more generic would be nice.

edit: see the next comment for publishing variables in action-chain workflows

@cognifloyd cognifloyd changed the title for dynamic parameters (multi-type) allow explicit casting of jinja variables for dynamic parameters (multi-type) or action-chain publishing allow explicit casting of jinja variables Jun 26, 2017
@cognifloyd
Copy link
Member Author

Here's another time where casting is a problem:
I just tried to publish an object in an action-chain workflow, but then that object is a string and can't be referenced in subesequent jinja templates as some_var.some_attribute. Publish needs the ability to specify what type a published var is.

@Kami
Copy link
Member

Kami commented Jun 26, 2017

Usually it's better if a variable / parameter contains only a single type (less ambiguity).

Having said that, there are probably some valid use cases for multiple-types and in that scenario what you have proposed (explicit casting) by the user makes sense.

As far as the implementation goes - would need to dig in, might be a bit complex because of the way and place where the casting is done now.

@cognifloyd
Copy link
Member Author

cognifloyd commented Jun 26, 2017

Usually it's better if a variable / parameter contains only a single type (less ambiguity).
Having said that, there are probably some valid use cases for multiple-types...

True less ambiguity is great when possible. Merely supporting multiple types / dynamic types is probably not as important. Here are my more concrete use cases:

One use case I have is passing stuff into ansible's extra_vars which is a list of either strings or objects. I implemented a workaround for that in StackStorm-Exchange/stackstorm-ansible#14.

The other use case I have is, after running an ansible.command with ansible_module=setup on a single host, I want to publish a facts var in an action-chain workfow:

name: "ansible_setup"
ref: "ansible.command"
  hosts: "all"
  module_name: "setup"
  limit: "{{ ansible_host }}"
  json: True
  inventory_file: "{{ inventory_file }}"
publish:
  facts:  "{{ ansible_setup.stdout[ansible_host].ansible_facts }}"

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

No branches or pull requests

2 participants