Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint Ansible playbook and tweak code style slightly (for readability) #1724

Closed
geerlingguy opened this issue May 2, 2020 · 2 comments
Closed

Comments

@geerlingguy
Copy link
Contributor

Version:

N/A

K3s arguments:

N/A

Describe the bug

There are some linting errors and code style issues with the way the playbook is currently written (though, in general, it is a very good example (IMO) of a concise and well-written Ansible playbook!).

To Reproduce

Run ansible-lint and/or yamllint on the contrib/ansible playbook.

Expected behavior

No linting issues found.

Actual behavior

$ ansible-lint
[201] Trailing whitespace
roles/k3s/master/tasks/main.yml:39
  set_fact: 

[201] Trailing whitespace
roles/k3s/master/tasks/main.yml:42
- name: Restore node-token file access 

[301] Commands should not change things if nothing needs doing
roles/k3s/master/tasks/main.yml:60
Task/Handler: Replace https://localhost:6443 by https://master-pi:6443

[201] Trailing whitespace
roles/raspbian/tasks/main.yml:19
- name: Rebooting on Raspbian 

[305] Use shell only when shell functionality is required
roles/raspbian/tasks/main.yml:19
Task/Handler: Rebooting on Raspbian
$ yamllint .
./site.yml
  7:8       error    too many spaces inside braces  (braces)
  7:21      error    too many spaces inside braces  (braces)
  8:8       error    too many spaces inside braces  (braces)
  8:23      error    too many spaces inside braces  (braces)
  9:8       error    too many spaces inside braces  (braces)
  9:23      error    too many spaces inside braces  (braces)
  13:1      warning  comment not indented like content  (comments-indentation)
  16:8      error    too many spaces inside braces  (braces)
  16:25     error    too many spaces inside braces  (braces)
  19:1      warning  comment not indented like content  (comments-indentation)
  22:8      error    too many spaces inside braces  (braces)
  22:23     error    too many spaces inside braces  (braces)

./reset.yml
  7:8       error    too many spaces inside braces  (braces)
  7:20      error    too many spaces inside braces  (braces)

./roles/raspbian/tasks/main.yml
  19:30     error    trailing spaces  (trailing-spaces)

./roles/download/tasks/main.yml
  10:7      error    wrong indentation: expected 4 but found 6  (indentation)
  15:1      warning  comment not indented like content  (comments-indentation)
  20:7      error    wrong indentation: expected 4 but found 6  (indentation)
  31:7      error    wrong indentation: expected 4 but found 6  (indentation)

./roles/k3s/master/tasks/main.yml
  39:12     error    trailing spaces  (trailing-spaces)
  40:4      error    wrong indentation: expected 4 but found 3  (indentation)
  42:39     error    trailing spaces  (trailing-spaces)

./inventory/group_vars/all.yml
  1:1       warning  missing document start "---"  (document-start)

Additional context / logs

To prevent any future regressions, it would be nice to set up ansible-lint and/or yamllint (at least—could also set up Molecule for a functional test of the playbook) in CI.

I'll be opening a PR that adds a .yamllint configuration that's fairly standard for Ansible playbooks, and fixes for all the discovered issues.

@geerlingguy
Copy link
Contributor Author

PR for this is here: #1726

Note that I haven't added ansible-lint and yamllint to any CI, but to do so, we would need to run a container with Python on it and run:

set -e
pip3 install ansible-lint yamllint
cd contrib/ansible
ansible-lint
yamllint .

@geerlingguy
Copy link
Contributor Author

Moved to k3s-io/k3s-ansible#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant