Ansible

Ansible

Made by DeepSource

Use module instead of command ANS-E3003

Performance
Major

Executing a command when there is an Ansible module is not recommended.

Ansible has two generic ways of performing a task, using Ansible modules or using the command/shell module. Ansible modules are developed by the Ansible community and third party vendors like rpm , docker , kubernetes , yum , azure etc.

command module allows you to run a shell command without actually invoking the shell but using command module is a bad idea, since it’s not idempotent in nature, the developer is responsible for handling the idempotency of the task.

Bad practice

- name: reboot the servers
  command: /sbin/reboot -t now

Recommended

Use an Ansible module with arguments.

- name: restart webserver
  service:
    name: httpd
    state: restarted