Skip to content

Instantly share code, notes, and snippets.

@164c
Created June 14, 2012 10:46
Show Gist options
  • Save 164c/2929567 to your computer and use it in GitHub Desktop.
Save 164c/2929567 to your computer and use it in GitHub Desktop.
chefのnodeファイルのnameをファイル名と合わせるscript
#!/bin/sh
BASE_DIR=/path/to/chef_nodes_dir
for filepath in $BASE_DIR/*.json
do
filename=`basename $filepath`
hostname=`echo $filename | sed -e "s/\.json//"`
written_host=`grep "\"name\"" $filepath | awk '{print $2}' | sed -e 's/[,"]//g'`
if [ $written_host != $hostname ] ; then
sed -i -e "s/$written_host/$hostname/" $filepath
fi
done
@164c
Copy link
Author

164c commented Jun 14, 2012

nodeファイルはhostname.jsonという名前になってる前提で、同じroleのホストを大量に立てるときに使える可能性0.5%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment