How does Ansible determine what version of a module to use (Windows/Unix)?

37 Views Asked by At

Ansible Core has a setup.py module for Unix systems (https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/setup.py). This is responsible for "fact gathering".

Ansible Windows has a setup.ps1 module for Windows systems and mimics the behaviour in setup.py to some extent (https://github.com/ansible-collections/ansible.windows/blob/main/plugins/modules/setup.ps1).

When running:

- name: Setup
  setup:

Ansible correctly identifies which module to run.

My question is, how does Ansible determine which module to run?

I cannot find any action plugins that would be called beforehand that would determine which module to run.

Furthermore, when I attempt to mimic this behvaiour with a custom module I receive errors when running with Unix. This is because it attempts to run the .ps1 version of the module rather than the .py version.

1

There are 1 best solutions below

0
ben brunyee On

I found the answer.

Under the collection you can create a meta/runtime.yml file in which you define:

plugin_routing:
  modules:
    [module_name].ps1:
      redirect: [module_name_in_other_collection]

This then allows you to ues [module_name] and Ansible will determine where to look for the .ps1 variant of that module.