def validate(self, syntax_only=False):
self.packer_cmd = self.packer.validate<EOL>self._add_opt('<STR_LIT>' if syntax_only else None)<EOL>self._append_base_arguments()<EOL>self._add_opt(self.packerfile)<EOL>try:<EOL><INDENT>validation = self.packer_cmd()<EOL>validation.succeeded = validation.exit_code == <NUM_LIT:0><EOL>validation.error = None<EOL><DEDENT>except Exception as ex:<EOL><INDENT>validation = ValidationObject()<EOL>validation.succeeded = False<EOL>validation.failed = True<EOL>validation.error = ex.message<EOL><DEDENT>return validation<EOL>
Validates a Packer Template file (`packer validate`)

        If the validation failed, an `sh` exception will be raised.
        :param bool syntax_only: Whether to validate the syntax only
        without validating the configuration itself.