跳转到内容

inline-env-var

此规则检查 playbook 是否在`ansible.builtin.command` 模块中设置环境变量。

应使用`ansible.builtin.shell` 模块或`environment` 关键字设置环境变量。

问题代码

---
- name: Example playbook
  hosts: all
  tasks:
    - name: Set environment variable
      ansible.builtin.command: MY_ENV_VAR=my_value # <- Sets an environment variable in the command module.

正确代码

---
- name: Example playbook
  hosts: all
  tasks:
    - name: Set environment variable
      ansible.builtin.shell: echo $MY_ENV_VAR
      environment:
        MY_ENV_VAR: my_value # <- Sets an environment variable with the environment keyword.
---
- name: Example playbook
  hosts: all
  tasks:
    - name: Set environment variable
      ansible.builtin.shell: MY_ENV_VAR=my_value # <- Sets an environment variable with the shell module.