rundeck-plugins / ansible-plugin

Ansible Integration for Rundeck
MIT License
330 stars 100 forks source link

Feature Request: Emtpy Optional Vars should be ignored #299

Open markfaine opened 3 years ago

markfaine commented 3 years ago

If I set arguments in the Extra Variables field and they are to be populated by arguments that are optional, if the user has not selected any value they will be empty, and this will likely result in a failure of the playbook to run.

If they are empty they should not be added as extra vars. Extra vars from ${option.foo} should not be added unless there is a value for option.foo

broferek commented 2 years ago

This is indeed very needed.

For now, I have to work around it with adding another boolean option whichs act as a kind of switch between 2 optional arguments. If true, then a particular argument has to be populated by the user and if false, another argument.

This is not an ideal solution whereas ignoring empty optional vars is !

simon-c-msc commented 1 year ago

An empty string value can sometimes be a correct and expected value that can be used at some point in the playbook.

What you are asking for is Rundeck ansible plugin executing some kind of logic to include or not an option in the extra-vars. Your need does not necessarily match other users'.

Furthermore, according to your example if the option is an empty string the job fails. How would it be any different if the variable was not present at all?

Overall it's much easier to have an empty value and ignore it when it's the case.

There is also the option to have a default value as well.

matthgyver commented 1 year ago

In my case, I've conditional tasks on my playbook like if a variable is defined, run the task but with the actual approach, variable is always defined.

I can revise my conditions to check if the value is empty. However, I also need to check whether the variable is set, as my playbooks can be called without going through rundeck and the sysadmins running them usually don't set the unused variable to empty.

The empty variable overrides the default values set in the inventories. To get around this, as you say, you need to set the same value as default value in the Rundeck option, but if you change it, you need to remember to do this everywhere. After several years and in a large team, not everyone thinks about these kinds of details. (not to mention turn-over)

It would be nice to be able to choose the behavior to adopt in case of an empty value. I understand that it may not be easy to implement.

simon-c-msc commented 1 year ago

I see what you mean, in your case I would use the default filter to set the variable with the default value in the playbook so you can keep the empty value when the playbook is called from Rundeck and keep the undefined variable when called from the cli:

- name: Print var value when not empty string
  debug: "{{ my_var }}"
  when: my_var | default('') != ''

One big challenge to implement the requested behaviour is that options are used for more than just the ansible plugin, so having a checkbox there would not be the most relevant location.

You would need to add an option to the ansible plugin in the extra-vars section. I'm not a contributor to this project so I can't say what it requires to implement this, but it seems like a lot of work for little benefit since checking the var value or using the default filter in the playbook is much easier.

matthgyver commented 1 year ago

Thank you