Octet

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

YAML
# 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.junos

Persistent 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

NeedPlugin
IOS, NX-OS, EOS, IOS XR CLI modulesnetwork_cli
Junos, or any NETCONF device with netconf_confignetconf
EOS eAPI, NX-API, firewalls and appliances with REST APIshttpapi

Traps

  • Mixing up ansible_network_os values. It must be the full collection name, such as cisco.ios.ios.
How did you do?