You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was doing something pretty trivial to loop over the users on the system (code below) but the debug action kept giving me an error that "item" wasn't defined.
It wasn't obvious in my other IDE that I had indented once too many and it became an argument for ansible.builtin.debug. At the time I was more focused on that I might not be correctly getting a list of items for ansible to iterate rather than the indenting so I had a bunch of commented lines of my attempts that made it a bit more difficult to see the indent issue. I only really noticed after I cleaned it up to get some help with another pair of eyes.
Two suggestions would be:
ansible-lint rule for ansible keywords like "loop" & "with_*" should be at the action level indent
ansible-lint rule "loop" (or "with_items", etc.) isn't an argument for ansible.builtin.debug
More restrictive rule could be one that takes 1 & 2 into account before generating a warning.
- name: Get users
ansible.builtin.getent:
database: passwd
- name: Debug this
ansible.builtin.debug:
msg: "{{ item }}"
# many comments like below of different attempts due to the ansible "item" undefined error
# loop: "{{ ansible_facts.getent_passwd | dict2items }}"
# with_items:
# - "test1"
# - "test2"
# loop: "{{ ansible_facts.getent_passwd.keys() | list }}"
loop: "{{ ansible_facts.getent_passwd.keys() | list }}"
# ^ warning about this indent would be helpful
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was doing something pretty trivial to loop over the users on the system (code below) but the debug action kept giving me an error that "item" wasn't defined.
It wasn't obvious in my other IDE that I had indented once too many and it became an argument for ansible.builtin.debug. At the time I was more focused on that I might not be correctly getting a list of items for ansible to iterate rather than the indenting so I had a bunch of commented lines of my attempts that made it a bit more difficult to see the indent issue. I only really noticed after I cleaned it up to get some help with another pair of eyes.
Two suggestions would be:
More restrictive rule could be one that takes 1 & 2 into account before generating a warning.
Beta Was this translation helpful? Give feedback.
All reactions