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

Fix ansible-lint and yamllint issues #255

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

thystips
Copy link
Collaborator

@thystips thystips commented Aug 23, 2024

Juste in case : I have not tested playbooks in test/ directory.

Ansible-lint result

WARNING  Ignored exception from ArgsRule.matchtasks while processing tasks/pve_cluster_config.yml (tasks): No module named 'ansible.module_utils.pvesh'
WARNING  Ignored exception from ArgsRule.matchtasks while processing tasks/main.yml (tasks): No module named 'ansible.module_utils.pvesh'

Passed: 0 failure(s), 0 warning(s) on 56 files. Last profile that met the validation criteria was 'production'.

I can't fix warnings about module_utils but for ansible-lint project is't a issue

Signed-off-by: ThysTips <contact@antoinethys.com>
@thystips thystips changed the title Fix all ansible-lint and yamllint issues Fix ansible-lint and yamllint issues Aug 26, 2024
@thystips thystips marked this pull request as draft August 26, 2024 11:29
@thystips thystips marked this pull request as ready for review August 26, 2024 11:29
Copy link
Owner

@lae lae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need more time to finish this review later but for the time being there are some things I need feedback on. Please also rebase against develop (and amend the commit/force push).

Consider everything reviewed except for tasks/ceph.yml and tests/test.yml for now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this file.

@@ -22,13 +22,14 @@ pve_pcie_report_msrs: true
pve_watchdog: none
pve_watchdog_ipmi_action: power_cycle
pve_watchdog_ipmi_timeout: 10
pve_zfs_enabled: no
pve_zfs_enabled: false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yamllint follows yaml 1.2 spec, which removes these truthy values, but Ansible does not. Ansible docs still heavily use yes/no as boolean and that doesn't seem like it's changing anytime soon, so I feel like these should be ignored. Thoughts? (I updated .yamllint.yml to reflect this for the time being.)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README.md should reflect these changes, especially since we're adding an additional role variable.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These handlers are being updated without the respective notify attributes being updated in task files, which I believe breaks the role?

...that said, I don't 100% agree with ansible-lint's casing rule being forced to apply to strings passed to notify . There's some discussion at https://forum.ansible.com/t/ansible-lints-fixation-on-upper-case-initial-letters/5862 that shares my sentiment. However, while it's not mentioned there, I can see the handler tasks themselves following the casing rule because at the end they'll look like normal tasks to whoever is running the playbook so...using the listen attribute to work around this does seem like the better option.

Keep the names as-is in this file for now.

@@ -1,50 +1,52 @@
# This is an Ansible version of what "pveceph install" actually does
---

- block:
- name: Create initial Ceph config
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to Ceph initialisation

when:
- not pve_cluster_enabled | bool or (pve_cluster_enabled and inventory_hostname == groups[pve_group][0])
- pve_domains_cfg | length > 0

- name: Select ldap-based realms with sync
set_fact:
ansible.builtin.set_fact:
pve_ldap_realms_with_sync: |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not need to be wrapped? Either way, this change does not seem to follow the usual indentation rule, nor does it try to follow any alignment for readability...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: has task key order rule

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: has task key order rule

create: yes
mode: 0644
create: true
mode: "0644"
dest: /root/.ssh/config
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to move dest above create here for consistency with the earlier blockinfile task.


- name: Update PVE cluster HA groups
command: >-
ansible.builtin.command: >-
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not need to be wrapped with updated line length limit.

Copy link
Owner

@lae lae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, done checking the last two files. See comments and last review.

\\g<space>type \\g<r_type>\
\\g<space>min_size {{ (pve_ceph_crush_rules | selectattr(\"name\", \"match\", item.name) | list)[0].min_size | default(\"\\g<min>\") | trim }}\
\\g<space>max_size {{ (pve_ceph_crush_rules | selectattr(\"name\", \"match\", item.name) | list)[0].max_size | default(\"\\g<max>\") | trim }}\
{%- if ((pve_ceph_crush_rules | selectattr(\"name\", \"match\", item.name) | list)[0].class | default(False)) -%}\
\\g<space>step take default class {{ (pve_ceph_crush_rules | selectattr(\"name\", \"match\", item.name) | list)[0].class }}\
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the untouched line below should also be indented for readability (because they're inside conditionals)

ansible.builtin.command: crushtool -c crush_map_decompressed -o new_crush_map_compressed
register: _crushmap_valid
when: _crushmap.changed
changed_when: _crushmap_valid.rc == 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably just be true? Cause the other cases are just task error if rc != 1 or task skip...I think? If that's accurate then this statement just feels like it's an unnecessary layer of indirection cause it'll always be successful as long as it completes.

pveceph fs create
--name {{ item.name }}
--add-storage {{ item.storage }}
--pg_num {{ item.pgs }}
register: _ceph_fs_create
failed_when: _ceph_fs_create.stderr
when: "item.name not in (_ceph_fs.stdout | from_json | map(attribute='name'))"
with_items: '{{ pve_ceph_fs }}'
with_items: "{{ pve_ceph_fs }}"
changed_when: _ceph_fs_create.rc == 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing about the layer of indirection here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to this file stating that all the shell tasks were replaced with command tasks?
As you've said you haven't tested these so there may or may not be breakage here...I don't really think there is, but just in case, that comment will help me remember if I run into any snags when I get around to rebuilding the test environment.

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 this pull request may close these issues.

2 participants