Created
December 13, 2018 17:06
-
-
Save openfirmware/7078e44a91e9fbe308b3ffadf37605f1 to your computer and use it in GitHub Desktop.
Chef Bash Resource without mangling interpolated variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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