community.windows
community.windows copied to clipboard
win_iis_webapppool cant set attributes for pool with "value" in the name
SUMMARY
win_iis_webapppool module fails with the below error when the word "value" in the app pool name and you try and set attributes:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, <No file>: line 225
fatal: [hob.hey.net]: FAILED! => {"changed": false, "msg": "Unhandled exception while executing module: You cannot call a method on a null-valued expression."}
ISSUE TYPE
- Bug Report
COMPONENT NAME
community.windows.win_iis_webapppool
ANSIBLE VERSION
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat
4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
/usr/local/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
ansible [core 2.11.12]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
jinja version = 3.0.3
libyaml = True
COLLECTION VERSION
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat
4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
/usr/local/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
# /usr/local/lib/python3.6/site-packages/ansible_collections
Collection Version
----------------- -------
community.windows 1.8.0
# /root/.ansible/collections/ansible_collections
Collection Version
----------------- -------
community.windows 1.10.0
CONFIGURATION
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat
4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
/usr/local/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
OS / ENVIRONMENT
I have tested this on Windows Server 2012 R2, Windows Server 2016 & Windows Server 2019
STEPS TO REPRODUCE
Blank IIS Target Web Server. Run the below playbook and note the failure above.
---
- name: App Pool Breaks
hosts: hob.hey.net
become: false
gather_facts: no
vars:
ansible_port: 5985
ansible_connection: winrm
ansible_winrm_transport: ntlm
ansible_winrm_server_cert_validation: ignore
tasks:
- name: Create Website Application Pool
win_iis_webapppool:
name: "value"
state: started
attributes:
managedRuntimeVersion: v4.0
startMode: "AlwaysRunning"
processModel.identityType: ApplicationIdentity
processModel.idleTimeout: 0
recycling.periodicRestart.time: "00:29:00:00.000000"
EXPECTED RESULTS
Create an app pool, set attributes provided in the attributes dict.
ACTUAL RESULTS
Creates the application pool and throws the below error when setting the attributes
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, <No file>: line 225
fatal: [hob.hey.net]: FAILED! => {"changed": false, "msg": "Unhandled exception while executing module: You cannot call a method on a null-valued expression."}
POTENTIAL BUG
It looks like in this section of the powershell when the Convert-ToPropertyValue
function is run for the current attribute value it is checking for a property named value and then setting the attribute_value to that property. but the match statement is finding the word value in the properties and incorrectly returning true.
Statement calling the Convert-ToPropertyValue
function for current attribute Value:
line 224: $current_raw_value = Get-ItemProperty -LiteralPath IIS:\AppPools\$name -Name $attribute_key -ErrorAction SilentlyContinue
line 225: $current_value = Convert-ToPropertyValue -pool $pool -attribute_key $attribute_key -attribute_value $current_raw_value
Statement in Convert-ToPropertyValue
checking for the Value property:
line 111: if ([bool]($attribute_value.PSobject.Properties -match "Value")) {
line 112: $attribute_value = $attribute_value.Value
line 113: }
Below script to reproduce this scenario:
New-WebAppPool -Name Value
$current_raw_value = Get-ItemProperty -LiteralPath IIS:\AppPools\Value -Name "processModel.identityType" -ErrorAction SilentlyContinue
if ([bool]($current_raw_value.PSobject.Properties -match "Value")) {
Write-Host "Incorrectly Returned True"
}
Result:
i'm running into this issue now. Is there a fix for this? or any type of syntax to get around this?
Looks like I am getting the same issues with win_xml as well when I have an attribute of value in an xml document
The full traceback is:
You cannot call a method on a null-valued expression.
At line:188 char:13
+ $candidate = $xmlorig.CreateElement($xmlfragment.get_Docu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvokeMethodOnNull
ScriptStackTrace:
at <ScriptBlock>, <No file>: line 188
fatal: [test.dev]: FAILED! => changed=false
msg: 'Unhandled exception while executing module: You cannot call a method on a null-valued expression.'
Looks like I am getting the same issues with win_xml as well when I have an attribute of value in an xml document
The full traceback is: You cannot call a method on a null-valued expression. At line:188 char:13 + $candidate = $xmlorig.CreateElement($xmlfragment.get_Docu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : InvokeMethodOnNull ScriptStackTrace: at <ScriptBlock>, <No file>: line 188 fatal: [test.dev]: FAILED! => changed=false msg: 'Unhandled exception while executing module: You cannot call a method on a null-valued expression.'
I sadly don't think there's a fix for this. It works for everything else besides if you wanna build a site with the word value. Really Unfortunate.
I'm getting the same issue. Somebody please make a pull request where this line
https://github.com/ansible-collections/community.windows/blob/main/plugins/modules/win_iis_webapppool.ps1#L111
if ([bool]($attribute_value.PSobject.Properties -match "Value")) {
is replaced with
if ([bool]($attribute_value.PSobject.Properties.Name -eq "Value")) {
Root cause is that the string "Value"
is matched against collection of property objects of the $attribute_value
but from the context it can be deduced that "Value"
should only be matched against collection of names of those properties. Match should not be partial either, hence the -eq
operator.