Example #1
0
    def create_instances(self):
        '''Run ansible-playbook for instances creation'''
        cmd = [
            playbook_exec,
            '-i',
            self.localcfg,
            '-e',
            'ansible_connection=local',
            self.playbook,
        ]
        if self.options['ansible_opts']:
            cmd = cmd + self.options['ansible_opts']
        if not self.options['assume_yes']:
            count = 0
            for role in ['masters', 'nodes', 'etcds']:
                if '%s_count' % role in list(self.options.keys()):
                    count = count + self.options['%s_count' % role]
            if self.options['add_node']:
                display.warning(
                    '%s node(s) will be added to the current inventory %s' %
                    (count, self.inventorycfg))
            if not query_yes_no('Create %s instances on %s ?' %
                                (count, self.cloud)):
                display.display('Aborted', color='red')
                sys.exit(1)

        display.display(" ".join(cmd))
        rcode, emsg = run_command('Create %s instances' % self.cloud, cmd)
        if rcode != 0:
            self.logger.critical('Cannot create instances: %s' % emsg)
            sys.exit(1)
Example #2
0
 def create_instances(self):
     '''Run ansible-playbook for instances creation'''
     cmd = [
         playbook_exec, '-i', self.localcfg, '-e',
         'ansible_connection=local', self.playbook
     ]
     if not self.options['assume_yes']:
         count = 0
         for role in ['masters', 'nodes', 'etcds']:
             if '%s_count' % role in self.options.keys():
                 count = count + self.options['%s_count' % role]
         if self.options['add_node']:
             display.warning(
                 '%s node(s) will be added to the current inventory %s' %
                 (count, self.inventorycfg)
             )
         if not query_yes_no('Create %s instances on %s ?' % (count, self.cloud)):
             display.display('Aborted', color='red')
             sys.exit(1)
     rcode, emsg = run_command('Create %s instances' % self.cloud, cmd)
     if rcode != 0:
         self.logger.critical('Cannot create instances: %s' % emsg)
         sys.exit(1)
Example #3
0
    def deploy_kubernetes(self):
        '''
        Run the ansible playbook command
        '''
        cmd = [
            playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
            '-u',
            '%s' % self.options['ansible_user'], '-b', '--become-user=root',
            '-i', self.inventorycfg,
            os.path.join(self.options['kubespray_path'], 'cluster.yml')
        ]
        # Configure network plugin if defined
        if 'network_plugin' in list(self.options.keys()):
            cmd = cmd + [
                '-e',
                'kube_network_plugin=%s' % self.options['network_plugin']
            ]
        # Configure the network subnets pods and k8s services
        if 'kube_network' in list(self.options.keys()):
            if not validate_cidr(self.options['kube_network'], version=4):
                display.error('Invalid Kubernetes network address')
                self.kill_ssh_agent()
                sys.exit(1)
            svc_network, pods_network = self.get_subnets()
            cmd = cmd + [
                '-e',
                'kube_service_addresses=%s' % svc_network.cidr, '-e',
                'kube_pods_subnet=%s' % pods_network
            ]
        # Check optional apps
        if 'apps_enabled' in list(self.options.keys()):
            for app in self.options['apps_enabled']:
                if app not in ['helm', 'netchecker', 'efk']:
                    display.error(
                        'The application %s is not available, possible values = %s'
                        % (app, ','.join(self.options['apps_enabled'])))
                    sys.exit(1)
                if app == "netchecker":
                    cmd = cmd + ['-e', 'deploy_netchecker=true']
                else:
                    cmd = cmd + ['-e', '%s_enabled=true' % app]
        # Set kubernetes version
        if 'kube_version' in list(self.options.keys()):
            available_kube_versions = self.read_kube_versions()
            if self.options['kube_version'] not in available_kube_versions:
                display.error(
                    'Kubernetes version %s is not supported, available versions = %s'
                    % (self.options['kube_version'],
                       ','.join(available_kube_versions)))
                sys.exit(1)
            cmd = cmd + [
                '-e', 'kube_version=%s' % self.options['kube_version']
            ]
        # Bootstrap
        if 'coreos' in list(self.options.keys()) and self.options['coreos']:
            cmd = cmd + ['-e', 'bootstrap_os=coreos']
        elif 'redhat' in list(self.options.keys()) and self.options['redhat']:
            cmd = cmd + [
                '-e', 'bootstrap_os=centos', '-e', 'ansible_os_family=RedHat'
            ]
        elif 'ubuntu' in list(self.options.keys()) and self.options['ubuntu']:
            cmd = cmd + ['-e', 'bootstrap_os=ubuntu']
        # Add root password for the apiserver
        if 'k8s_passwd' in list(self.options.keys()):
            cmd = cmd + ['-e', 'kube_api_pwd=%s' % self.options['k8s_passwd']]
        # Ansible verbose mode
        if 'verbose' in list(self.options.keys()) and self.options['verbose']:
            cmd = cmd + ['-vvvv']
        # Add privilege escalation password
        if self.options['ask_become_pass']:
            cmd = cmd + ['--ask-become-pass']
        # Add any additionnal Ansible option
        cmd = cmd + self.options.get('ansible_opts', [])

        for cloud in ['aws', 'gce']:
            if self.options[cloud]:
                cmd = cmd + ['-e', 'cloud_provider=%s' % cloud]
        self.check_ping()
        if 'kube_network' in list(self.options.keys()):
            display.display('Kubernetes services network : %s (%s IPs)' %
                            (svc_network.cidr, str(svc_network.size.real - 2)),
                            color='bright gray')
            display.display(
                'Pods network : %s (%s IPs)' %
                (pods_network.cidr, str(pods_network.size.real - 2)),
                color='bright gray')
        display.display(' '.join(cmd), color='bright blue')
        if not self.options['assume_yes']:
            if not query_yes_no(
                    'Run kubernetes cluster deployment with the above command ?'
            ):
                display.display('Aborted', color='red')
                sys.exit(1)
        display.banner('RUN PLAYBOOK')
        self.logger.info('Running kubernetes deployment with the command: %s' %
                         ' '.join(cmd))
        rcode, emsg = run_command('Run deployment', cmd)
        if rcode != 0:
            self.logger.critical('Deployment failed: %s' % emsg)
            self.kill_ssh_agent()
            sys.exit(1)
        display.display('Kubernetes deployed successfuly', color='green')
        self.kill_ssh_agent()
Example #4
0
 def deploy_kubernetes(self):
     '''
     Run the ansible playbook command
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-u',  '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-i', self.inventorycfg,
         os.path.join(self.options['kubespray_path'], 'cluster.yml')
     ]
     # Configure network plugin if defined
     if 'network_plugin' in self.options.keys():
         cmd = cmd + ['-e',
             'kube_network_plugin=%s' % self.options['network_plugin']
             ]
     # Configure the network subnets pods and k8s services
     if 'kube_network' in self.options.keys():
         if not validate_cidr(self.options['kube_network'], version=4):
             display.error('Invalid Kubernetes network address')
             self.kill_ssh_agent()
             sys.exit(1)
         svc_network, pods_network = self.get_subnets()
         cmd = cmd + [
             '-e', 'kube_service_addresses=%s' % svc_network.cidr,
             '-e', 'kube_pods_subnet=%s' % pods_network
         ]
     # Check optional apps
     if 'apps_enabled' in self.options.keys():
         for app in self.options['apps_enabled']:
             if app not in ['helm', 'netchecker', 'efk']:
                 display.error(
                     'The application %s is not available, possible values = %s' %
                     (app, ','.join(self.options['apps_enabled']))
                 )
                 sys.exit(1)
             if app == "netchecker":
                 cmd = cmd + ['-e', 'deploy_netchecker=true']
             else:
                 cmd = cmd + ['-e', '%s_enabled=true' % app]
     # Set kubernetes version
     if 'kube_version' in self.options.keys():
         available_kube_versions = self.read_kube_versions()
         if self.options['kube_version'] not in available_kube_versions:
             display.error(
                 'Kubernetes version %s is not supported, available versions = %s' %
                 (self.options['kube_version'], ','.join(available_kube_versions))
             )
             sys.exit(1)
         cmd = cmd + ['-e', 'kube_version=%s' % self.options['kube_version']]
     # Bootstrap
     if 'coreos' in self.options.keys() and self.options['coreos']:
         cmd = cmd + ['-e', 'bootstrap_os=coreos']
     elif 'redhat' in self.options.keys() and self.options['redhat']:
         cmd = cmd + [
             '-e', 'bootstrap_os=centos', '-e', 'ansible_os_family=RedHat'
         ]
     elif 'ubuntu' in self.options.keys() and self.options['ubuntu']:
         cmd = cmd + ['-e', 'bootstrap_os=ubuntu']
     # Add root password for the apiserver
     if 'k8s_passwd' in self.options.keys():
         cmd = cmd + ['-e', 'kube_api_pwd=%s' % self.options['k8s_passwd']]
     # Ansible verbose mode
     if 'verbose' in self.options.keys() and self.options['verbose']:
         cmd = cmd + ['-vvvv']
     # Add privilege escalation password
     if self.options['ask_become_pass']:
         cmd = cmd + ['--ask-become-pass']
     # Add any additionnal Ansible option
     if 'ansible_opts' in self.options.keys():
         cmd = cmd + self.options['ansible_opts'].split(' ')
     for cloud in ['aws', 'gce']:
         if self.options[cloud]:
             cmd = cmd + ['-e', 'cloud_provider=%s' % cloud]
     self.check_ping()
     if 'kube_network' in self.options.keys():
         display.display(
             'Kubernetes services network : %s (%s IPs)'
             % (svc_network.cidr, str(svc_network.size.real - 2)),
             color='bright gray'
         )
         display.display(
             'Pods network : %s (%s IPs)'
             % (pods_network.cidr, str(pods_network.size.real - 2)),
             color='bright gray'
         )
     display.display(' '.join(cmd), color='bright blue')
     if not self.options['assume_yes']:
         if not query_yes_no(
             'Run kubernetes cluster deployment with the above command ?'
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     display.banner('RUN PLAYBOOK')
     self.logger.info(
         'Running kubernetes deployment with the command: %s' % ' '.join(cmd)
     )
     rcode, emsg = run_command('Run deployment', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         self.kill_ssh_agent()
         sys.exit(1)
     display.display('Kubernetes deployed successfuly', color='green')
     self.kill_ssh_agent()