Ad hoc commands

At the very basic core of Puppet Bolt, we issue remote commands, send scripts, and run scripts. Bolt provides three simple commands to do just that: bolt command runbolt file upload, and bolt script run. To test our SSH key from earlier, let's run a simple command using bolt command run:

rary at Ryans-MacBook-Pro-3 in ~/workspace/packt/bolt
$ bolt command run "echo 'Hello World'" --nodes puppetserver --no-host-key-check
Started on puppetserver.puppet.net...
Finished on puppetserver.puppet.net:
STDOUT:
Hello World
Successful on 1 node: pe-puppet-master.puppet.net
Ran on 1 node in 0.40 seconds

For simple one-off tasks, running the bolt command can be a great way to inspect a system. When we have a larger list of instructions to send, we'll want to write a script and run it remotely. Here is a simple script that returns users and all open ports:

#./inspect.sh

#!/bin/bash

echo 'Users:'
cat /etc/passwd | cut -f 1 -d ':'
echo 'Ports:'
netstat -tulpn

When we run this script via bolt script run, we get the following:

$ bolt script run inspect.sh --nodes puppetserver --no-host-key-check
Started on puppetserver.puppet.net...
Finished on puppetserver.puppet.net:
STDOUT:
Users:
root
...
vboxadd
vagrant
Ports:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1258/sshd
...
Successful on 1 node: puppetserver.puppet.net
Ran on 1 node in 0.85 seconds

Finally, if I wanted to make this script available on the Puppet Server for a local user, I could send it over with bolt script upload:

rary at Ryans-MacBook in ~/workspace/packt/bolt
$ bolt file upload inspect.sh /tmp/inspect.sh --nodes puppetserver --no-host-key-check
Started on puppetserver.puppet.net...
Finished on puppetserver.puppet.net:
Uploaded 'inspect.sh' to 'puppetserver.puppet.net:/tmp/inspect.sh'
Successful on 1 node: puppetserver.puppet.net
Ran on 1 node in 0.66 seconds
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.90.44