There is an assertation that one reason the "curl | sudo bash" pattern is bad is because you may experience network failure and execute a partially downloaded script.
This:
rm -rf /tmp/random_directory
Could accidentally become:
rm -rf /
PS C:\ruby> chef-apply package.rb | |
Recipe: (chef-apply cookbook)::(chef-apply recipe) | |
* log[lolwut ruby] action write (skipped due to only_if) | |
PS C:\ruby> vim .\package.rb | |
PS C:\ruby> chef-apply package.rb | |
Recipe: (chef-apply cookbook)::(chef-apply recipe) | |
* log[lolwut ruby] action write | |
PS C:\ruby> chef-apply package.rb -l info | |
[2014-06-26T13:16:07-04:00] INFO: Run List is [] | |
[2014-06-26T13:16:07-04:00] INFO: Run List expands to [] |
Ohai.plugin(:Mdadm) do | |
provides 'mdadm' | |
def create_raid_device_mash(stdout) | |
device_mash = Mash.new | |
device_mash[:device_counts] = Mash.new | |
stdout.each do |line| | |
case line | |
when /Version\s+: ([0-9.]+)/ | |
device_mash[:version] = Regexp.last_match[1].to_f |
I wrote this on 2010-10-01, and I've been passing it around as the entry to my opinion on why we need namespacing on the community site. Maybe it's a terrible argument since we haven't implemented it yet, but it's a lot of words that I can save myself from typing over again. | |
I thought there were tickets or mailing list posts with opposition to namespacing, but I can't find them. Drop them in the comments if you know of any please. | |
Bryan McLellan <[email protected]> | |
### | |
Earlier in the week we had a meeting (you guys rock) at HQ about | |
cookbook workflow and one of the subjects we discussed heavily was | |
cookbook namespace on the cookbook site. At the end of the meeting I |
# Using Color in log messages in Chef | |
require 'highline' | |
# Use the log resource (runs during convergence) | |
log HighLine.new.color("foobar", :yellow) | |
# Use Chef::Log (runs during compilation) | |
Chef::Log.info(HighLine.new.color("foobar", :yellow)) |
# Reads a product code from an MSI file | |
# Checks if that product code is installed on the system | |
require 'rubygems' | |
require 'ffi' | |
require 'pathname' | |
PRODUCT_CODE_LENGTH = 38 | |
module Win32 |
There is an assertation that one reason the "curl | sudo bash" pattern is bad is because you may experience network failure and execute a partially downloaded script.
This:
rm -rf /tmp/random_directory
Could accidentally become:
rm -rf /
#!/bin/bash | |
# This is the current stable release to default to, with Omnibus patch level (e.g. 10.12.0-1) | |
# Note that the chef template downloads 'x.y.z' not 'x.y.z-r' which should be a duplicate of the latest -r | |
use_shell=0 | |
prerelease="false" | |
# Check whether a command exists - returns 0 if it does, 1 if it does not | |
exists() { |
class A | |
@@cvar = {} | |
def mutate | |
@@cvar[:foo] = "bar" | |
end | |
def add(k,v) | |
@@cvar[k] = v | |
end |
curl https://www.opscode.com/chef/install.sh | sudo bash
That's it. This can be put in any instructions, such as a README or someone's blog, since the logic is in the shell script. Provided you download the script using https, the file has standard levels of authentication and encryption protecting it from manipulation.
This is obviously a shell script, if you're really concerned about the argument that it may contain nefarious activities within, you can easily review it before you run it.
# This error goes to STDERR | |
$ asdfasdf | |
-bash: asdfasdf: command not found | |
# We redirect STDERR to STDOUT, but STDOUT to null, so we can use grep against STDERR | |
$ asdfasdf 2>&1 >/dev/null | grep -q not ; echo $? | |
0 |