DEPRECATED: Ansible: Utilizing Cumulus Linux Ansible Modules

Follow

DeprecatedThis article has been deprecated, and replaced with Automation for Network Engineers

This article outlines the process for utilizing Cumulus Linux modules for Ansible playbooks. The advantages of the modules are:

  • Reduced complexity of playbooks
  • No need for Jinja templates
  • Simple software upgrades and licensing

Requirements

Utilizing Cumulus Linux Modules

To utilize Cumulus Linux modules with your Ansible playbook, do the following:

  1. Install the Ansible role. Install the cumulus.CumulusLinux role, which contains the Cumulus Linux modules, from Ansible Galaxy. Use the ansible-galaxy install cumulus.CumulusLinux command:
    cumulus@switch:~$ sudo ansible-galaxy install cumulus.CumulusLinux
     downloading role 'CumulusLinux', owned by cumulus
     no version specified, installing master
     - downloading role from https://github.com/cumulusnetworks/cumulus-linux-ansible-modules/archive/master.tar.gz
     - extracting cumulus.CumulusLinux to /etc/ansible/roles/cumulus.CumulusLinux
    cumulus.CumulusLinux was installed successfully
    cumulus@switch:~$
  2. Set up the Ansible libraries. In some environments, multiple people use the same Debian host to run Ansible playbooks. Normally the ansible.cfg is found at /etc/ansible/ansible.cfg. However, a playbook will first check the local directory for an ansible.cfg. This allows for multiple ansible.cfg files without affecting another user's playbooks by changes made to the ansible.cfg file. Here is the configuration of an ansible.cfg located at ~/playbook/:
    cumulus@switch:~$ cat ansible.cfg
    [defaults]
    library=/etc/ansible/roles/cumulus.CumulusLinux/library/:/usr/share/ansible 
    host_key_checking=False 
    hostfile = ansible.hosts
    What do these three lines mean?
    • library = /etc/ansible/roles/cumulus.CumulusLinux/library/:/usr/share/ansible
      When you installed the cumulus.CumulusLinux role, it placed the Cumulus Linux modules at /etc/ansible/roles/cumulus.CumulusLinux/library/; the colon (:) is equivalent to AND in this case and the /usr/share/ansible is the default installation area for Ansible's built-in modules. This line specifies that the custom Cumulus Linux Modules AND the normal built-in modules will be used.
    • host_key_checking=False
      SSH key checking is enabled by default. In some environments, this can slow you down if you are doing something as simple as testing with plain-text passwords.
    • hostfile = ansible.hosts
      Instead of looking at /etc/ansible/hosts, use a local file called ansible.hosts in the same directory.
  3. Create a playbook. Make a really simple playbook that calls the new module cl_license, one of the numerous modules included with this installation.
    1. To see all the modules, run ls /etc/ansible/roles/cumulus.CumulusLinux/library/ or visit the Cumulus Networks GitHub.
    2. Create the task file under ~/playbook/roles/license/tasks/main.yml.
      cumulus@switch:~$ cat ~/playbook/roles/license/tasks/main.yml
      - name: install license using http url
        cl_license: src='http://192.168.100.224/license.txt'
        
    3. Create your playbook file under ~/playbook/license.yml
      cumulus@switch:~$ cat license.yml
        ---
        - hosts: switches
          user: root
          roles:
            - license
        
    4. Show the ansible.hosts file, mentioned earlier, located at ~/playbook/ansible.hosts.
      cumulus@switch:~$ cat ansible.hosts
        [switches]
        sw1
        
  4. Run the playbook. Run ansible-playbook playbookname -k, where -k enables the use of a text password instead of an SSH key:
    ansible-playbook license.yml -k
    SSH password:
    
    PLAY [switches] ***************************************************************
    
    GATHERING FACTS ***************************************************************
    ok: [sw1]
    
    TASK: [license | install license using http url] ******************************
    changed: [sw1]
    
    PLAY RECAP ********************************************************************
    sw1                        : ok=2    changed=1    unreachable=0    failed=0
    
  5. The Cumulus Linux modules now work with Ansible! Check out all the modules on GitHub at github.com/CumulusNetworks/cumulus-linux-ansible-modules.

See Also

Have more questions? Submit a request

Comments

Powered by Zendesk