Example #1
0
    def apply(self):
        inventory_path = get_inventory_path(
            self.cluster_model.specification.name)

        # copy resources
        self.copy_resources()

        # create inventory
        inventory_creator = AnsibleInventoryCreator(self.cluster_model,
                                                    self.config_docs)
        inventory_creator.create()
        time.sleep(10)

        # generate vars
        ansible_vars_generator = AnsibleVarsGenerator(
            inventory_creator=inventory_creator)
        ansible_vars_generator.generate()

        # pre-flight to prepare machines
        self.pre_flight(inventory_path)

        # run roles
        enabled_roles = inventory_creator.get_enabled_roles()
        for role in enabled_roles:
            self.ansible_command.run_playbook(inventory=inventory_path,
                                              playbook_path=self.playbook_path(
                                                  to_role_name(role)))

        #post-flight after we are done
        self.post_flight(inventory_path)
Example #2
0
    def assert_no_master_downscale(self):
        components = self.cluster_model.specification.components

        # Skip downscale assertion for single machine clusters
        if ('single_machine' in components) and (int(
                components['single_machine']['count']) > 0):
            return

        cluster_name = self.cluster_model.specification.name
        inventory_path = get_inventory_path(cluster_name)

        if os.path.isfile(inventory_path):
            existing_inventory = InventoryManager(loader=DataLoader(),
                                                  sources=inventory_path)

            both_present = all([
                'kubernetes_master' in existing_inventory.list_groups(),
                'kubernetes_master' in components,
            ])

            if both_present:
                prev_master_count = len(
                    existing_inventory.list_hosts(pattern='kubernetes_master'))
                next_master_count = int(
                    components['kubernetes_master']['count'])

                if prev_master_count > next_master_count:
                    raise Exception(
                        "ControlPlane downscale is not supported yet. Please revert your 'kubernetes_master' count to previous value or increase it to scale up Kubernetes."
                    )
Example #3
0
    def run(self):
        inventory_path = get_inventory_path(
            self.cluster_model.specification.name)

        # create inventory on every run
        self.inventory_creator.create()
        time.sleep(10)

        copy_files_recursively(
            AnsibleRunner.ANSIBLE_PLAYBOOKS_PATH,
            get_ansible_path(self.cluster_model.specification.name))

        # todo: install packages to run ansible on Red Hat hosts
        self.ansible_command.run_task_with_retries(
            hosts="all",
            inventory=inventory_path,
            module="raw",
            args="cat /etc/lsb-release | grep -i DISTRIB_ID | grep -i ubuntu && "
            "sudo apt-get install -y python-simplejson "
            "|| echo 'Cannot find information about Ubuntu distribution'",
            retries=5)

        self.ansible_vars_generator.run()

        common_play_result = self.ansible_command.run_playbook_with_retries(
            inventory=inventory_path,
            playbook_path=os.path.join(
                get_ansible_path(self.cluster_model.specification.name),
                "common.yml"),
            retries=5)
        if common_play_result != 0:
            return

        enabled_roles = self.inventory_creator.get_enabled_roles()

        for role in enabled_roles:
            play_result = self.ansible_command.run_playbook_with_retries(
                inventory=inventory_path,
                playbook_path=os.path.join(
                    get_ansible_path(self.cluster_model.specification.name),
                    to_role_name(role) + ".yml"),
                retries=1)
            if play_result != 0:
                break