Skip to content
This repository was archived by the owner on Aug 20, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lldp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Bolt powered LLDP Query

Tasks allow you to take your existings admin scripts and package them into puppet modules, making your code repos ad-hoc task enabled. Have a script related to a puppet taks that doesn't currently need to be in catalogs? Add them to a puppet module! This example shows how you might take an LLDP script you use to validate connection maps and use tasks to run them against hosts.

Note that tasks can be implemented in any language which will run on the target nodes. This example uses `bash`, purely as a simple demonstration, but you could use Perl, Python, Lua, Javascript, etc. as long as it can read environment variables or take content on stdin.

Scripts should be under [modulename]/tasks/[script] which then namespaces natively as modulename::script


We can then run that task using `bolt` like so.

```
bolt task run lldp <nodes> --modules ./ #This assumes you're in the tasks-playground dir
```

This should result in output similar to:

```
bolt_ssh_1:

lldpad is installed

Ran on 1 node in 0.23 seconds
```

As shown above, the init script included is just a package check (would also allow install if account permissions allowed). Also included is a neighbor check to get info of attached swtiches/devices.
bolt task run lldp::neighbors <nodes> --modules ./

Try running the `bolt` command with a different value for `message` and you should see the expected results.
```
bolt_ssh_1:

eth0=myfirstswitch.mydomain.com eth1=mysecondswitch.mydomain.com

Ran on 1 node in 0.78 seconds
```
27 changes: 27 additions & 0 deletions lldp/tasks/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# See if lldp prereqs are installed. In not, see if we can install them

# Paths
lldpad=/usr/sbin/lldpad
lldpcli=/usr/sbin/lldpcli
lldptool=/usr/sbin/lldptool
YUM_CMD=$(which yum 2>/dev/null)
APT_CMD=$(which apt-get 2>/dev/null)

if [[ ! -z $YUM_CMD ]]; then
if [[ -f $lldpad ]]; then
printf "lldpad is installed\n"
else
yum install -y lldpad
fi
elif [[ ! -z $APT_CMD ]]; then
if [[ -f lldpcli ]]; then
printf "lldpcli is installed\n"
else
apt-get install -y lldpcli
fi
else
printf "No suitable package manager found\n"
exit 1
fi
39 changes: 39 additions & 0 deletions lldp/tasks/neighbors
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

# Find Switch/Neighbor Information

# Paths
lldpad=/usr/sbin/lldpad
lldpcli=/usr/sbin/lldpcli
lldptool=/usr/sbin/lldptool


if [[ -a $lldpcli ]]; then
$lldpcli show neighbors | grep "Interface\|SysName" | awk {'print $2'} | sed 'N;s/\n/ /' | sed 's/, /=/' | sed 'N;s/\n/ /'
elif [[ -a /usr/sbin/lldptool ]]; then
# Run daemon
$lldpad -d

# Configure interfaces
for i in `ls /sys/class/net/ | grep 'eth\|ens\|eno'`; do
$lldptool set-lldp -i $i adminStatus=rxtx &>/dev/null
$lldptool -T -i $i -V sysName enableTx=yes &>/dev/null
$lldptool -T -i $i -V portDesc enableTx=yes &>/dev/null
$lldptool -T -i $i -V sysDesc enableTx=yes &>/dev/null
$lldptool -T -i $i -V sysCap enableTx=yes &>/dev/null
$lldptool -T -i $i -V mngAddr enableTx=yes &>/dev/null
done

# Get neighbors
for i in `ls /sys/class/net/ | grep 'eth\|ens\|eno'`; do
upswitch=$($lldptool -t -n -i $i | sed -n '/System Name/{n;p;}' | sed 's/\s//')
if [[ -n $upswitch ]]; then
printf "$i=$upswitch "
else
printf "No neighbor found on $i"
fi
done
else
echo "No tool"
exit 1
fi