What are network_cli, netconf and httpapi in Ansible, and how do you set them up?
Show the answer
Say this first
They are connection plugins from ansible.netcommon. network_cli keeps a persistent SSH session and
drives the CLI, used by most ios, nxos and eos modules. netconf opens a NETCONF session on port 830,
used by Junos modules and the generic netconf_config and netconf_get. httpapi talks to a device REST
API such as Arista eAPI or NX-API. You select one with ansible_connection and the platform with
ansible_network_os.
Group variables per platform
# group_vars/ios.yml
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
ansible_become: true
ansible_become_method: enable
# group_vars/eos.yml
ansible_connection: ansible.netcommon.httpapi
ansible_network_os: arista.eos.eos
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: true
ansible_become: true
ansible_become_method: enable
# group_vars/junos.yml
ansible_connection: ansible.netcommon.netconf
ansible_network_os: junipernetworks.junos.junosPersistent connections
network_cli, netconf and httpapi keep one connection per host open across tasks, instead of
logging in for every task. Two timers matter: the connect timeout and the command timeout, both 30
seconds by default. A slow show tech or a big config needs a larger command timeout.
The old way
Older playbooks used connection: local with a provider dictionary on each task. That pattern is
deprecated; set the connection in inventory variables instead.
Picking one
| Need | Plugin |
|---|---|
| IOS, NX-OS, EOS, IOS XR CLI modules | network_cli |
Junos, or any NETCONF device with netconf_config | netconf |
| EOS eAPI, NX-API, firewalls and appliances with REST APIs | httpapi |
Follow-ups
A task fails with "command timeout triggered". What do you change?
Raise the persistent command timeout (
ansible_command_timeoutor[persistent_connection] command_timeoutinansible.cfg) for that task or group, and check that the command really returns a prompt. A wrong prompt pattern also looks like a timeout.
Traps
- Mixing up
ansible_network_osvalues. It must be the full collection name, such ascisco.ios.ios.