Using command
yum
in place of yum
module 8 changed_when: false
9
10 - name: run yum update
11 command: yum update12
13 - name: clone git repo
14 git:
Description
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