Which Ansible module executes EXEC commands on Cisco IOS?

300-435 By islever Editorial Last updated

Construct a network automation solution with Ansible to manage configurations

Short answer

A Ios_command is the Ansible module for Cisco IOS that runs EXEC and show commands and returns their stdout for inspection.

Question

Which Ansible module sends EXEC commands to Cisco IOS?
  1. ios_command Correct Answer
  2. ios_config
  3. ios_facts
  4. cli_command

Key Takeaways

Ansible's ios_command module is the IOS-specific module that executes EXEC and show commands on Cisco devices and returns the raw output for inspection. It wins over ios_config, which pushes configuration lines, and over ios_facts, which only collects a fixed set of normalized facts. In this scenario the requirement to run EXEC commands and read back their stdout maps directly onto ios_command and its wait_for matching.

Expert Analysis

The decisive condition here is that the automation goal is to run a privileged EXEC or show operation and read its output back, which is what separates ios_command from every other module listed. Ansible's Cisco IOS collection distinguishes modules by intent rather than by transport: one family pushes configuration stanzas, another gathers structured device data, and one executes arbitrary EXEC-level commands and returns their stdout. The question names EXEC commands explicitly, and that word alone routes the decision to the module whose documented purpose is running commands and registering output.

ios_command executes EXEC-level commands and returns stdout for inspection

The ios_command module targets the operational side of the device rather than its configuration datastore. You supply a list of commands — show version, show ip interface brief, show running-config — and Ansible opens a connection, enters the appropriate privilege level, issues each command, and returns the raw text under a results structure. The wait_for parameter adds a conditional gate: the task can retry until a regex matches the returned output, which turns a simple show command into a polling assertion. That combination of command execution plus output matching is precisely the behaviour the question describes. It also explains why ios_command is idempotency-neutral in a way configuration modules are not: it reports changed values based on task semantics, but it never computes a diff against a candidate configuration, because it is not writing configuration at all.

The ios_config alternative would only win if the task were declaring desired configuration state

The condition that would flip the verdict is a task whose payload is a configuration hierarchy or set of configuration lines meant to be reconciled against the running configuration. If the scenario described pushing an interface description, an ACL, or a set of line vty parameters and expecting Ansible to detect drift and only send the delta, then ios_config would be the correct module, since it builds candidate configuration, compares against the device, and optionally saves with save_when. Nothing in the requirement mentions configuration lines, parents, or children, so that branch never opens. The presence of the word EXEC is itself the discriminator: configuration modules operate on the configuration datastore through configuration-mode entry, while command modules operate at the EXEC prompt. A scenario that mixes both — for example, deploy VLANs and then verify them — would use ios_config for the first task and ios_command for the second, and the verification task is the one under discussion here.

Each remaining module breaks a different assumption in this EXEC-command task

ios_config costs correctness because it will attempt to treat the supplied strings as configuration lines, pushing them through configuration mode and reporting changes against a candidate config instead of returning the EXEC output a monitoring or verification task needs. ios_facts costs completeness: it runs a fixed internal set of show commands and returns normalized, prefixed facts such as ansible_net_hostname and ansible_net_interfaces, so any command outside that curated list — a bespoke troubleshooting show, a clear operation, a ping from the device — simply cannot be expressed, and the raw text is not preserved for regex matching. cli_command costs portability and specificity: it exists on the cli_command-capable connection framework and is not the IOS-specific module for this job, and in a Cisco IOS Collection context the platform-scoped ios_command is the module whose documentation, privilege escalation behaviour and test coverage are written for IOS.

Where in the run the module actually takes effect

Execution happens after the control node resolves inventory, selects the network_cli connection plugin, and completes authentication and privilege escalation. At that point the module renders the command list into the task's argument spec, sends each command down the persistent SSH channel, and captures the prompt-delimited response. Only then does wait_for evaluate: if the condition is unmet, the module re-sends the command up to retries times with interval seconds between attempts, and fails the task when the budget is exhausted. Registering the result exposes stdout, stdout_lines, and rc-style metadata for downstream conditionals, which is how the captured EXEC output feeds later tasks in the playbook.

Official Reference

Exam Strategy

Classify the requirement by intent before scanning module names: configuration lines, curated facts, or arbitrary EXEC output. Words like show, verify, clear, ping and stdout point at the command module family, while parents, lines, intended and drift point at the configuration family. On Cisco platforms, prefer the platform-scoped module (ios_command, nxos_command, iosxr_command) over the generic cli_command unless the scenario spans multiple vendors.

Practice All 300-435 Questions

Access 150 questions with complete answers and detailed explanations.

View Full 300-435 Practice Test →

← Back to 300-435 Study Guide