Hi
I’m trying to work through the process on how best to document the versions of PowerShell that a module may support. In the past modules only worked on Windows PowerShell provided by Windows. The upcoming Ansible 2.21 release adds support for running modules against PowerShell 7.x as well as running PowerShell modules on POSIX hosts. I still need to submit a PR to the Ansible documentation repo to document these changes and update the dev guide for PowerShell but the first thing I want to try and do is standardise a common way for collections to document what PowerShell versions a module supports.
The goal would be to have a common approach where a module could:
- indicate what PowerShell version(s) it supports
- 5.1 being Windows PowerShell (powershell.exe)
- 7 being PowerShell 7 (pwsh.exe)
- 7.x being a specific PowerShell 7 version rather than just 7 in general
- the above may not be ideal as Ansible will only support one 7.x version in a release due to lifecycle constraints of PowerShell
- a free form human description that can provide more context
- maybe even a field that indicates what PowerShell version is used by default
- the
#!powershellshebang defaults to WinPS on Windows and Pwsh on POSIX - the
#!/usr/bin/pwshshebang defaults to Pwsh on Windows and POSIX - either option can still be overriden by
ansible_pwsh_interpreterlike how Python works
- the
It would also potentially be nice if each version could have a ternary like value that indicates whether that version is:
validated through tests as working
may not be tested or tested thoroughly but should work
known to not work
For example we have some modules that are next to impossible to test in CI and while they should work it has not been validated to work on version x, y, z, etc.
My first approach was to create a doc fragment with the powershell attribute defined as:
attributes:
powershell:
description:
- List of target PowerShell versions specified by O(versions) supported by
this module.
- Version V(7) without a minor version specified means the V(7.x) versions
should be supported by Ansible should work but see O(details) for more
information.
- PowerShell V(5.1) is supported on Windows only while V(7.x) is
cross-platform. See O(platform) for more details on what platforms are
supported.
support: N/A
Each module would then define the versions, optional details, any other options relevant to PowerShell and that module.
extends_documentation_fragment:
- ns.name.powershell_fragment
attributes:
powershell:
versions:
- '5.1'
- '7'
When attempting to see what that would look like in a PR I’ve found that our documentation builder is strict on what child keys are allowed in an attribute Document PowerShell version support by jborean93 · Pull Request #52 · ansible-collections/microsoft.iis · GitHub. From my understanding the attributes were designed as a free form and flexible way for metadata to be applied to modules but maybe it’s evolved from there to ensure the attribute table in the documentation can still be rendered. I’m not against the stricter validation logic here to enforce common values but just wanted to bring this up as if this approach is desired then we would need this validation to be updated to support the new powershell structure in whatever format is desired.
Another alternative I could do is use the support key indicate what versions are supported:
attributes:
powershell:
description:
- Target PowerShell versions supported.
- V(suppport=full) works on both Windows PowerShell 5.1 and Powershell 7.x.
- V(support=partial) works on either, see O(details) for more information.
The advantage here is it works in the existing validation schema but looses some flexibility in specifying specific versions and relies on the description and details to provide more context. It also could potentially conflate partial support being the PowerShell version rather than specific features only being partially supported. I’m not the biggest fan of this approach as it really feels like shoehorning data into a structure that’s not really designed for it and the end result in the documentation is just poorer because of that.
A final alternatives is to just not use the attributes and use the notes or some other free form field to document what PowerShell versions are supported or not but this means our documentation builder can’t take advantage of this to provide a nicer indication of what is and isn’t supported. Maybe this is an ok stop gap until a decision is made on the correct approach and the relevant changes are made to the documentation validator and builder.
If we were to go with the first approach it could enable us to provide a more user friendly output rather than the somewhat limited attributes table we use today. For example we could generate a new section to the rst that could look something like:
Attributes
Existing attributes go here as they always have.
| Attribute | Support | Description |
|---|---|---|
| action | full | Action description. |
| check_mode | full | Check mode description. |
PowerShell
This module supports the following PowerShell versions
- … list of versions indicated by the attribute
5.1
7 - May contain bugs
7 - Known to not support this version at all
… any further information from the details key.
I would love to see what people’s thoughts and potential other ideas may be. I want to ensure that whatever approach that is taken results in an easy way to document the PowerShell version requirements from a dev perspective but also a human friendly way to see those requirements in the module documentation itself.
While I’m not suggesting we should do this, the approach we take here could also be used for indicating things like Python versions, or even other module languages.