Skip to content

module 'WebAdministration' was not loaded because no valid module file was found in any module directory #612

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

Open
eliassal opened this issue Mar 11, 2025 · 2 comments
Labels
needs_info This issue requires further information. Please answer any outstanding questions.

Comments

@eliassal
Copy link

SUMMARY

I have a very basic playbook with the example given at https://docs.ansible.com/ansible/latest/collections/community/windows/win_iis_website_module.html#ansible-collections-community-windows-win-iis-website-module

- 
- name: Acme IIS site
    community.windows.win_iis_website:
      name: Acme
      state: started
      port: 80
      ip: 127.0.0.1
      hostname: acme.local
      application_pool: acme
      physical_path: C:\sites\acme
      parameters: logfile.directory:C:\sites\logs
    register: website

When I run the playbook I get

TASK [Acme IIS site] *****************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, <No file>: line 35
fatal: [webservansible]: FAILED! => {"changed": false, "msg": "Unhandled exception while executing module: The specified module 'WebAdministration' was not loaded because no valid module file was found in any module directory."}

I added before the following tasks which goes through

- name: Add a PowerShell PowerShellGet module
    community.windows.win_psmodule:
      name: PowerShellGet
      state: present
  - name: Add a PowerShell PackageManagement module
    community.windows.win_psmodule:
      name: PackageManagement
      state: present
  - name: Add a PowerShell module
    community.windows.win_psmodule:
      name: IISAdministration
      state: present
      accept_license: true
      skip_publisher_check: true

but it did not help

ISSUE TYPE
  • Bug Report
COMPONENT NAME

WebAdministration

ANSIBLE VERSION
salam@salam7:~/projects/jptoto_windowsLab$ ansible-playbook -i hosts_iis webserver_playbook.yaml

PLAY [webservers] ********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************************
ok: [webservansible]

TASK [Ensure that IIS is installed] **************************************************************************************************************************************************************************************
ok: [webservansible]

TASK [Add a PowerShell PowerShellGet module] *****************************************************************************************************************************************************************************
ok: [webservansible]

TASK [Add a PowerShell PackageManagement module] *************************************************************************************************************************************************************************
ok: [webservansible]

TASK [Add a PowerShell module] *******************************************************************************************************************************************************************************************
ok: [webservansible]

TASK [Ensure the globomantics website directory is created] **************************************************************************************************************************************************************
ok: [webservansible]

TASK [Acme IIS site] *****************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, <No file>: line 35
fatal: [webservansible]: FAILED! => {"changed": false, "msg": "Unhandled exception while executing module: The specified module 'WebAdministration' was not loaded because no valid module file was found in any module directory."}

PLAY RECAP ***************************************************************************************************************************************************************************************************************
webservansible             : ok=6    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

COLLECTION VERSION
----------------- -------
community.windows 2.1.0
CONFIGURATION
CONFIG_FILE() = /etc/ansible/ansible.cfg
OS / ENVIRONMENT

WSL2 ubuntu 22.04

STEPS TO REPRODUCE

create a playbook
run the playbook

---
- hosts: webservers
  vars:
    globomantics_site_path: "c:\\inetpub\\wwwroot\\globosite"
    default_index_file: "index.html"
  tasks:
  - name: Ensure that IIS is installed
    win_feature:
      name: "Web-Server"
      state: present
      restart: no
      include_sub_features: no
      include_management_tools: yes
  - name: Add a PowerShell PowerShellGet module
    community.windows.win_psmodule:
      name: PowerShellGet
      state: present
  - name: Add a PowerShell PackageManagement module
    community.windows.win_psmodule:
      name: PackageManagement
      state: present
  - name: Add a PowerShell module
    community.windows.win_psmodule:
      name: IISAdministration
      state: present
      accept_license: true
      skip_publisher_check: true
  - name: Ensure the globomantics website directory is created
    win_file:
      path: "{{ globomantics_site_path }}"
      state: directory
  - name: Acme IIS site
    community.windows.win_iis_website:
      name: Acme
      state: started
      port: 80
      ip: 127.0.0.1
      hostname: acme.local
      application_pool: acme
      physical_path: C:\sites\acme
      parameters: logfile.directory:C:\sites\logs
    register: website
  - name: Create sub iis website
    win_iis_website:
      name: "Globomantics Application"
      state: started
      port: 8080
      physical_path: "{{ globomantics_site_path }}"

  - name: Copy default index file to site
    win_copy:
      src: "{{ default_index_file }}"
      dest: "{{ globomantics_site_path}}\\index.html"

  - name: Ensure filewall rule is in place for site
    win_firewall_rule:
      name: Globomantics
      enabled: yes
      state: present
      localport: 8080
      action: allow
      direction: in
      protocol: tcp

EXPECTED RESULTS

create iis web site

ACTUAL RESULTS
salam@salam7:~/projects/jptoto_windowsLab$ ansible-playbook -i hosts_iis webserver_playbook.yaml -vvv
ansible-playbook [core 2.15.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/salam/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/salam/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/salam/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.10.12 (main, Feb  4 2025, 14:57:36) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/salam/projects/jptoto_windowsLab/hosts_iis as it did not pass its verify_file() method
script declined parsing /home/salam/projects/jptoto_windowsLab/hosts_iis as it did not pass its verify_file() method
auto declined parsing /home/salam/projects/jptoto_windowsLab/hosts_iis as it did not pass its verify_file() method
Parsed /home/salam/projects/jptoto_windowsLab/hosts_iis inventory source with ini plugin
redirecting (type: modules) ansible.builtin.win_feature to ansible.windows.win_feature
redirecting (type: modules) ansible.builtin.win_file to ansible.windows.win_file
redirecting (type: modules) ansible.builtin.win_iis_website to community.windows.win_iis_website
redirecting (type: action) ansible.builtin.win_copy to ansible.windows.win_copy
redirecting (type: modules) ansible.builtin.win_firewall_rule to community.windows.win_firewall_rule
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: webserver_playbook.yaml ****************************************************************************************************************************************************************************************
1 plays in webserver_playbook.yaml

PLAY [webservers] ********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************************
task path: /home/salam/projects/jptoto_windowsLab/webserver_playbook.yaml:2
redirecting (type: modules) ansible.builtin.setup to ansible.windows.setup
Using module file /home/salam/.local/lib/python3.10/site-packages/ansible_collections/ansible/windows/plugins/modules/setup.ps1
Pipelining is enabled.
<webservansible> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO webservansible
EXEC (via pipeline wrapper)
ok: [webservansible]

TASK [Ensure that IIS is installed] **************************************************************************************************************************************************************************************
task path: /home/salam/projects/jptoto_windowsLab/webserver_playbook.yaml:7
redirecting (type: modules) ansible.builtin.win_feature to ansible.windows.win_feature
redirecting (type: modules) ansible.builtin.win_feature to ansible.windows.win_feature
Using module file /home/salam/.local/lib/python3.10/site-packages/ansible_collections/ansible/windows/plugins/modules/win_feature.ps1
Pipelining is enabled.
<webservansible> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO webservansible
EXEC (via pipeline wrapper)
ok: [webservansible] => {
    "changed": false,
    "exitcode": "NoChangeNeeded",
    "feature_result": [],
    "reboot_required": true,
    "success": true
}

TASK [Add a PowerShell PowerShellGet module] *****************************************************************************************************************************************************************************
task path: /home/salam/projects/jptoto_windowsLab/webserver_playbook.yaml:14
Using module file /home/salam/.local/lib/python3.10/site-packages/ansible_collections/community/windows/plugins/modules/win_psmodule.ps1
Pipelining is enabled.
<webservansible> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO webservansible
EXEC (via pipeline wrapper)
ok: [webservansible] => {
    "changed": false,
    "nuget_changed": false,
    "output": "Module PowerShellGet already present",
    "repository_changed": false
}

TASK [Add a PowerShell PackageManagement module] *************************************************************************************************************************************************************************
task path: /home/salam/projects/jptoto_windowsLab/webserver_playbook.yaml:18
Using module file /home/salam/.local/lib/python3.10/site-packages/ansible_collections/community/windows/plugins/modules/win_psmodule.ps1
Pipelining is enabled.
<webservansible> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO webservansible
EXEC (via pipeline wrapper)
ok: [webservansible] => {
    "changed": false,
    "nuget_changed": false,
    "output": "Module PackageManagement already present",
    "repository_changed": false
}

TASK [Add a PowerShell module] *******************************************************************************************************************************************************************************************
task path: /home/salam/projects/jptoto_windowsLab/webserver_playbook.yaml:22
Using module file /home/salam/.local/lib/python3.10/site-packages/ansible_collections/community/windows/plugins/modules/win_psmodule.ps1
Pipelining is enabled.
<webservansible> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO webservansible
EXEC (via pipeline wrapper)
ok: [webservansible] => {
    "changed": false,
    "nuget_changed": false,
    "output": "Module IISAdministration already present",
    "repository_changed": false
}

TASK [Ensure the globomantics website directory is created] **************************************************************************************************************************************************************
task path: /home/salam/projects/jptoto_windowsLab/webserver_playbook.yaml:28
redirecting (type: modules) ansible.builtin.win_file to ansible.windows.win_file
redirecting (type: modules) ansible.builtin.win_file to ansible.windows.win_file
Using module file /home/salam/.local/lib/python3.10/site-packages/ansible_collections/ansible/windows/plugins/modules/win_file.ps1
Pipelining is enabled.
<webservansible> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO webservansible
EXEC (via pipeline wrapper)
ok: [webservansible] => {
    "changed": false
}

TASK [Acme IIS site] *****************************************************************************************************************************************************************************************************
task path: /home/salam/projects/jptoto_windowsLab/webserver_playbook.yaml:32
Using module file /home/salam/.local/lib/python3.10/site-packages/ansible_collections/community/windows/plugins/modules/win_iis_website.ps1
Pipelining is enabled.
<webservansible> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO webservansible
EXEC (via pipeline wrapper)
The full traceback is:
The specified module 'WebAdministration' was not loaded because no valid module file was found in any module directory.
At line:35 char:5
+     Import-Module WebAdministration
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (WebAdministration:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 35
fatal: [webservansible]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: The specified module 'WebAdministration' was not loaded because no valid module file was found in any module directory."
}

PLAY RECAP ***************************************************************************************************************************************************************************************************************
webservansible             : ok=6    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
@Akasurde
Copy link
Member

@eliassal Do you have Management Tools installed for Web Server? You can check using

Image

You can check UI here -

Image

@Akasurde Akasurde changed the title Unhandled exception while executing module: module 'WebAdministration' was not loaded because no valid module file was found in any module directory."} module 'WebAdministration' was not loaded because no valid module file was found in any module directory Mar 25, 2025
@Akasurde Akasurde added the needs_info This issue requires further information. Please answer any outstanding questions. label Mar 25, 2025
@eliassal
Copy link
Author

eliassal commented Apr 1, 2025

Thanks Akasurde, I added the webadmnistration and was able to run succesfully the playbook. However, visiting IIS management, I saw that the website was created but flagged with red cross and cant start it. After investigating, I noticed that the application pool was not created as expected in the ansible playbook.
Here is the piece of ansible code

- name: Acme IIS site
    community.windows.win_iis_website:
      name: Acme
      state: started
      port: 80
      ip: 127.0.0.1
      hostname: acme.local
      application_pool: acme
      physical_path: C:\sites\acme
      parameters: logfile.directory:C:\sites\logs

and here is a snapshot of the IIS

Image

Here you can see that application pool is not created

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs_info This issue requires further information. Please answer any outstanding questions.
Projects
None yet
Development

No branches or pull requests

2 participants