-
Notifications
You must be signed in to change notification settings - Fork 167
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
win_environment : Maybe add an option to read variable content ? #605
Comments
I don't see a real benefit of doing this over a simple call to - hosts: windows
gather_facts: false
tasks:
- name: Gather all env vars
setup:
gather_subset: env
- name: Display env var through facts
debug:
var: ansible_env['SystemRoot']
- name: get env var through win_shell
win_shell: $env:SystemRoot
register: shell_res
changed_when: False
- name: Display env var through win_shell
debug:
var: shell_res.stdout | trim # Or shell_res.stdout_lines[0] The We try to avoid having modules that both set a state and get a state in favour of separate modules. While we do have some today that do that it's more of a historical thing that happened before we put those rules in place. |
Why is that ? |
It makes the module development a lot easier to handle as they stay dedicated to one task and one task only. For example
While yes this is a pretty simple thing to add support for I don't believe the benefits outweigh the extra complexity in the code, especially since the |
While I understand (and agree) what @jborean93 states regarding the single purpose/responsibility of a module, I would like to add that for me So my question is: How could I achieve this other than using a PowerShell script (which is what I do now)? Maybe I'm missing something here.. Thanks for your reply! If anyone is interested this is what I do now (don't hit me 🙃):
|
Short of using a Getting values for specific scopes is a bit of a niche scenario as typically you just set the value rather than get the value. In your particular example you can just use ansible.windows.win_path to idempotently set the - ansible.windows.win_path:
name: PATH
elements:
- C:\Program Files\OpenSSL\bin
# scope: user # Uncomment if you want this on the suer scope |
Thanks so much, @jborean93. Apparently that's what I was missing as this seems to do exactly what I need. I wonder why I wasn't able to find that before... m( |
SUMMARY
win_environment only modify var. We could add an option to return the current value.
ISSUE TYPE
COMPONENT NAME
We could only return the value when no actual value is given
ADDITIONAL INFORMATION
Return value of TestVariable
The text was updated successfully, but these errors were encountered: