ansible/molecule

The env option of the shell dependency has no effect

gardar opened this issue · 0 comments

Prerequisites

  • This was not already reported in the past (duplicate check)
  • It does reproduce it with code from main branch (latest unreleased version)
  • I include a minimal example for reproducing the bug
  • The bug is not trivial, as for those a direct pull-request is preferred
  • Running pip check does not report any conflicts
  • I was able to reproduce the issue on a different machine
  • The issue is not specific to any driver other than 'default' one

Environment

molecule 24.2.0 using python 3.11
    ansible:2.16.5
    azure:23.5.0 from molecule_plugins
    containers:23.5.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    default:24.2.0 from molecule
    docker:23.5.0 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
    ec2:23.5.0 from molecule_plugins
    gce:23.5.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    podman:23.5.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
    vagrant:23.5.0 from molecule_plugins

What happened

The env option of the shell dependency has no effect, despite what the documentation claims.

Environment variables can be passed to the dependency.

    dependency:
      name: shell
      command: path/to/command --flag1 subcommand --flag2
      env:
        FOO: bar

I suspect this has been broken since #3958

I tried the fix proposed in #4047, but it did not fully resolve the issue. It populates the environment variable in the shell; however, it doesn't make the environment variable available in the command section itself. That is, it made the environment variable accessible via $(env), but referencing it with ${MY_ENV_VAR} yields no results.

Reproducing example

---
dependency:
  name: shell
  command: "echo ${TEST_ENV_VAR} > /tmp/test.txt"
  env:
    TEST_ENV_VAR: hello
---
dependency:
  name: shell
  command: "echo $$(env) > /tmp/test.txt"
  env:
    TEST_ENV_VAR: hello