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

Ansible runner & 'env/' directory #493

Closed
dcasasok opened this issue Aug 14, 2020 · 9 comments
Closed

Ansible runner & 'env/' directory #493

dcasasok opened this issue Aug 14, 2020 · 9 comments
Labels

Comments

@dcasasok
Copy link

Hi, i'm trying to understand how env/ directory works in ansible runner...
First all, i'm using runner as a python module. So i run ansible_runner.interface.run_async() with parameters :
extravars: dictionary parameter
settings: dictionary parameter
envvars: dictionary parameter
When i execute my script for first time it creates the env/ path in my local directory, where each file contain all parameters data.
Altrought i execute again, those files are still existing and not overwriting.
If i run ansible runner script with debug -vvvv, i saw:
extra_vars: ('@/var/ansible-runner/project/XXX/env/extravars' , '{ "my_extra_vars" : nnnnnn }' )
where my dict {"my_extra_vars": nnnn} is a representation.
Which parameters ansible runner interface must to use?
What are the usefulness of env/ directory?

@AlanCoding
Copy link
Member

If you are using it as a python interface and pass settings (for example), then it lays down files YAML vars for what you passed in env/settings. This is a convenience thing, so that you don't have to write them to a file in order to use ansible-runner.

if obj and not os.path.exists(os.path.join(private_data_dir, 'env', key)):
path = os.path.join(private_data_dir, 'env')
dump_artifact(json.dumps(obj), path, key)

Speaking anecdotally, it does not clean up these setting files at the end of the run, and I agree it should. I have gotten an error when I provided non-empty settings but the file existed. Sounds like you got a different result, so I would like to know more specifically what your code looks like when it uses the ansible-runner python interface.

@rajasaur
Copy link

I encountered a similar result and did not expect the parameters to be persisted especially as these are passed at runtime. Like a standalone ansible-playbook, I was expecting the process to just receive the values, run the playbook and not persist any values.

In my case, I ran it with extravars, which created a env/extravars and stored the values there. I ran it a second time without passing extravars and expected an error from Ansible since there was no value passed during the run, but it was successful as it used the value from the previous run. That wasnt the behaviour with ansible-playbook.

@matburt
Copy link
Member

matburt commented Aug 31, 2020

I agree, I'd like Runner to be able to clean these up.

@AlanCoding
Copy link
Member

Behavior described in duplicate issue:

(env) [djuran@localhost ~]$ env/bin/python3 test.py
Traceback (most recent call last):
File "test.py", line 8, in
settings={})
File "/home/djuran/env/lib64/python3.6/site-packages/ansible_runner/interface.py", line 177, in run
r = init_runner(**kwargs)
File "/home/djuran/env/lib64/python3.6/site-packages/ansible_runner/interface.py", line 64, in init_runner
rc = RunnerConfig(**kwargs)
TypeError: init() got an unexpected keyword argument 'settings'

This is what I have seen as well, on the 2nd run or any other subsequent runs. Several tests are now working around this behavior.

@lleontop
Copy link

lleontop commented Jul 15, 2021

Hi, I also stumbled across this issue while passing envvars parameters to ansible-runner as a python module interface. Is there any update on this? I would expect the runner should always respect whatever envvars/extravars are/if passed from the module call even if the env/ directory exists.

Edit: With regards to envvars I think the order of updating self.env in https://github.com/ansible/ansible-runner/blob/devel/ansible_runner/config/_base.py#L204 would make sense to change and give different priority. Load the env/envvars file first and then update with whatever is passed as envvars parameter. I could probably procced with a PR if you agree!

Thanks!

@FloLaco
Copy link

FloLaco commented Sep 13, 2021

This PR should fix the issue about settings : #811

The issue about precedence between dict argment and file is here :

self.env.update(self.envvars)

and here :

self.env.update({str(k): str(v) for k, v in envvars.items()})

You should swap this two block of code.
First we import the file and update the env.
Then we update the env with the envvars provided by argument in interface

@Smixi
Copy link

Smixi commented Jun 10, 2022

I ran into this issue recently, we use a service to deploy stuff through ansible, and changing data that we pass to Ansible python interface, the env/extravars is merged. But even merging is not OK, because we use the same project with different inventory and env variable, leading to deployment having too much extravars from old execution, not only bad values, too much also.

@AlanCoding
Copy link
Member

An option to not write files in the env/ directory was added in #1000

Perhaps that can be said to resolve this issue?

@matburt matburt closed this as completed Jun 10, 2022
@Smixi
Copy link

Smixi commented Jun 10, 2022

@AlanCoding yep it will do for me :). It just felt weird that is was taking up both config (extravars in folder and through python interface), but in my use case I can never it and it will work perfectly. Thanks :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants