def _get_vars(self):
        ''' load the vars section from a play, accounting for all sorts of variable features
        including loading from yaml files, prompting, and conditional includes of the first
        file found in a list. '''

        if self.vars is None:
            self.vars = {}

        if type(self.vars) not in [dict, list]:
            raise errors.AnsibleError("'vars' section must contain only key/value pairs")

        vars = {}

        # translate a list of vars into a dict
        if type(self.vars) == list:
            for item in self.vars:
                if getattr(item, 'items', None) is None:
                    raise errors.AnsibleError("expecting a key-value pair in 'vars' section")
                k, v = item.items()[0]
                vars[k] = v
        else:
            vars.update(self.vars)

        if type(self.playbook.extra_vars) == dict:
            vars.update(self.playbook.extra_vars)

        if type(self.vars_prompt) == list:
            for var in self.vars_prompt:
                if not 'name' in var:
                    raise errors.AnsibleError("'vars_prompt' item is missing 'name:'")

                vname = var['name']
                prompt = var.get("prompt", vname)
                default = var.get("default", None)
                private = var.get("private", True)

                confirm = var.get("confirm", False)
                encrypt = var.get("encrypt", None)
                salt_size = var.get("salt_size", None)
                salt = var.get("salt", None)

                if vname not in self.playbook.extra_vars:
                    vars[vname] = self.playbook.callbacks.on_vars_prompt (
                                     vname, private, prompt, encrypt, confirm, salt_size, salt, default
                                  )

        elif type(self.vars_prompt) == dict:
            for (vname, prompt) in self.vars_prompt.iteritems():
                prompt_msg = "%s: " % prompt
                if vname not in self.playbook.extra_vars:
                    vars[vname] = self.playbook.callbacks.on_vars_prompt(
                                     varname=vname, private=False, prompt=prompt_msg, default=None
                                  )

        else:
            raise errors.AnsibleError("'vars_prompt' section is malformed, see docs")

        results = self.playbook.extra_vars.copy()
        results.update(vars)
        return results
def _get_vars ( self ) : if self . vars is None : self . vars = { } if type ( self . vars ) not in [ dict , list ] : raise errors . AnsibleError ( "'vars' section must contain only key/value pairs" ) vars = { } if type ( self . vars ) == list : for item in self . vars : if getattr ( item , 'items' , None ) is None : raise errors . AnsibleError ( "expecting a key-value pair in 'vars' section" ) k , v = item . items ( ) [ 0 ] vars [ k ] = v else : vars . update ( self . vars ) if type ( self . playbook . extra_vars ) == dict : vars . update ( self . playbook . extra_vars ) if type ( self . vars_prompt ) == list : for var in self . vars_prompt : if not 'name' in var : raise errors . AnsibleError ( "'vars_prompt' item is missing 'name:'" ) vname = var [ 'name' ] prompt = var . get ( "prompt" , vname ) default = var . get ( "default" , None ) private = var . get ( "private" , True ) confirm = var . get ( "confirm" , False ) encrypt = var . get ( "encrypt" , None ) salt_size = var . get ( "salt_size" , None ) salt = var . get ( "salt" , None ) if vname not in self . playbook . extra_vars : vars [ vname ] = self . playbook . callbacks . on_vars_prompt ( vname , private , prompt , encrypt , confirm , salt_size , salt , default ) elif type ( self . vars_prompt ) == dict : for ( vname , prompt ) in self . vars_prompt . iteritems ( ) : prompt_msg = "%s: " % prompt if vname not in self . playbook . extra_vars : vars [ vname ] = self . playbook . callbacks . on_vars_prompt ( varname = vname , private = False , prompt = prompt_msg , default = None ) else : raise errors . AnsibleError ( "'vars_prompt' section is malformed, see docs" ) results = self . playbook . extra_vars . copy ( ) results . update ( vars ) return results
load the vars section from a play, accounting for all sorts of variable features
        including loading from yaml files, prompting, and conditional includes of the first
        file found in a list.