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

Octal-like strings are quoted unnecessarily #4166

Closed
kousu opened this issue May 16, 2024 · 0 comments · Fixed by #4167
Closed

Octal-like strings are quoted unnecessarily #4166

kousu opened this issue May 16, 2024 · 0 comments · Fixed by #4167
Assignees
Labels

Comments

@kousu
Copy link
Contributor

kousu commented May 16, 2024

Summary

ansible-lint --fix will quote any string value that starts with a "0", whether or not it needs to be. This behaviour was meant for handling the mess that are octals in YAML, and was introduced in #3030 and did a good job of helping that, but it's spilled out and is affecting all strings! 🍦

Issue Type
  • Bug Report
OS / ENVIRONMENT
% ansible-lint --version
WARNING: PATH altered to include /opt/homebrew/Cellar/ansible-lint/24.2.3_1/libexec/bin, /opt/homebrew/Cellar/ansible-lint/24.2.3_1/libexec/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.
ansible-lint 24.2.3 using ansible-core:2.16.6 ansible-compat:4.1.11 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
  • ansible installation method: brew install ansible

  • ansible-lint installation method: brew install ansible-lint && ansible-galaxy collection install --force community.general

    (I don't know why I needed to re-install community.general to get ansible-lint working, but that's a different bug, maybe in brew)

STEPS TO REPRODUCE
# config.yml 
---
- name: Configure things
  hosts: all
  become: false
  tasks:
    - name: Configure ii listen address
      ansible.builtin.command: |
        cmd: |
          tee /var/run/ii/config/addr
        stdin:
          {{ listen_addr }}:{{ listen_port }}
      vars:
        listen_addr: 0.0.0.0
        listen_port: 0o7828
        hex_input: 0x8294
        dec_input: 29848
        oct_input: 0364
        str_input: 0steps
        str_input2: 1steps
      changed_when: false

Run:

ansible-lint --fix
Actual Behavior
% ansible-lint --fix
WARNING: PATH altered to include /opt/homebrew/Cellar/ansible-lint/24.2.3_1/libexec/bin, /opt/homebrew/Cellar/ansible-lint/24.2.3_1/libexec/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.

Modified 1 files.
Passed: 0 failure(s), 0 warning(s) on 1 files. Last profile that met the validation criteria was 'production'.
A new release of ansible-lint is available: 24.2.3 → 24.5.0

Result:

% git diff
diff --git a/config.yml b/config.yml
index 1a9fef1..4ee77c2 100644
--- a/config.yml
+++ b/config.yml
@@ -10,11 +10,11 @@
         stdin:
           {{ listen_addr }}:{{ listen_port }}
       vars:
-        listen_addr: 0.0.0.0
-        listen_port: 0o7828
-        hex_input: 0x8294
+        listen_addr: "0.0.0.0"
+        listen_port: "0o7828"
+        hex_input: "0101224"
         dec_input: 29848
-        oct_input: 0364
-        str_input: 0steps
+        oct_input: "0364"
+        str_input: "0steps"
         str_input2: 1steps
       changed_when: false

If you need a more realistic example, consider managing Ubuntu's /etc/update-motd.d/ files: there's no reason "00-header" needs to be an odd duck, but ansible-lint made it so on my codebase:

   loop:
-    - 00-header
+    - "00-header"
     - 10-help-text
     - 50-landscape-sysinfo
     - 50-motd-news
     - 88-esm-announce
     - 91-contract-ua-esm-status
     - 95-hwe-eol
     - 97-overlayroot
Desired Behavior

I think strings that start with a "0" like "0.0.0.0" and "0steps" should remain unquoted. "1steps" remained unquoted, there's no reason "0steps" needs to be either.

🗃️ 🌵 🍰

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

Successfully merging a pull request may close this issue.

3 participants