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 prop-erties. This means that you can store one template in source control that applies to many dif-ferent environments.
Roles
Roles are a way to encapsulate common tasks and properties for reuse, if you find yourself writ-ing 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
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/nxos-ansible http://docs.ansible.com/ansible/
Chef
Introduction
Chef is a powerful automation platform that transforms complex infrastructure into code, en-abling your data center infrastructure automation using a declarative, intent-based model.
Whether you’re operating in the cloud, on-premises, or a hybrid, Chef automates how applica-tions are configured, deployed, and managed across your network, no matter its size.
Chef is built around simple concepts: achieving desired state, centralized modeling of IT infra-structure, and resource primitives that serve as building blocks. These concepts enable you to quickly manage any infrastructure with Chef. These very same concepts allow Chef to handle the most difficult infrastructure challenges and customer use-cases, anything that can run the chef-client can be managed by Chef.
Key Technical Concepts
Chef Server
The Chef server acts as a hub for configuration data. It stores:
• Cookbooks
• Recipes (The policies that are applied to nodes)
• Metadata that describes each registered node that is being managed by the chef-client.
Node
Any physical, virtual, or cloud machine or switch configured to be maintained by a chef-client.
Chef Client
Runs locally on every node that is registered with the Chef server. Performs all configuration tasks specified by the run-list and brings client into desired state.
Chef Resources
Term used for a grouping of managed objects/attributes and one or more corresponding im-plementations. It describes the desired state for a configuration item and declares the steps needed to bring that item to the desired state. It specifies a resource type—such as a package, template or service, and lists additional details (also known as attributes), as necessary. These are grouped into recipes, which describe working configurations
The 2 core layers of a resource:
• Resource Type: Definition of managed objects.
• Resource Provider: Implementation of management tasks on objects.
Cookbook
A cookbook defines a scenario and contains everything that is required to support that sce-nario, and is used for device configuration and policy distribution:
• Recipes that specify the resources to use and the order in which they are to be applied
• Attribute values
• File distributions
• Templates
• Extensions to Chef, such as libraries, definitions, and custom resources Recipe
A collection of resources, defined using patterns (resource names, attribute-value pairs, and ac-tions); helper code is added around this using Ruby:
• Must be stored in a cookbook
• May use the results of a search query and read the contents of a data bag
• May have a dependency on one (or more) recipes
• Must be added to a run-list before it can be used by the chef-client
• Is always executed in the same order as listed in a run-list
• The chef-client will run a recipe only when asked
Sample Cookbook Showing Configuration of Switch Interface as L3 or L2:
cisco_interface 'Ethernet1/1' do action :create
ipv4_address '10.1.1.1' ipv4_netmask_length 24 ipv4_proxy_arp true ipv4_redirects true shutdown true
switchport_mode 'disabled' end
switchport_mode 'access' switchport_vtp true end