This error usually comes in Ansible versions below 2.5. The loop command is not available in Ansible versions less than 2.5.

amalgjose.com

Solution

If you are facing this error, you have two options to solve this error

  • Upgrade Ansible version to 2.5+
  • Use with_items instead of loop command in the script. The same code should work.