Set up a Basic Ansible Lab

This article outlines the process for managing a switch using Ansible in a lab environment. This example is showing off Ansible’s ad-hoc commands. For repeated tasks, use an Ansible playbook; like this easy playbook example.


  • One switch running Cumulus Linux (any version), called switch1
  • A server or virtual machine running Debian, with a basic installation (default packages only), called server1

On the server, set up the following:

  • DHCP
  • Ansible

Network Addresses

This example uses the subnet.

IP AddressEntity existing gateway

Configure server1

Configure a DHCP server on the server, then install Ansible.

  1. Install the required packages:

    root@server:~# apt-get install isc-dhcp-server
  2. Assign the static IP address to server1. Edit /etc/network/interfaces so it looks like:

    auto lo
    iface lo inet loopback
    auto eth0
    iface eth0 inet static
  3. Configure the DHCP scope. Edit /etc/dhcp/dhcpd.conf and add this to the file:

    subnet netmask {
        option routers;
        option domain-name-server;
        option domain-name "";
        host switch1 {
          hardware ethernet 00:JJ:YU:38:AC:45;
  4. Restart server1.

  5. Reboot switch1.

  6. Confirm that switch1 is reachable from server1:

     root@server:~# ping 
     64 bytes from icmp_req=2 ttl=64 time=0.141 ms
  7. Install Ansible:

    root@server:~# apt-get install python-pip
    root@server:~# pip install ansible

Configure a MOTD via Ansible

This section describes how to create a simple message of the day (MOTD) using Ansible.

  1. Create a sample MOTD file:

     root@server:~#  echo "SAMPLE MOTD" > ~/sample.motd
  2. Create an inventory file with switch1 in the list:

     root@server:~#  echo "" > ~/ansible.hosts
  3. Push the sample MOTD to switch1 ( Enter the password for the cumulus user (the default user):

    root@server:~# ansible -k -K -u cumulus -i ~/ansible.hosts -m 'copy' -a 'src=~/sample.motd dest=/etc/motd'
    SSH password:
    sudo password [defaults to SSH password]: 
     sw1 | success >> {
        "changed": false, 
        "dest": "/etc/motd", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "b04dde3768174a34f75fdde78142849d", 
        "mode": "0644", 
        "owner": "root", 
        "path": "/etc/motd", 
        "size": 12, 
        "state": "file", 
        "uid": 0

See Also

Default username and password for Cumulus Linux