Member-only story

Ansible troubleshooting — Error use-loop

Embracing the Loop: Ansible Lint’s Use-Loop Rule

Luca Berton
4 min readNov 9, 2023

Introduction

Ansible, a powerful IT automation tool, continually evolves to improve the efficiency and readability of playbooks. One such evolution is the introduction of the use-loop rule in Ansible Lint, aiming to discourage the use of with_xxx as a looping mechanism in favor of the more versatile loop.

The Rule in Action

The use-loop rule emphasizes the preference for the loop construct over the older with_xxx syntax. While the latter is not deprecated, adopting the loop syntax is encouraged for a future-proof playbook.

When applied, the rule generates messages highlighting instances where with_xxx is used for looping, nudging developers towards the more modern and flexible loop alternative. For example, it may produce warnings such as:

  • use-loop[play]: The play uses strategy: free.
  • use-loop[task]: Using run_once may behave differently if the strategy is set to free.

Understanding the Motivation

The use-loop rule aligns with Ansible’s commitment to staying current and streamlining syntax for better code maintenance. By discouraging the use of with_xxx

--

--

Luca Berton
Luca Berton

Written by Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday

No responses yet