{"id":1216,"date":"2026-07-08T18:11:29","date_gmt":"2026-07-08T18:11:29","guid":{"rendered":"https:\/\/techno.slomka.biz\/?p=1216"},"modified":"2026-07-08T18:11:29","modified_gmt":"2026-07-08T18:11:29","slug":"quick-yaml-validation-without-installing-yamllint","status":"publish","type":"post","link":"https:\/\/techno.slomka.biz\/?p=1216","title":{"rendered":"Quick YAML Validation Without Installing `yamllint`"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If Python and the <strong>PyYAML<\/strong> module are available, you can perform a simple YAML syntax check without installing <code>yamllint<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">Bash<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>python -c \"import yaml; yaml.safe_load(open('main.yml')); print('YAML OK')\"<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFCB6B\">python<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">-c<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">import yaml; yaml.safe_load(open(&#39;main.yml&#39;)); print(&#39;YAML OK&#39;)<\/span><span style=\"color: #89DDFF\">&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">If the file is valid YAML, the command prints:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">Bash<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>YAML OK<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFCB6B\">YAML<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">OK<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">If the parser encounters invalid YAML syntax, PyYAML raises an exception and reports the location of the error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This approach verifies that the file can be successfully parsed, making it useful for quick checks in scripts, CI jobs, or restricted environments where additional tools cannot be installed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>However, it is important to understand that parsing is not the same as linting.<\/strong> PyYAML only checks whether the YAML syntax is valid. It does not detect style issues, formatting inconsistencies, duplicate keys, excessive line lengths, trailing spaces, or violations of project-specific conventions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tools such as <code>yamllint <\/code>provide more comprehensive validation by combining syntax checking with configurable style and quality rules. As a result, a file that passes the PyYAML check may still produce warnings or errors when analyzed with <code>yamllint<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In summary:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>PyYAML (yaml.safe_load)<\/strong>: Verifies that the YAML document is syntactically valid and can be parsed.<\/li>\n\n\n\n<li><strong><code>yamllint<\/code><\/strong>: Verifies syntax and enforces formatting, style, and best-practice rules.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For quick syntax validation, the PyYAML approach is often sufficient. For production environments and collaborative projects, <code>yamllint <\/code>remains the preferred option.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If Python and the PyYAML module are available, you can perform a simple YAML syntax check without installing yamllint: If the file is valid YAML, the command prints: If the parser encounters invalid YAML syntax, PyYAML raises an exception and reports the location of the error. This approach verifies that the file can be successfully parsed, making it useful for quick checks in scripts, CI jobs, or restricted environments where additional tools cannot be installed. However, it is important to understand that parsing is not the same as linting. PyYAML only checks whether the YAML syntax is valid. It does not detect style issues, formatting inconsistencies, duplicate keys, excessive line lengths, trailing spaces, or violations of project-specific conventions. Tools such as yamllint provide more comprehensive validation by combining syntax checking with configurable style and quality rules. As a result, a file that passes the PyYAML check may still produce warnings or errors when analyzed with yamllint. In summary: For quick syntax validation, the PyYAML approach is often sufficient. For production environments and collaborative projects, yamllint remains the preferred option.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,114],"tags":[116,140],"class_list":["post-1216","post","type-post","status-publish","format-standard","hentry","category-devops","category-python","tag-python","tag-yamllint"],"_links":{"self":[{"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=\/wp\/v2\/posts\/1216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1216"}],"version-history":[{"count":2,"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=\/wp\/v2\/posts\/1216\/revisions"}],"predecessor-version":[{"id":1219,"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=\/wp\/v2\/posts\/1216\/revisions\/1219"}],"wp:attachment":[{"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techno.slomka.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}