Ansible network_cli connection for device CLI automation
Short answer
A Use Ansible's network_cli connection plugin, which drives device CLI automation over SSH with proper prompt and privilege handling.
Question
Key Takeaways
Ansible network automation over device CLI requires the network_cli connection plugin, which handles prompt parsing, privilege escalation, and platform terminal plugins on top of SSH. Option A, network_cli, is correct because generic transports like ssh, paramiko, and local lack the network-specific handling that ios_command and similar modules depend on.
Expert Analysis
'connection: network_cli' is used for network CLI automation.
The deciding constraint is that Ansible modules for network devices do not run on the target host the way ordinary Linux modules do. They execute on the control node and push commands over the device's CLI transport, so the play must declare a connection plugin that understands network inventory hosts. Option A, network_cli, is exactly that plugin: it authenticates to the device, handles the CLI prompt/#-terminator exchange, and lets modules such as ios_command, ios_facts, or ios_config run without Python on the box. That is why connection: network_cli (and the ansible_connection inventory variable) is the correct choice for CLI-based automation of IOS, NX-OS, IOS-XE and similar platforms.
Option B, ssh, names the underlying protocol rather than a valid Ansible connection plugin. Ansible's plugins are ssh, paramiko, local, network_cli, httpapi and a few others, but the plain ssh plugin is the legacy general-purpose one that assumes a POSIX target with Python and a shell it can drive — it does not perform the network-specific prompt handling that network_cli adds on top of the SSH transport. Choosing it would leave the playbook expecting a login shell on the device, which is not how network CLI modules are designed to work.
Option C, paramiko, is a Python SSH library and also an Ansible connection plugin name, but like ssh it is a generic host-connection mechanism. It exists as a fallback when OpenSSH is unavailable on the control node; it provides no network-device prompt handling, no privilege escalation to enable mode, and no platform-specific terminal plugin wiring. For a network device it is simply the wrong layer of abstraction compared with network_cli.
Option D, local, runs the module on the control node with no remote connection at all. That is appropriate for playbooks that call local_action, delegate_to: localhost, or RESTCONF/NETCONF requests built with uri/uri-style modules against the device's API, but it is not a connection type for driving the device's CLI. If a question asked about a RESTCONF or NETCONF play using the uri or ansible.netcommon.httpapi family, local or httpapi would be defensible; for CLI automation it is not.
One mechanism this answer relies on but the option list never states: network_cli requires ansible_network_os (for example ios, nxos, eos) to be set for each host. Without that variable the plugin cannot select the matching terminal and cliconf plugins, so authentication and prompt parsing fail even though SSH itself works. This is the classic trap in Ansible network questions — the transport (SSH) is a given, but the correct answer is the connection plugin layered on top of it. In exam terms, when a question says "Ansible connection type for network" and lists generic transports alongside network_cli, network_cli is the answer because it is the only option purpose-built for network CLI automation.
Exam Strategy
When an Ansible question asks for a connection type and mixes generic transports (ssh, paramiko, local) with network-specific plugins, pick the network-specific one — network_cli, httpapi, or netconf — because Ansible network modules need platform-aware prompt handling that generic plugins do not provide. Also remember that network_cli requires ansible_network_os to be set per host; if the scenario emphasizes RESTCONF or NETCONF instead of CLI, httpapi or netconf becomes the right plugin.
Related Analysis
Practice All 300-435 Questions
Access 150 questions with complete answers and detailed explanations.
View Full 300-435 Practice Test →