Ansible
Structure

Step 1 - Ansible Playbooks

Ansible, calls its configuration and orchestration framework "playbooks" and its collections of "play(s)" or tasks for configuration management and deployment to a device or multiple devices in a synchronous or asynchronous fashion. While playbooks can be represented as a single file, Ansible's best practice recommends a particular directory structure for playbooks that we'll be building below. This directory structure lets you organize files into smaller configuration files for better reuse, particularly into "roles." Roles in Ansible are a way to automatically load certain variables, tasks, etc., depending on a categorization. A role can be defined for example by device type. Before creating the configuration tasks using Ansible modules, lets create the appropriate directory structure.


cd ~/ltrdcn-3225/ansible


mkdir -p playbooks/aci/group_vars
mkdir -p playbooks/aci/host_vars
mkdir -p playbooks/aci/roles

Step 2 - Initialize Ansible APIC via Galaxy

We're going to use Ansible Galaxy to create our roles within the roles directory. Ansible Galaxy is the official community for downloading or creating roles.


ansible-galaxy init playbooks/aci/roles/apic

You can view all the changes via the Visual Studio Code Browser or you can run the tree command. We'll mainly be working within the defaults, tasks, and vars directories. The defaults and vars directories contain variables to be used by the tasks, and as you probably guessed, the tasks will be placed within the tasks directory.


tree


.
└── playbooks/
    └── aci/
        ├── group_vars/
        ├── host_vars/
        └── roles/
            └── apic/
                ├── defaults/
                │   └── main.yml
                ├── files/
                ├── handlers/
                │   └── main.yml
                ├── meta/
                │   └── main.yml
                ├── README.md
                ├── tasks/
                │   └── main.yml
                ├── templates/
                ├── tests/
                │   ├── inventory
                │   └── test.yml
                └── vars/
                    └── main.yml

14 directories, 8 files