=======================================================================================
main.py
=======================================================================================
from first import *
from variables import *
import subprocess
print("pass from main:", Vars.password)
subprocess.Popen("ansible-playbook -i localhost ansible_playbook.yml", shell=True)
.
=======================================================================================
first.py
=======================================================================================
from variables import *
import getpass
pass_ = getpass.getpass("Enter password:")
Vars.password= pass_
=======================================================================================
ansible_playbook.yml
=======================================================================================
---
- hosts: localhost
vars:
pass_ : "abcd"
tasks:
- debug: var=pass_
=======================================================================================
variables.py
=======================================================================================
class Vars():
password = None
When we run main.py, password is entered by user and that gets stored in variables.py as a part of main.py and if we run the ansible playbook in the main.py same class variable password need to be accessed in a ansible script without passing as command line argument or storing in a file or vault file, how can we do this?
You can't use playbook prompts ?
Otherwise for executing ansible playbooks from python, have a look at the python api ( PlaybookExecutor ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.