The community.windows.win_iis_webapplication module shows as changed every time

Hello! I am creating a bunch of IIS web sites under a web application and for some reason the community.windows.win_iis_webapplication module shows that it changes the web apps every time it is executed.

Here is my play:

- name: "Create the web apps"
  community.windows.win_iis_webapplication:
    name: '{{ item.virtual_path }}'
    site: '{{ my_site_web_site.name }}'
    state: present
    physical_path: '{{ item.folder_path }}'
    application_pool: '{{ my_site_app_pool.name }}'
  loop: '{{ my_site_web_apps }}'
  notify: 'Restart web site: {{ my_site_web_site.name }}'

Here’s what my vars look like:

---

debug: false
my_site_app_pool:
  name: My-Default
  auto_start: false
my_site_web_site:
  name: '{{ my_site_app_pool.name }}'
  path: 'D:\Inetpub\{{ my_site_app_pool.name }}'
  url: my-default.example.com
my_site_web_apps:
  - virtual_path: 'App1'
    folder_path: '{{ my_site_web_site.path }}/App1'
  - virtual_path: 'App2'
    folder_path: '{{ my_site_web_site.path }}/App2'

Here’s my output for one of the web apps that I see in AWX:

{
    "changed": true,
    "connect_as": "pass_through",
    "physical_path": "D:\\Inetpub\\My-Default/App1",
    "application_pool": "My-Default",
    "_ansible_no_log": false,
    "item": {
        "virtual_path": "App1",
        "folder_path": "D:\\Inetpub\\My-Default/App1"
    },
    "ansible_loop_var": "item",
    "_ansible_item_label": {
        "virtual_path": "App1",
        "folder_path": "D:\\Inetpub\\My-Default/App1"
    }
}

Finally, here’s what I get when I interrogate the web app using a one-liner:

# Output of this command:
# ansible --ask-vault-pass -i hosts.ini  -m community.windows.win_iis_webapplication -a "name='App1' site='My-Default'" my-server

wi-web19d | SUCCESS => {
    "application_pool": "My-Default",
    "changed": false,
    "connect_as": "pass_through",
    "physical_path": "D:\\Inetpub\\My-Default/App1"
}

I’ve run this play a half-dozen times on the same server and it shows as changed every time. This makes little sense to me because everything looks idempotent to me.

What am I doing wrong?

Hi, how about replacing / with \?

my_site_web_apps:
  - virtual_path: 'App1'
    # folder_path: '{{ my_site_web_site.path }}/App1'
    folder_path: '{{ my_site_web_site.path }}\App1'
  - virtual_path: 'App2'
    # folder_path: '{{ my_site_web_site.path }}/App2'
    folder_path: '{{ my_site_web_site.path }}\App2'

Thank you for the quick suggestion. I just tried your suggestion but unfortunately it didn’t make a difference.

Hmm, I know it will be changed the first time after replacing / with \, but will it continue to be changed after further re-runs?

Let me explain technical background:

By using / in your path, exact / is used in Physical Path for your application. This works, since Windows can handle / as same as \.

image

On the other hand, win_iis_webapplication module compares following two paths to determine if there is any diffs that should be modified:

  • (A) Current configured path for the application
  • (B) Specified path via physical_path

For now, (A) includes / as stated in screenshot above.

But (B) does NOT contain /, since it is compared with the FullName parameter of the object that is retrieved with Get-Item. The FullName parameter of the object that retrieved by Get-Item with the path contains / always uses \ as separator.

See this code block:

So by using / in the path in your playbook, the module always determines that the path is incorrect and should be modified, and returns changed. This is why I think the cause of your issue is using / in path.

2 Likes

This is very helpful @kurokobo , thank you!

Well, I’m surprised to say that I’m not having this issue any more :slight_smile: I’m not sure why though. I made your suggested changes to the file paths, but even after repeated runs that didn’t seem to fix the problem.

I then changed the part of my module that creates an app pool. I changed the state property from “stopped” to “present”.

But that seems to be it, and now everything is working as expected.

Thanks again for all of your help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.