Ansible

Ansible

Made by DeepSource

Environment variables don't work as part of command ANS-E3004

Bug risk
Major

Command module does not accept setting environment variables inline.

Use environment: to set environment variables or use shell module which accepts both.

Bad practice

- name: install ruby 2.3.1
  command: CONFIGURE_OPTS='--disable-install-doc' RBENV_ROOT='{{ rbenv_root }}' rbenv install {{ rbenv_ruby_version }}
  args:
    creates: '{{ rbenv_root }}/versions/{{ rbenv_ruby_version }}/bin/ruby'
  vars:
    rbenv_root: /usr/local/rbenv
    rbenv_ruby_version: 2.3.1

Recommended

---
- name: install ruby 2.3.1
  command: rbenv install {{ rbenv_ruby_version }}
  args:
    creates: '{{ rbenv_root }}/versions/{{ rbenv_ruby_version }}/bin/ruby'
  vars:
    rbenv_root: /usr/local/rbenv
    rbenv_ruby_version: 2.3.1
  environment:
    CONFIGURE_OPTS: '--disable-install-doc'
    RBENV_ROOT: '{{ rbenv_root }}'
    PATH: '{{ rbenv_root }}/bin:{{ rbenv_root }}/shims:{{ rbenv_plugins }}/ruby-build/bin:{{ ansible_env.PATH }}'