Skip to content

Commit

Permalink
Avoid running args rule if we encounter a windows module (#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka authored Apr 19, 2023
1 parent fd23b3a commit b5e48e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions examples/playbooks/rule-args-module-pass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@
owner: false
group: false
use_ssh_args: true

- name: Create software directory (Windows module - Bug 3200)
ansible.windows.win_file:
path: "c:\\test_dir"
state: directory
16 changes: 13 additions & 3 deletions src/ansiblelint/rules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# pylint: disable=reimported
import ansible.module_utils.basic as mock_ansible_module
from ansible.module_utils import basic
from ansible.plugins import loader
from ansible.plugins.loader import PluginLoadContext, module_loader

from ansiblelint.constants import LINE_NUMBER_KEY
from ansiblelint.errors import MatchError
Expand Down Expand Up @@ -63,9 +63,9 @@


@lru_cache
def load_module(module_name: str) -> loader.PluginLoadContext:
def load_module(module_name: str) -> PluginLoadContext:
"""Load plugin from module name and cache it."""
return loader.module_loader.find_plugin_with_context(module_name)
return module_loader.find_plugin_with_context(module_name)


class ValidationPassed(Exception):
Expand Down Expand Up @@ -105,6 +105,16 @@ def matchtask(
return []

loaded_module = load_module(module_name)

# https://github.com/ansible/ansible-lint/issues/3200
# since "ps1" modules cannot be executed on POSIX platforms, we will
# avoid running this rule for such modules
if isinstance(
loaded_module.plugin_resolved_path,
str,
) and loaded_module.plugin_resolved_path.endswith(".ps1"):
return []

module_args = {
key: value
for key, value in task["action"].items()
Expand Down
2 changes: 1 addition & 1 deletion tools/install-reqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -euo pipefail
pushd examples/playbooks/collections >/dev/null
MISSING=()
export ANSIBLE_COLLECTIONS_PATH=.
for COLLECTION in ansible.posix community.docker community.general community.molecule;
for COLLECTION in ansible.posix community.docker community.general community.molecule ansible.windows;
do
COL_NAME=${COLLECTION//\./-}
FILENAME=$(find . -maxdepth 1 -name "$COL_NAME*" -print -quit)
Expand Down

0 comments on commit b5e48e6

Please sign in to comment.