(self, files=None)
Directly loads JSON to inventory.
Directly loads JSON to inventory.
Directly loads JSON to inventory .
def load_file(self, files=None):
        '''Directly loads JSON to inventory.'''

        if not files:
            raise Exception("No input file specified.")

        import json

        for filename in list(files):
            # Try JSON
            try:
                with open(filename, 'r') as f:
                    data = json.load(f)
            except ValueError:
                raise Exception("Cannot read %s as JSON, or CSV", filename)

            self.ensure_required_groups(ROLES)
            self.set_k8s_cluster()
            for group, hosts in data.items():
                self.ensure_required_groups([group])
                for host, opts in hosts.items():
                    optstring = {'ansible_host': opts['ip'],
                                 'ip': opts['ip'],
                                 'access_ip': opts['ip']}
                    self.add_host_to_group('all', host, optstring)
                    self.add_host_to_group(group, host)
            self.write_config(self.config_file)
def load_file ( self , files = None ) : if not files : raise Exception ( "No input file specified." ) import json for filename in list ( files ) : # Try JSON try : with open ( filename , 'r' ) as f : data = json . load ( f ) except ValueError : raise Exception ( "Cannot read %s as JSON, or CSV" , filename ) self . ensure_required_groups ( ROLES ) self . set_k8s_cluster ( ) for group , hosts in data . items ( ) : self . ensure_required_groups ( [ group ] ) for host , opts in hosts . items ( ) : optstring = { 'ansible_host' : opts [ 'ip' ] , 'ip' : opts [ 'ip' ] , 'access_ip' : opts [ 'ip' ] } self . add_host_to_group ( 'all' , host , optstring ) self . add_host_to_group ( group , host ) self . write_config ( self . config_file )