Skip to content

Instantly share code, notes, and snippets.

@dayne
Last active June 26, 2021 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dayne/3869744e305531fc878d to your computer and use it in GitHub Desktop.
Save dayne/3869744e305531fc878d to your computer and use it in GitHub Desktop.
Cowsay Fortunes

Chef essentials training result

... a cowsay fortune tool

installing (on your chef essentials vm)

curl the silly moo.rb recipe file

curl -o moo.rb https://gist.githubusercontent.com/dayne/3869744e305531fc878d/raw/moo.rb

chef client local mode install it and try it out:

sudo chef-client -z moo.rb 
cowfortune 

usage

cowfortune to get a random cow type with random fortune

cowfortune -l to give yourself a looping cowfortune

#!/usr/bin/env ruby
#
$cowfiles = Dir.glob('/usr/share/cowsay/*.cow').collect{ |i| File.basename(i, '.cow') }
def cowfortune
cf = $cowfiles[rand($cowfiles.size)]
fortune = `fortune`
`cowsay -f #{cf} \`fortune\``
end
if ARGV.delete("-l")
loop do
system('clear')
cowfortune
sleep 10
end
elsif ARGV.delete("-w")
require 'sinatra'
set :port, 8080
get "/" do
"<h2><pre>" +
`cowfortune` +
"</pre></h2>"
end
else
puts cowfortune
end
# chef cookbook to install cowsay, fortune, and cowfortune
[ 'cowsay', 'fortune-mod', 'ruby' ].each { |p| package p }
gem_package 'sinatra'
remote_file '/usr/local/bin/cowfortune' do
source 'https://gist.githubusercontent.com/dayne/3869744e305531fc878d/raw/cowfortune.rb'
mode '0755'
owner 'chef'
group 'chef'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment