Introduction

Ansible is an open-source software platform for configuring and managing compute and switching infrastructure using "playbooks". Ansible features a state-driven resource model that describes the desired state of computer systems and services. It is used to automate the configuration of a company’s compute and switching resources in an agent-less manner.

Ansible is a very straightforward and powerful tool for intent-based network automation, all you need to get started are playbooks, a server configuration file, and an inventory file.

Key Technical Concepts

Playbooks

Playbooks specify a list of tasks that are run in sequence across one or more hosts. Each task can also run multiple times with a variable taking a different value. Playbooks are expressed in YAML format.

Inventory

Inventory is the representation of information about hosts — what groups a host belongs to, the properties those groups and hosts have. A hierarchy of groups often results.

Templates

Templates allow you to generate configuration files from values set in various inventory properties. This means that you can store one template in source control that applies to many different environments.

Roles

Roles are a way to encapsulate common tasks and properties for reuse, if you find yourself writing the same tasks in multiple playbooks, turn them into roles.

Sample Playbook To Configure VLANs:

  cisco@linux-dev:~/nxos-ansible/ansible_playbooks$ more vlans.yml 
  # vlans.yml  
  `---`
  
  - name: VLANs  
    hosts: all  
    connection: local  
    gather_facts: no  
  
  
    tasks:  
      - name: ensure VLANs 2-20 and 99 exist on all switches  
        nxos_vlan: vlan_id="2-20,99" state=present host={{ inventory_hostname }}  
  
      - name: config VLANs names for a few VLANs  
        nxos_vlan: vlan_id={{ item.vid }} name={{ item.name }} host={{ inventory_hostname }} state=present  
        with_items:  
          - { vid: 2, name: web }  
          - { vid: 3, name: app }  
          - { vid: 4, name: db }  
          - { vid: 20, name: server }  
          - { vid: 99, name: native }  
          - 

Ansible Reference Links

https://github.com/datacenter/Ansible-NXOS

https://docs.ansible.com/ansible/