`[WARNING]: TASK: app : Configure vhost: The loop variable 'item' is already in use. You should set the `loop_var` value in the `loop_control` option for the task to something else to avoid variable collisions and unexpected behavior.`
IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer
Likely causes → An outer loop runs include_tasks or include_role, and the included file loops again. Both use item, so the inner loop shadows the outer one.
Fix →
- ansible.builtin.include_tasks: vhost.yml
loop: "{{ sites }}"
loop_control:
loop_var: site
Inside vhost.yml, refer to site.name and keep item for the inner loop.
Prevent → Always set loop_var when looping over include_*. It also makes the included files easier to read.
More on Variables, Facts and Precedence Problems
Variables in `group_vars/webservers.yml` are silently ignoredBeginnerYou set `nginx_port: 8443` in inventory `group_vars`, but the role still uses `80`Intermediate`set_fact: release_tag=v2` runs, but later tasks still see `v1`Intermediate`'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'` when templating `hostvars['db01']`Intermediate`'ansible_eth0' is undefined` on new cloud instancesBeginnerFacts like `ansible_hostname` became undefined after someone changed `ansible.cfg`Intermediate