Member-only story
Ansible troubleshooting — Error 304: inline-env-var
How to Solve the Ansible Error 304 inline-env-var
Introduction
Ansible, the powerful automation tool, empowers users to streamline tasks and processes efficiently. However, ensuring best practices and maintaining a clean and predictable playbook is crucial. Ansible-Lint, a popular linting tool for Ansible playbooks, enforces a range of rules to help users optimize their automation scripts. In this article, we focus on Rule 304, “inline-env-var
,” which checks that environment variables should not be set within the ansible.builtin.command
module. Instead, the ansible.builtin.shell
module or the environment keyword should be used for this purpose.
Understanding Rule 304
Rule 304, “inline-env-var,” offers a simple yet effective piece of guidance for Ansible playbook authors. It highlights the importance of maintaining clarity and best practices in your playbooks by ensuring that environment variables are not set directly within the ansible.builtin.command
module.
Problematic Code
Consider this problematic code snippet:
---
- name: Example playbook
hosts: all
tasks:
- name: Set environment variable
ansible.builtin.command…