Skip to content
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

molecule ignores ANSIBLE_FILTER_PLUGINS env var #3839

Closed
ultral opened this issue Mar 7, 2023 · 0 comments · Fixed by #4135
Closed

molecule ignores ANSIBLE_FILTER_PLUGINS env var #3839

ultral opened this issue Mar 7, 2023 · 0 comments · Fixed by #4135
Labels

Comments

@ultral
Copy link
Contributor

ultral commented Mar 7, 2023

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),
            },
        )
@ultral ultral added the bug label Mar 7, 2023
ssbarnea added a commit that referenced this issue Apr 8, 2024
if ANSIBLE_FILTER_PLUGINS set then molecule uses it instead of hardcoded
paths. closes #3839

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant