def _validate_output_file_exists(self, output_file, log): _dir = os.path.dirname(output_file) if _dir != '' and not os.path.exists(_dir): log.warn("Path '%s' does not exist. Creating the directory.", _dir) os.makedirs(_dir) if os.path.isfile(output_file): valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} ans = input("%s%sThe output file '%s' already exists. " "Would you like to override it (y,n)?%s " % (WARN, PREFIX, output_file, END)) while True: ans = ans.lower() if ans in valid: if valid[ans]: break msg = "Failed to create output file. " \ "File could not be overridden." log.error(msg) print("%s%s%s%s" % (FAIL, PREFIX, msg, END)) sys.exit(0) ans = input("%s%sPlease respond with 'yes' or 'no': %s" % (INPUT, PREFIX, END)) try: os.remove(output_file) except OSError: log.error("File %s could not be replaced.", output_file) print("%s%sFile %s could not be replaced.%s" % (FAIL, PREFIX, output_file, END)) sys.exit(0)
def run(self, conf_file): print("%s%sValidate variable mapping file " "for oVirt ansible disaster recovery%s" % (INFO, PREFIX, END)) self._set_dr_conf_variables(conf_file) print("%s%sVar File: '%s'%s" % (INFO, PREFIX, self.var_file, END)) while not os.path.isfile(self.var_file): self.var_file = input( "%s%sVar file '%s' does not exists. " "Please provide the location of the var file:%s " % (FAIL, PREFIX, self.var_file, END)) python_vars = self._read_var_file() self.primary_pwd = input( "%s%sPlease provide password for the primary setup: %s" % (INPUT, PREFIX, END)) self.second_pwd = input( "%s%sPlease provide password for the secondary setup: %s" % (INPUT, PREFIX, END)) if (not self._validate_lists_in_mapping_file(python_vars) or not self._validate_duplicate_keys(python_vars) or not self._entity_validator(python_vars) or not self._validate_failback_leftovers()): self._print_finish_error() sys.exit() if not self._validate_hosted_engine(python_vars): self._print_finish_error() sys.exit() if not self._validate_export_domain(python_vars): self._print_finish_error() sys.exit() self._print_finish_success()
def _set_dr_conf_variables(self, conf_file): _SECTION = 'validate_vars' _VAR_FILE = 'var_file' # Get default location of the yml var file. settings = ConfigParser() settings.read(conf_file) if _SECTION not in settings.sections(): settings.add_section(_SECTION) if not settings.has_option(_SECTION, _VAR_FILE): settings.set(_SECTION, _VAR_FILE, '') var_file = settings.get(_SECTION, _VAR_FILE, vars=DefaultOption(settings, _SECTION, site=self.def_var_file)) var_file = os.path.expanduser(var_file) while not os.path.isfile(var_file): var_file = input("%s%sVar file '%s' does not exist. Please " "provide the location of the var file (%s): %s" % (WARN, PREFIX, var_file, self.def_var_file, END)) or self.def_var_file var_file = os.path.expanduser(var_file) self.var_file = var_file self.primary_pwd = input( "%s%sPlease provide password for the primary setup: %s" % (INPUT, PREFIX, END)) self.second_pwd = input( "%s%sPlease provide password for the secondary setup: %s" % (INPUT, PREFIX, END))
def prompt_and_delete(item, prompt, assumeyes): if not assumeyes: assumeyes = input(prompt).lower() == 'y' assert hasattr(item, 'destroy'), "Class <%s> has no delete attribute" % item.__class__ if assumeyes: item.destroy() print("Deleted %s" % item)
def missing_host_key(self, session, hostname, username, key_type, fingerprint, message): if all(( self._options["host_key_checking"], not self._options["host_key_auto_add"], )): if (self.connection.get_option("use_persistent_connections") or self.connection.force_persistence): # don't print the prompt string since the user cannot respond # to the question anyway raise AnsibleError( AUTHENTICITY_MSG.rsplit("\n", 2)[0] % (hostname, message, key_type, fingerprint)) self.connection.connection_lock() old_stdin = sys.stdin sys.stdin = self._new_stdin # clear out any premature input on sys.stdin tcflush(sys.stdin, TCIFLUSH) inp = input(AUTHENTICITY_MSG % (hostname, message, key_type, fingerprint)) sys.stdin = old_stdin self.connection.connection_unlock() if inp not in ["yes", "y", ""]: raise AnsibleError("host connection rejected by user") session.hostkey_auto_add(username)
def _validate_failback_leftovers(self): valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} with open(self.default_main_file, 'r') as stream: try: info_dict = yaml.safe_load(stream) running_vms_file = info_dict.get(self.running_vms) if os.path.isfile(running_vms_file): ans = input( "%s%sFile with running vms info already exists from " "previous failback operation. Do you want to " "delete it(yes,no)?: %s" % (WARN, PREFIX, END)) ans = ans.lower() if ans in valid and valid[ans]: os.remove(running_vms_file) print("%s%sFile '%s' has been deleted successfully%s" % (INFO, PREFIX, running_vms_file, END)) else: print("%s%sFile '%s' has not been deleted." " It will be used in the next failback" " operation%s" % (INFO, PREFIX, running_vms_file, END)) except yaml.YAMLError as exc: print("%s%syaml file '%s' could not be loaded%s" % (FAIL, PREFIX, self.default_main_file, END)) print(exc) return False except OSError as ex: print("%s%sFail to validate failback running vms file '%s'%s" % (FAIL, PREFIX, self.default_main_file, END)) print(ex) return False return True
def missing_host_key(self, client, hostname, key): if all((C.HOST_KEY_CHECKING, not C.PARAMIKO_HOST_KEY_AUTO_ADD)): if C.USE_PERSISTENT_CONNECTIONS: raise AnsibleConnectionFailure('rejected %s host key for host %s: %s' % (key.get_name(), hostname, hexlify(key.get_fingerprint()))) self.connection.connection_lock() old_stdin = sys.stdin sys.stdin = self._new_stdin # clear out any premature input on sys.stdin tcflush(sys.stdin, TCIFLUSH) fingerprint = hexlify(key.get_fingerprint()) ktype = key.get_name() inp = input(AUTHENTICITY_MSG % (hostname, ktype, fingerprint)) sys.stdin = old_stdin self.connection.connection_unlock() if inp not in ['yes', 'y', '']: raise AnsibleError("host connection rejected by user") key._added_by_ansible_this_time = True # existing implementation below: client._host_keys.add(hostname, key.get_name(), key)
def missing_host_key(self, client, hostname, key): if all((C.HOST_KEY_CHECKING, not C.PARAMIKO_HOST_KEY_AUTO_ADD)): if C.USE_PERSISTENT_CONNECTIONS: raise AnsibleConnectionFailure( 'rejected %s host key for host %s: %s' % (key.get_name(), hostname, hexlify(key.get_fingerprint()))) self.connection.connection_lock() old_stdin = sys.stdin sys.stdin = self._new_stdin # clear out any premature input on sys.stdin tcflush(sys.stdin, TCIFLUSH) fingerprint = hexlify(key.get_fingerprint()) ktype = key.get_name() inp = input(AUTHENTICITY_MSG % (hostname, ktype, fingerprint)) sys.stdin = old_stdin self.connection.connection_unlock() if inp not in ['yes', 'y', '']: raise AnsibleError("host connection rejected by user") key._added_by_ansible_this_time = True # existing implementation below: client._host_keys.add(hostname, key.get_name(), key)
def delete_autoscaling_group(get_func, attr, opts): assumeyes = opts.assumeyes group_name = None for item in get_func(): group_name = getattr(item, attr) if re.search(opts.match_re, group_name): if not opts.assumeyes: assumeyes = input("Delete matching %s? [y/n]: " % (item).lower()) == 'y' break if assumeyes and group_name: groups = asg.get_all_groups(names=[group_name]) if groups: group = groups[0] group.max_size = 0 group.min_size = 0 group.desired_capacity = 0 group.update() instances = True while instances: tmp_groups = asg.get_all_groups(names=[group_name]) if tmp_groups: tmp_group = tmp_groups[0] if not tmp_group.instances: instances = False time.sleep(10) group.delete() while len(asg.get_all_groups(names=[group_name])): time.sleep(5) print("Terminated ASG: %s" % group_name)
def get_credentials(self): display.display(u'\n\n' + "We need your " + stringc("Github login", 'bright cyan') + " to identify you.", screen_only=True) display.display("This information will " + stringc("not be sent to Galaxy", 'bright cyan') + ", only to " + stringc("api.github.com.", "yellow"), screen_only=True) display.display("The password will not be displayed." + u'\n\n', screen_only=True) display.display("Use " + stringc("--github-token", 'yellow') + " if you do not want to enter your password." + u'\n\n', screen_only=True) try: self.github_username = input("Github Username: "******"Password for %s: " % self.github_username) except: pass if not self.github_username or not self.github_password: raise AnsibleError( "Invalid Github credentials. Username and password are required." )
def _set_dr_conf_variables(self, conf_file): _SECTION = 'validate_vars' _VAR_FILE = 'var_file' # Get default location of the yml var file. settings = ConfigParser() settings.read(conf_file) if _SECTION not in settings.sections(): settings.add_section(_SECTION) if not settings.has_option(_SECTION, _VAR_FILE): settings.set(_SECTION, _VAR_FILE, '') var_file = settings.get(_SECTION, _VAR_FILE, vars=DefaultOption(settings, _SECTION, site=self.def_var_file)) # If no default location exists, get the location from the user. while not var_file: var_file = input( "%s%sVar file is not initialized. Please provide " "the location of the var file (%s):%s " % (WARN, PREFIX, self.def_var_file, END)) or self.def_var_file self.var_file = var_file
def missing_host_key(self, client, hostname, key): if all((self._options['host_key_checking'], not self._options['host_key_auto_add'])): fingerprint = hexlify(key.get_fingerprint()) ktype = key.get_name() if C.USE_PERSISTENT_CONNECTIONS or self.connection.force_persistence: # don't print the prompt string since the user cannot respond # to the question anyway raise AnsibleError(AUTHENTICITY_MSG[1:92] % (hostname, ktype, fingerprint)) self.connection.connection_lock() old_stdin = sys.stdin sys.stdin = self._new_stdin # clear out any premature input on sys.stdin tcflush(sys.stdin, TCIFLUSH) inp = input(AUTHENTICITY_MSG % (hostname, ktype, fingerprint)) sys.stdin = old_stdin self.connection.connection_unlock() if inp not in ['yes', 'y', '']: raise AnsibleError("host connection rejected by user") key._added_by_ansible_this_time = True # existing implementation below: client._host_keys.add(hostname, key.get_name(), key)
def prompt_and_delete(item, prompt, assumeyes): if not assumeyes: assumeyes = input(prompt).lower() == 'y' assert hasattr(item, 'delete') or hasattr(item, 'terminate'), "Class <%s> has no delete or terminate attribute" % item.__class__ if assumeyes: if hasattr(item, 'delete'): item.delete() print("Deleted %s" % item) if hasattr(item, 'terminate'): item.terminate() print("Terminated %s" % item)
def prompt_and_delete(item, prompt, assumeyes): if not assumeyes: assumeyes = input(prompt).lower() == 'y' assert hasattr(item, 'delete') or hasattr(item, 'terminate'), \ "Class <%s> has no delete or terminate attribute" % item.__class__ if assumeyes: if hasattr(item, 'delete'): item.delete() print("Deleted %s" % item) if hasattr(item, 'terminate'): item.terminate() print("Terminated %s" % item)
def update_check(): """ checking whenever upgrade is required. """ message = "\tDell EMC OpenManage Ansible Modules is already present." \ " Do you want to upgrade? (y/n)?" yes = {'y', '', 'Y'} print(message) print("\tPress `y` to update the Dell EMC OpenManage Ansible Modules" " specific folders and files...") choice = input("\tPress any other key to exit installation " "(default: 'y'):") return choice in yes
def run(self, conf_file, log_file, log_level): log = self._set_log(log_file, log_level) log.info("Start failover operation...") target_host, source_map, var_file, vault, ansible_play = \ self._init_vars(conf_file) report = report_name.format(int(round(time.time() * 1000))) log.info("\ntarget_host: %s \n" "source_map: %s \n" "var_file: %s \n" "vault: %s \n" "ansible_play: %s \n" "report log file: /tmp/%s\n", target_host, source_map, var_file, vault, ansible_play, report) dr_tag = "fail_over" extra_vars = (" dr_target_host=" + target_host + " dr_source_map=" + source_map + " dr_report_file=" + report) command = [ "ansible-playbook", ansible_play, "-t", dr_tag, "-e", "@" + var_file, "-e", "@" + vault, "-e", extra_vars, "--vault-password-file", "vault_secret.sh", "-vvv" ] # Setting vault password. vault_pass_msg = ("Please enter vault password " "(in case of plain text please press ENTER): ") vault_pass = input(INPUT + PREFIX + vault_pass_msg + END) os.system("export vault_password=\"" + vault_pass + "\"") log.info("Executing failover command: %s", ' '.join(map(str, command))) if log_file is not None and log_file != '': self._log_to_file(log_file, command) else: self._log_to_console(command, log) call(["cat", "/tmp/" + report]) print("\n%s%sFinished failover operation" " for oVirt ansible disaster recovery%s" % (INFO, PREFIX, END))
def update_check(): """ checking whenever upgrade is required. """ message = "Dell EMC OpenManage Ansible Modules is already present. Do you want to upgrade? (y/n) " yes = {'y', ''} print(" ") print(message) print( "Press `y` to update the Dell EMC OpenManage Ansible Modules specific folders and files..." ) print("Press any other key to exit installation (default: 'y'):") choice = input() if choice in yes: return True else: return False
def get_credentials(self): display.display(u'\n\n' + "We need your " + stringc("Github login", 'bright cyan') + " to identify you.", screen_only=True) display.display("This information will " + stringc("not be sent to Galaxy", 'bright cyan') + ", only to " + stringc("api.github.com.", "yellow"), screen_only=True) display.display("The password will not be displayed." + u'\n\n', screen_only=True) display.display("Use " + stringc("--github-token", 'yellow') + " if you do not want to enter your password." + u'\n\n', screen_only=True) try: self.github_username = input("Github Username: "******"Password for %s: " % self.github_username) except: pass if not self.github_username or not self.github_password: raise AnsibleError("Invalid Github credentials. Username and password are required.")
def _init_vars(self, conf_file): """ Declare constants """ _SECTION = "failover_failback" _TARGET = "dr_target_host" _SOURCE = "dr_source_map" _VAULT = "vault" _VAR_FILE = "var_file" _ANSIBLE_PLAY = 'ansible_play' setups = ['primary', 'secondary'] settings = ConfigParser() settings.read(conf_file) if _SECTION not in settings.sections(): settings.add_section(_SECTION) if not settings.has_option(_SECTION, _TARGET): settings.set(_SECTION, _TARGET, '') if not settings.has_option(_SECTION, _SOURCE): settings.set(_SECTION, _SOURCE, '') if not settings.has_option(_SECTION, _VAULT): settings.set(_SECTION, _VAULT, '') if not settings.has_option(_SECTION, _VAR_FILE): settings.set(_SECTION, _VAR_FILE, '') if not settings.has_option(_SECTION, _ANSIBLE_PLAY): settings.set(_SECTION, _ANSIBLE_PLAY, '') # We fetch the source map as target host, # since in failback we do the reverse operation. target_host = settings.get(_SECTION, _SOURCE, vars=DefaultOption(settings, _SECTION, source_map=None)) # We fetch the target host as target the source mapping for failback, # since we do the reverse operation. source_map = settings.get(_SECTION, _TARGET, vars=DefaultOption(settings, _SECTION, target_host=None)) vault_file = settings.get(_SECTION, _VAULT, vars=DefaultOption(settings, _SECTION, vault=None)) vault_file = os.path.expanduser(vault_file) var_file = settings.get(_SECTION, _VAR_FILE, vars=DefaultOption(settings, _SECTION, var_file=None)) var_file = os.path.expanduser(var_file) ansible_play_file = settings.get(_SECTION, _ANSIBLE_PLAY, vars=DefaultOption(settings, _SECTION, ansible_play=None)) ansible_play_file = os.path.expanduser(ansible_play_file) while target_host not in setups: target_host = input("%s%sThe target host '%s' was not defined. " "Please provide the target host " "to failback to (primary or secondary): %s" % (INPUT, PREFIX, target_host, END)) while source_map not in setups: source_map = input("%s%sThe source mapping '%s' was not defined. " "Please provide the source mapping " "(primary or secondary): %s" % (INPUT, PREFIX, source_map, END)) while not os.path.isfile(var_file): var_file = input( "%s%sVar file '%s' does not exist. Please " "provide the location of the var file (%s): %s" % (INPUT, PREFIX, var_file, VAR_FILE_DEF, END)) or VAR_FILE_DEF var_file = os.path.expanduser(var_file) while not os.path.isfile(vault_file): vault_file = input("%s%sPassword file '%s' does not exist. " "Please provide a valid password file: %s" % (INPUT, PREFIX, vault_file, END)) vault_file = os.path.expanduser(vault_file) while not os.path.isfile(ansible_play_file): ansible_play_file = input( "%s%sAnsible play file '%s' does not " "exist. Please provide the ansible play " "file to run the failback flow (%s): %s" % (INPUT, PREFIX, ansible_play_file, PLAY_DEF, END)) or PLAY_DEF ansible_play_file = os.path.expanduser(ansible_play_file) return target_host, source_map, var_file, vault_file, ansible_play_file
def _init_vars(self, conf_file): """ Declare constants """ _SECTION = "failover_failback" _TARGET = "dr_target_host" _SOURCE = "dr_source_map" _VAULT = "vault" _VAR_FILE = "var_file" _ANSIBLE_PLAY = 'ansible_play' setups = ['primary', 'secondary'] settings = ConfigParser() settings.read(conf_file) if _SECTION not in settings.sections(): settings.add_section(_SECTION) if not settings.has_option(_SECTION, _TARGET): settings.set(_SECTION, _TARGET, '') if not settings.has_option(_SECTION, _SOURCE): settings.set(_SECTION, _SOURCE, '') if not settings.has_option(_SECTION, _VAULT): settings.set(_SECTION, _VAULT, '') if not settings.has_option(_SECTION, _VAR_FILE): settings.set(_SECTION, _VAR_FILE, '') if not settings.has_option(_SECTION, _ANSIBLE_PLAY): settings.set(_SECTION, _ANSIBLE_PLAY, '') target_host = settings.get(_SECTION, _TARGET, vars=DefaultOption(settings, _SECTION, target_host=None)) source_map = settings.get(_SECTION, _SOURCE, vars=DefaultOption(settings, _SECTION, source_map=None)) vault = settings.get(_SECTION, _VAULT, vars=DefaultOption(settings, _SECTION, vault=None)) var_file = settings.get(_SECTION, _VAR_FILE, vars=DefaultOption(settings, _SECTION, var_file=None)) ansible_play = settings.get(_SECTION, _ANSIBLE_PLAY, vars=DefaultOption(settings, _SECTION, ansible_play=None)) while target_host not in setups: target_host = input( INPUT + PREFIX + "The target host was not defined. " "Please provide the target host (to failover to) " "(primary or secondary): " + END) while source_map not in setups: source_map = input( INPUT + PREFIX + "The source mapping was not defined. " "Please provide the source mapping " "(primary or secondary): " + END) while not os.path.isfile(var_file): var_file = input("%s%svar file mapping '%s' does not exist. " "Please provide a valid mapping var file: %s" % (INPUT, PREFIX, var_file, END)) while not os.path.isfile(vault): vault = input("%s%sPassword file '%s' does not exist. " "Please provide a valid password file: %s" % (INPUT, PREFIX, vault, END)) while (not ansible_play) or (not os.path.isfile(ansible_play)): ansible_play = input("%s%sansible play '%s' " "is not initialized. " "Please provide the ansible play file " "to generate the mapping var file " "with ('%s'):%s " % (INPUT, PREFIX, str(ansible_play), PLAY_DEF, END) or PLAY_DEF) return target_host, source_map, var_file, vault, ansible_play
#!/usr/bin/python
try: import requests except ImportError as e: print( "You must install the python requests module. Otherwise, the iBMC cannot be connected!" ) ansible_installed_path = ansible.__path__[0] ibmc_lib_path = os.path.join(ansible_installed_path, "modules") if os.path.exists(os.path.join(ibmc_lib_path, 'ibmc')): print( "The ibmc_ansible module already exists, Do you want to upgrade it? (y/n)" ) choice = input() if choice in ['y', 'Y']: ret = subprocess.call( ["cp", "-r", "./ibmc_ansible/ibmc", ibmc_lib_path], shell=False) if ret != 0: print("Failed to copy ibmc module!") sys.exit(1) else: print("Cancel installation ibmc_ansible module!") sys.exit(1) else: ret = subprocess.call(["cp", "-r", "./ibmc_ansible/ibmc", ibmc_lib_path], shell=False) if ret != 0: print("Failed to copy ibmc_ansible/ibmc module!") sys.exit(1)
from ansible.module_utils.six.moves import input user_input = input('foo') print(user_input)
import sys from ansible.module_utils.six.moves import input prompts = sys.argv[1:] or ['foo'] for prompt in prompts: user_input = input(prompt) print(user_input)
def run(self, conf_file, log_file, log_level): log = self._set_log(log_file, log_level) log.info("Start failback operation...") target_host, source_map, var_file, vault_file, ansible_play_file = \ self._init_vars(conf_file) report = report_name.format(int(round(time.time() * 1000))) log.info( "\ntarget_host: %s \n" "source_map: %s \n" "var_file: %s \n" "vault_file: %s \n" "ansible_play_file: %s \n" "report log file: /tmp/%s\n", target_host, source_map, var_file, vault_file, ansible_play_file, report) dr_clean_tag = "clean_engine" extra_vars_cleanup = " dr_source_map=" + target_host command_cleanup = [ "ansible-playbook", ansible_play_file, "-t", dr_clean_tag, "-e", "@" + var_file, "-e", "@" + vault_file, "-e", extra_vars_cleanup, "--vault-password-file", "vault_secret.sh", "-vvv" ] dr_failback_tag = "fail_back" extra_vars_failback = (" dr_target_host=" + target_host + " dr_source_map=" + source_map + " dr_report_file=" + report) command_failback = [ "ansible-playbook", ansible_play_file, "-t", dr_failback_tag, "-e", "@" + var_file, "-e", "@" + vault_file, "-e", extra_vars_failback, "--vault-password-file", "vault_secret.sh", "-vvv" ] # Setting vault password. vault_pass = input("%s%sPlease enter vault password " "(in case of plain text please press ENTER): %s" % (INPUT, PREFIX, END)) os.system("export vault_password=\"" + vault_pass + "\"") info_msg = ("Starting cleanup process of setup '{0}' for " "oVirt ansible disaster recovery".format(target_host)) log.info(info_msg) print("\n%s%s%s%s" % (INFO, PREFIX, info_msg, END)) log.info("Executing cleanup command: %s", ' '.join(map(str, command_cleanup))) if log_file is not None and log_file != '': self._log_to_file(log_file, command_cleanup) else: self._log_to_console(command_cleanup, log) info_msg = ("Finished cleanup of setup '{0}' " "for oVirt ansible disaster recovery".format(source_map)) log.info(info_msg) print("\n%s%s%s%s" % (INFO, PREFIX, info_msg, END)) info_msg = ( "Starting failback process to setup '{0}' " "from setup '{1}' for oVirt ansible disaster recovery".format( target_host, source_map)) log.info(info_msg) print("\n%s%s%s%s" % (INFO, PREFIX, info_msg, END)) log.info("Executing failback command: %s", ' '.join(map(str, command_failback))) if log_file is not None and log_file != '': self._log_to_file(log_file, command_failback) else: self._log_to_console(command_failback, log) call(["cat", "/tmp/" + report]) print("\n%s%sFinished failback operation" " for oVirt ansible disaster recovery%s" % (INFO, PREFIX, END))
def _init_vars(self, conf_file, log): """ Declare constants """ _SECTION = 'generate_vars' _SITE = 'site' _USERNAME = '******' _PASSWORD = '******' _CA_FILE = 'ca_file' # TODO: Must have full path, should add relative path support. _OUTPUT_FILE = 'output_file' _ANSIBLE_PLAY = 'ansible_play' settings = ConfigParser() settings.read(conf_file) if _SECTION not in settings.sections(): settings.add_section(_SECTION) if not settings.has_option(_SECTION, _SITE): settings.set(_SECTION, _SITE, '') if not settings.has_option(_SECTION, _USERNAME): settings.set(_SECTION, _USERNAME, '') if not settings.has_option(_SECTION, _PASSWORD): settings.set(_SECTION, _PASSWORD, '') if not settings.has_option(_SECTION, _CA_FILE): settings.set(_SECTION, _CA_FILE, '') if not settings.has_option(_SECTION, _OUTPUT_FILE): settings.set(_SECTION, _OUTPUT_FILE, '') if not settings.has_option(_SECTION, _ANSIBLE_PLAY): settings.set(_SECTION, _ANSIBLE_PLAY, '') site = settings.get(_SECTION, _SITE, vars=DefaultOption(settings, _SECTION, site=None)) username = settings.get(_SECTION, _USERNAME, vars=DefaultOption(settings, _SECTION, username=None)) password = settings.get(_SECTION, _PASSWORD, vars=DefaultOption(settings, _SECTION, password=None)) ca_file = settings.get(_SECTION, _CA_FILE, vars=DefaultOption(settings, _SECTION, ca_file=None)) output_file = settings.get(_SECTION, _OUTPUT_FILE, vars=DefaultOption(settings, _SECTION, output_file=None)) ansible_play = settings.get(_SECTION, _ANSIBLE_PLAY, vars=DefaultOption(settings, _SECTION, ansible_play=None)) if not site: site = input("%s%sSite address is not initialized. " "Please provide the site URL (%s):%s " % (INPUT, PREFIX, SITE_DEF, END)) or SITE_DEF if not username: username = input("%s%sUsername is not initialized. " "Please provide the username (%s):%s " % (INPUT, PREFIX, USERNAME_DEF, END) ) or USERNAME_DEF while not password: password = input("%s%sPassword is not initialized. " "Please provide the password for username %s:%s " % (INPUT, PREFIX, username, END)) while not ca_file: ca_file = input("%s%sCA file is not initialized. " "Please provide the CA file location (%s):%s " % (INPUT, PREFIX, CA_DEF, END)) or CA_DEF while not output_file: output_file = input("%s%sOutput file is not initialized. " "Please provide the output file location " "for the mapping var file (%s):%s " % (INPUT, PREFIX, _OUTPUT_FILE, END) ) or _OUTPUT_FILE self._validate_output_file_exists(output_file, log) while not ansible_play or not os.path.isfile(ansible_play): ansible_play = input("%s%sAnsible play '%s' is not initialized. " "Please provide the ansible play to generate " "the mapping var file (%s):%s " % (INPUT, PREFIX, ansible_play, PLAY_DEF, END) ) or PLAY_DEF return site, username, password, ca_file, output_file, ansible_play