command module
The module that runs any program you name on the host and reports what it printed, without being able to tell whether it changed anything.
In more detail
Because it cannot know what the command did, it reports changed every time, so it is not idempotent unless you add changed_when or a similar guard. Its result includes the return code (rc) and the output. Prefer a dedicated module when one exists, and reach for command for questions such as uname -s or id -u.
Example
ansible all -m ansible.builtin.command -a "echo hello"Related terms
- shell module — The module that runs a command through the host's shell, so pipes, redirection and variables work, unlike the command module.
- changed_when — The task keyword that decides, from a condition, whether the task should report changed.
- idempotency — The property of an operation that gives the same result whether you run it once or many times, because a repeat run finds nothing left to do.
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- register — The task keyword that saves a task's result in a named variable so later tasks can read it.
Taught in
- Your First Ad Hoc Command — Ansible Configuration Management at Scale
- Connections And Privilege Escalation — Ansible Configuration Management at Scale
- Modules And Idempotency — Ansible Configuration Management at Scale
- Graded On A Machine You Never Touched — RHCE in Ansible (EX294): Automate Red Hat Systems
- Conditionals: register, when, changed_when And failed_when — RHCE in Ansible (EX294): Automate Red Hat Systems
- Services And Boot Targets: Started Is Not Enabled — RHCE in Ansible (EX294): Automate Red Hat Systems
- File Systems And Mounts: mounted, present And UUIDs — RHCE in Ansible (EX294): Automate Red Hat Systems
- SELinux: Labels, Ports And Booleans That Persist — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: A Web Node From A Ticket — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: Storage Only Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: People, Passwords And sudo From The Vault — RHCE in Ansible (EX294): Automate Red Hat Systems
- Mock Exam, Part 2: Real Machines And The Patterns That Fail — RHCE in Ansible (EX294): Automate Red Hat Systems