Skip to content

Instantly share code, notes, and snippets.

@kronn
Forked from niklas/fetch_facts.sh
Last active December 15, 2015 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kronn/5320216 to your computer and use it in GitHub Desktop.
Save kronn/5320216 to your computer and use it in GitHub Desktop.
#!/bin/bash
ssh_host=$1
host_name=${2:-$ssh_host}
puppet_version="2.7.1"
if [ -z "$ssh_host" ]; then
echo "please provide hostname for node to fetch facts from"
exit
fi
file="features/nodes/$host_name.yaml"
cat > $file <<EOHEAD
--- !ruby/object:Puppet::Node
classes: []
environment: &id002 production
name: $host_name
parameters:
clientversion: ${puppet_version}"
EOHEAD
# run facter on the remote host, remove the first line ("---"), indend the yaml under above params
ssh $ssh_host 'sudo facter --yaml --puppet' \
| sed -e '1d' \
| sed -e 's/^/ /' \
>> $file
echo "Facts for $host_name written to $file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment