ansible/molecule

molecule ignores ANSIBLE_FILTER_PLUGINS env var

ultral opened this issue · 0 comments

Issue Type

  • Bug report

Molecule and Ansible details

ansible [core 2.11.12] 
  config file = None
  configured module search path = ['/home/jenkins_slave/workspace/st_all_roles_and_branches_master/library']
  ansible python module location = /home/jenkins_slave/workspace/st_all_roles_and_branches_master/.venv/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/jenkins_slave/workspace/st_all_roles_and_branches_master/.cache/collections
  executable location = /home/jenkins_slave/workspace/st_all_roles_and_branches_master/.venv/bin/ansible
  python version = 3.8.13 (default, Nov  8 2022, 17:19:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  jinja version = 3.0.3
  libyaml = True

  molecule 4.0.4 using python 3.8 
    ansible:2.11.12
    delegated:4.0.4 from molecule
    docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Detail any linters or test runners used:

Desired Behavior

if set ANSIBLE_FILTER_PLUGINS is set to /home/jenkins_slave/workspace/st_all_roles_and_branches_master/filter_plugins then molecule pass it to ansible-playbook comand.

Actual Behaviour

ANSIBLE_FILTER_PLUGINS is configured to

    /home/jenkins_slave/workspace/st_all_roles_and_branches_master/.venv/lib64/python3.8/site-packages/molecule/provisioner/ansible/plugins/filter
    /home/jenkins_slave/.cache/molecule/bashrc_vars/default/plugins/filter
    /home/jenkins_slave/workspace/st_all_roles_and_branches_master/roles/bashrc_vars/plugins/filter
    /home/jenkins_slave/.ansible/plugins/filter
    /usr/share/ansible/plugins/filter

this behaviour is coming from .venv/lib/python3.8/site-packages/molecule/provisioner/ansible.py. the paths are hardcoded

                "ANSIBLE_FILTER_PLUGINS": ":".join(
                    [
                        self._get_filter_plugin_directory(),
                        util.abs_path(
                            os.path.join(
                                self._config.scenario.ephemeral_directory,
                                "plugins",
                                "filter",
                            )
                        ),
                        util.abs_path(
                            os.path.join(
                                self._config.project_directory, "plugins", "filter"
                            )
                        ),
                        util.abs_path(
                            os.path.join(
                                os.path.expanduser("~"), ".ansible", "plugins", "filter"
                            )
                        ),
                        "/usr/share/ansible/plugins/filter",
                    ]
                ),

it would be nice to see something like:

        roles_path_list = [
            self._get_filter_plugin_directory(),
            util.abs_path(
                os.path.join(
                    self._config.scenario.ephemeral_directory,
                    "plugins",
                    "filter",
                )
            ),
            util.abs_path(
                os.path.join(
                    self._config.project_directory, "plugins", "filter"
                )
            ),
            util.abs_path(
                os.path.join(
                    os.path.expanduser("~"), ".ansible", "plugins", "filter"
                )
            ),
            "/usr/share/ansible/plugins/filter",
        ]

...

        if os.environ.get("ANSIBLE_FILTER_PLUGINS", ""):
            filter_plugins_path_list.extend(
                list(map(util.abs_path, os.environ["ANSIBLE_FILTER_PLUGINS"].split(":")))
            )
        env = util.merge_dicts(
            os.environ,
            {
                "ANSIBLE_CONFIG": self._config.provisioner.config_file,
                "ANSIBLE_ROLES_PATH": ":".join(roles_path_list),
                self._config.ansible_collections_path: ":".join(collections_path_list),
                "ANSIBLE_LIBRARY": ":".join(self._get_modules_directories()),
                "ANSIBLE_FILTER_PLUGINS": ":".join(self.filter_plugins_path_list),
            },
        )