ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
205 stars 159 forks source link

win_iis_website : serverAutoStart attribute is not updated (All Boolean value) #139

Open ygo74 opened 4 years ago

ygo74 commented 4 years ago
SUMMARY

I'm not able to update the boolean attribute serverAutoStart with module win_iis_website

ISSUE TYPE
COMPONENT NAME

win_iis_website

ANSIBLE VERSION
ansible 2.9.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/etc/ansible/modules', u'/appli/alm/libs/v1.5/modules']
  ansible python module location = /appli/alm/venv/ansible-2.9_p27/lib/python2.7/site-packages/ansible
  executable location = /appli/alm/venv/ansible-2.9_p27/bin/ansible
  python version = 2.7.5 (default, Sep 26 2019, 13:23:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION
DEFAULT_LOOKUP_PLUGIN_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/lookup_plugins', u'/appli/alm/libs/v1.5/lookup_plugins']
DEFAULT_MODULE_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/modules', u'/appli/alm/libs/v1.5/modules']
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/roles', u'/usr/share/ansible/roles']
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30
OS / ENVIRONMENT

All Windows versions

STEPS TO REPRODUCE
    - name: Windows - IIS - Stop WebSite
      win_iis_website:
        name: "test"
        state: stopped
        parameters: 'serverAutoStart:false'

or

    - name: Windows - IIS - Start WebSite
      win_iis_website:
        name: "test"
        state: started
        parameters: 'serverAutoStart:true'
EXPECTED RESULTS

I expect that serverAutoStart attribute is updated to true or false C:\Windows\System32\inetsrv\appcmd.exe list SITE test /config:* /xml

ACTUAL RESULTS

It changes only the website state but not he serverAutoStart attribute

ygo74 commented 4 years ago

the issue is you can't compare a boolean value with a string value, the powershell result of this comparison is always false so attribute is never updated

sample of potential fix :


    # Set properties
    if($parameters) {
      $parameters | ForEach-Object {
        $property_value = Get-ItemProperty "IIS:\Sites\$($site.Name)" $_[0]

        switch ($property_value.GetType().Name)
        {
            "ConfigurationAttribute" { $parameter_value = $property_value.value }
            "String" { $parameter_value = $property_value }
        }

        # Fix space after split of parameters
        $inputValue = $_[1]
        if ($null -ne $inputValue) {$inputValue = $inputValue.Trim()}

        # Fix Boolean
        if ($parameter_value.GetType().FullName -eq "System.Boolean")
        {
           $inputValue = [System.Convert]::ToBoolean($inputValue)
        }

        if((-not $parameter_value) -or ($parameter_value) -ne $inputValue) {
          Set-ItemProperty -LiteralPath "IIS:\Sites\$($site.Name)" $_[0] $inputValue
          $result.changed = $true
        }
      }
    }
ygo74 commented 3 years ago

Hello,

I'm updating my roles to be compatible with ansible 2.10 / python 3. I found that I have a workaround in my role (this solution) and I see my open issue stills opened 👎 Could I have a reply ? Maybe closed in ansible windows collection xx.xx ?