-
Notifications
You must be signed in to change notification settings - Fork 39
Fix lint issue #170
Fix lint issue #170
Conversation
loop: "{{ molecule_yml.platforms }}" | ||
register: dockerfile_stats | ||
|
||
- name: Create Dockerfiles from image names | ||
ansible.builtin.template: | ||
# when using embedded playbooks the dockerfile is alonside them | ||
src: >- | ||
{%- if dockerfile_stats.results[i].stat.exists -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you really sure that removing the "-" does not break the template? AFAIK the linter does not touch these and altering them has high risk of damaging the generate template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Sorry I forgot to mark it as a draft PR.
It's lucky we have test to stop me doing this.
Currently, there is an extra space between before else
.
Actual: }} {%- else -%}
Expected by linter: }}{%- else -%}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems only if we put all statement in one single line, the linter can pass.
{%- if foo -%}...{%- endif -%}
But it will make the line too long.
@ssbarnea
Do you have any suggestion?
https://github.com/ansible-community/molecule-docker/runs/8033866754?check_suite_focus=true#step:9:122
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still have any concern about this PR?
Folding without spaces
Using double quote and back slash
is the only way supporting folding without spaces.
Using a “Folded Block Scalar” > will fold newlines to spaces;
But ansible-lint is not happy with the spaces
.
BTW, I tried to remove if-else
statement in Jinja, but use set_fact module with Conditionals.
As it's a for-loop, it's not elegant either.
Test with ansible-lint==6.5.0
❯ ansible-lint --version
ansible-lint 6.5.0 using ansible 2.13.3
~/src/github/molecule-docker feature/fix-lint-issue* 23:50:00
❯ ansible-lint src/molecule_docker/playbooks/create.yml
~/src/github/molecule-docker feature/fix-lint-issue* 23:50:11
❯ echo $?
0
Reference
https://docs.ansible.com/ansible/2.9/reference_appendices/YAMLSyntax.html
https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-in-yaml-over-multiple-lines/21699210#21699210
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d4273c9
to
9491d1c
Compare
cd7faa6
to
986d4e6
Compare
Related to #163