Skip to content

Instantly share code, notes, and snippets.

@rmoriz
Last active February 15, 2016 18:52
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 rmoriz/c3e7d8fd5061480b680b to your computer and use it in GitHub Desktop.
Save rmoriz/c3e7d8fd5061480b680b to your computer and use it in GitHub Desktop.
Copy chef data bags
#!/bin/bash
function copy_data_bag() {
data_bag=$1
data_bag_item=$2
new_data_bag_item=$3
tmp_file_old=$(mktemp)
tmp_file_new=$(mktemp)
chef exec knife data bag show ${data_bag} ${data_bag_item} -f json > ${tmp_file_old}
jq -c ".id = \"${new_data_bag_item}\"" ${tmp_file_old} > ${tmp_file_new}.json
chef exec knife data bag from file ${data_bag} ${tmp_file_new}.json --encrypt
rm ${tmp_file_old}
rm ${tmp_file_new}
rm ${tmp_file_new}.json
}
@rmoriz
Copy link
Author

rmoriz commented Feb 15, 2016

Usage:

copy_data_bag apps my_application my_application_staging

Requires:

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