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

[Question] How to disable env/passwords to be created #809

Closed
FloLaco opened this issue Aug 31, 2021 · 2 comments · Fixed by #899
Closed

[Question] How to disable env/passwords to be created #809

FloLaco opened this issue Aug 31, 2021 · 2 comments · Fixed by #899

Comments

@FloLaco
Copy link

FloLaco commented Aug 31, 2021

Hi,

I run ansible-runner by providing password with a dict. It run with success. If I re-run the script. It's not working anymore.
The issue is, when I run the first time the script, ansible-runner create a the file env/passwords with the content of what I provided with my dict.
If I remove manually this folder, my script is working, but again, it re create the file ...

How to disable the creation of this sensitive file ?

import ansible_runner
passwords = {"SSH password:": "MYPASSWORD"}
r = ansible_runner.run(private_data_dir='/home/florian/ansible-runner-test', playbook='get_facts.yaml', inventory="myhosts", passwords=passwords)
print("{}: {}".format(r.status, r.rc))
# successful: 0
for each_host_event in r.events:
    print(each_host_event['event'])
print("Final status:")
print(r.stats)

Here's the error on my second run :

(ansible-runner) florian@dsrauto-dev1:~/ansible-runner-test$ python main.py
Traceback (most recent call last):
  File "main.py", line 6, in <module>
    r = ansible_runner.run(private_data_dir='/home/florian/ansible-runner-test', playbook='get_facts.yaml', inventory="myhosts", passwords=passwords)
  File "/home/florian/.pyenv/versions/ansible-runner/lib/python3.8/site-packages/ansible_runner/interface.py", line 254, in run
    r = init_runner(**kwargs)
  File "/home/florian/.pyenv/versions/ansible-runner/lib/python3.8/site-packages/ansible_runner/interface.py", line 119, in init_runner
    rc.prepare()
  File "/home/florian/.pyenv/versions/ansible-runner/lib/python3.8/site-packages/ansible_runner/config/runner.py", line 144, in prepare
    self.prepare_env()
  File "/home/florian/.pyenv/versions/ansible-runner/lib/python3.8/site-packages/ansible_runner/config/runner.py", line 182, in prepare_env
    super(RunnerConfig, self)._prepare_env()
  File "/home/florian/.pyenv/versions/ansible-runner/lib/python3.8/site-packages/ansible_runner/config/_base.py", line 158, in _prepare_env
    for pattern, password in iteritems(self.passwords)
  File "/home/florian/.pyenv/versions/ansible-runner/lib/python3.8/site-packages/six.py", line 605, in iteritems
    return iter(d.items(**kw))
AttributeError: 'NoneType' object has no attribute 'items'
@FloLaco
Copy link
Author

FloLaco commented Sep 6, 2021

Oh, I found a bug

self.passwords = self.passwords.update(self.loader.load_file('env/passwords', Mapping))

dict.update() return None, so you can't assign self.passwords.update() to self.passwords

@FloLaco
Copy link
Author

FloLaco commented Sep 13, 2021

I found the same bug : #493

@samdoran samdoran added the needs_triage New item that needs to be triaged label Nov 1, 2021
@samdoran samdoran removed the needs_triage New item that needs to be triaged label Nov 2, 2021
ansible-zuul bot added a commit that referenced this issue Nov 3, 2021
Fix settings and password dict update

The update method on dict returns None, so we can not use the return value to set the variable as this will just delete the dictionary.
Let me know if I missunderstand something, but this did not work for me before the change.
How to reproduce:
use
ansible_runner.run(..., passwords={'expr': 'password'}) command with a dict as argument to passwords
Fixes #809

Reviewed-by: David Shrewsbury <None>
Reviewed-by: None <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants