Member-only story
Ansible troubleshooting — Error 305: command-instead-of-shell
How to Solve the Ansible Error 305 command-instead-of-shell
Introduction
Ansible, the popular automation tool, provides a powerful platform for managing and configuring IT infrastructure efficiently. While Ansible offers various modules to execute tasks, it’s crucial to choose the right module for specific use cases. Ansible-Lint, a widely-used linting tool for Ansible playbooks, enforces rules to help you follow best practices. In this article, we’ll delve into Rule 305, “command-instead-of-shell,” which encourages the use of the command module over the shell module when it’s not necessary to employ shell features.
Understanding Rule 305
Rule 305, “command-instead-of-shell,” is a valuable guideline that promotes efficiency and best practices in Ansible playbooks. It suggests that the command module should be preferred over the shell module unless specific shell features, such as environment variable expansion or chaining multiple commands using pipes, are required.
Problematic Code
Let’s explore a piece of problematic code that Rule 305 can identify in your playbooks:
---
- name: Problematic example
hosts: all…