2

I know well about passenv and setenv use on tox.ini files but I am facing a case where I want to undefine some variables so they are not included in the wildcard passenv.

Example

[testenv]
passenv = ANSIBLE_*

# I how do I assure that ANSIBLE_INVENTORY is not passed?

2 Answers 2

1

To quote the docs:

tox will take care of environment isolation for you: it will strip away all operating system environment variables not specified via passenv.

That is, you just do not mention the variables you don't want passed.

For passenv, docs say:

You can override these variables with the setenv option.

Since a shell variable which is unset looks like an empty string, you can try to setenv to '' all the variables you don't want to pass. It may or may not work, depending on how these variables are used by the code, because there is a difference between an empty env variable and an unset one.

I don't see any way to selectively unset variables in the tox docs. I would suggest to use a few wildcards weaker than ANSIBLE_* so that they don't let in the variables you want to stay unset.

Another solution would be to unset the variables in the shell that runs tox, so that the tox process was unable to access and pass them:

#!/bin/sh
unset ANSIBLE_KEYS_TO_KINGDOM
tox "$@"
Sign up to request clarification or add additional context in comments.

2 Comments

Setting a variable to empty string is not the same as unsetting it. I know a huge number of cases where the tools using these will misbehave on empty vars.
@sorin: Exactly! This is detailed in the answer. Not all programs discern this (e.g. most shell scripts and Python scripts don't), but some do. The unset variant is the correct general solution.
1

So far it seems impossible to perform an unset like this, so I raised it as a feature request at https://github.com/tox-dev/tox/issues/1387

There is an workaround but it is so inconvenient that I do not even know if it worth mentioning:

command = bash -c "unset ANSIBLE_INVENTORY; <original command>"

As you can see, this approach does not scale at all and can make maintenance of tox.ini a real burden.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.