Bookmark this page

Guided Exercise: Executing Ad Hoc Commands

In this exercise, you will execute ad hoc commands on multiple managed hosts.

Outcomes

You should be able to execute a command on a group of hosts on ad hoc basis.

You should have set the value of variables to support connection and authentication, as described in the Deploying Ansible exercise. The rest of the exercises in this section have the same dependency.

Open a terminal window as the student user on the workstation VM.

Procedure 2.1. Instructions

  1. Change to the ~/proj/ directory created in Lab 1.

  2. Verify that the cs01 device can ping the tower machine (172.25.250.9).

    [student@workstation proj]$ ansible -m ios_ping -a "dest=172.25.250.9" cs01
    SSH password: student
    cs01 | SUCCESS => {
        "changed": false,
        "commands": [
            "ping 172.25.250.9"
        ],
        "packet_loss": "20%",
        "packets_rx": 4,
        "packets_tx": 5,
        "rtt": {
            "avg": 2,
            "max": 4,
            "min": 1
        }
    }
  3. Use the traceroute command to inspect the path between cs01 and the management workstation.

    [student@workstation proj]$ ansible -m ios_command \
    > -a "commands='traceroute 172.25.250.254 probe 2 timeout 2'" cs01
    SSH password: student
    cs01 | SUCCESS => {
        "changed": false,
        "stdout": [
            "Type escape sequence to abort.\nTracing the route to 172.25.250.254\nVRF info:
    (vrf in name/id, vrf out name/id)\n 1 172.25.250.254 4 msec 1 msec"
        ],
        "stdout_lines": [
            [
                "Type escape sequence to abort.",
                "Tracing the route to 172.25.250.254",
                "VRF info: (vrf in name/id, vrf out name/id)",
                " 1 172.25.250.254 4 msec 1 msec"
            ]
        ]
    }
  4. An extremely useful command for VyOS devices is sh conf com, which displays the running configuration. You will see other ways of obtaining the running configuration (vyos_conf module with backup=yes, vyos_facts with subset=all).

    [student@workstation proj]$ ansible -m vyos_command \
    > -a "commands='sh conf com'" spine01
    SSH password: vyos
    spine01 | SUCCESS => {
        "changed": false,
        "stdout": [
    ...output omitted...

This concludes the guided exercise.

Revision: do457-2.5-4693601