Skip to content

Instantly share code, notes, and snippets.

@openfirmware
Created December 13, 2018 17:06
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 openfirmware/7078e44a91e9fbe308b3ffadf37605f1 to your computer and use it in GitHub Desktop.
Save openfirmware/7078e44a91e9fbe308b3ffadf37605f1 to your computer and use it in GitHub Desktop.
Chef Bash Resource without mangling interpolated variables
# Wrong way:
bash "Add Icinga Web 2 User" do
code <<-EOH
/usr/bin/psql -U icingaweb2 -d icingaweb2 -h localhost -p 5432 \
-c "INSERT INTO icingaweb_user (name, active, password_hash) \
VALUES ('#{username}', 1, '#{hash_pw}') ON CONFLICT (name) \
DO UPDATE SET password_hash = '#{hash_pw}' \
WHERE icingaweb_user.name = '#{username}';"
EOH
sensitive true
end
# Right way:
bash "Add Icinga Web 2 User" do
code <<-EOH
/usr/bin/psql -U icingaweb2 -d icingaweb2 -h localhost -p 5432 \
<<'EOF'
INSERT INTO icingaweb_user (name, active, password_hash) \
VALUES ('#{username}', 1, '#{hash_pw}') ON CONFLICT (name) \
DO UPDATE SET password_hash = '#{hash_pw}' \
WHERE icingaweb_user.name = '#{username}';
EOF
EOH
sensitive true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment