예제 #1
0
    def config_import_inventory(self, file_path):
        # type: (str) -> None
        """Config Import Inventory

        Import groups and child associations from the provided
        inventory file. This currently does not import hosts, group
        vars, or host vars that may also exist in the inventory file.

        :param file_path: path to inventory file to import
        :type file_path: string
        """
        check_arg(file_path, u._('File path'), str)
        if not os.path.isfile(file_path):
            raise InvalidArgument(
                u._('File {path} is not valid.').format(path=file_path))
        inventory = Inventory(file_path)
        Inventory.save(inventory)
예제 #2
0
    def run(self):
        try:
            if self.local_only:
                # Create a temporary local inventory with only localhost
                self.inventory = Inventory()
                self.inventory.set_deploy_mode(False)
                self.inventory.add_host('localhost')
            else:
                self.inventory = Inventory.load()
            inventory_path = self._make_temp_inventory()
            cmd = self._get_playbook_cmd(inventory_path)
            self._log_ansible_cmd(cmd, inventory_path)

            # create and run the job
            job = AnsibleJob(cmd, self.deploy_id, self.print_output,
                             inventory_path)
            job._ignore_error_strings = self.ignore_error_strings
            job.run()
            return job

        except Exception:
            raise Exception(traceback.format_exc())