Linux Configuration Templates

I’m trying to template a configuration file on linux. From what I can find on the documentation, this must be accomplished through a script (we’re deploying an archive to a linux system). With that in mind, I added a custom post-deploy script shown below. This works to template the file only if I remove the $(get_octopusvariable "app_key") variable substitution. As soon as I add the variable substitution, I get bad decrypt errors. The endpoint is an ssh target. What is causing there errors? Is there a better way to template arbitrary files if you’re not using Nuget packages? That would be a nice feature as OD moves further into cross platform.

Octopus Version: 3.5.2

Deployment Target OS: Centos 7

Variables:
app_key -> base64:+oP1Az/MeQsBMV5JOQONK5ICheVKdRGpCo3o76ved3A=

Post Deploy Script:
#!/bin/bash

cat > /var/www/html/website_root/.env << EOF
APP_ENV=local
APP_DEBUG=true
APP_KEY=$(get_octopusvariable “app_key”)

DB_HOST=localhost
DB_DATABASE=database
DB_USERNAME=user
DB_PASSWORD=password

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null

LDAP_PASSWORD_RESET.DEV.USERNAME=
LDAP_PASSWORD_RESET.DEV.PASSWORD=

LDAP_PASSWORD_RESET.TEST.USERNAME=
LDAP_PASSWORD_RESET.TEST.PASSWORD=

LDAP_PASSWORD_RESET.PROD.USERNAME=
LDAP_PASSWORD_RESET.PROD.PASSWORD=
EOF

ServerTasks-55986.log.txt (6 KB)

Hi Joe,

Thanks for getting in touch.

I believe the “bad decrypt” error you are seeing is because of the length of the sensitive variable you are using. I’ve create an issue here to track and contribute to: https://github.com/OctopusDeploy/Issues/issues/3122

A workaround would be to package your template into a zip file and use variable substitution.

Cheers,
Shane

Thanks for the update. I was able to get the templating to work via the code deploy feature. Thanks for the workaround!

Is there a way to change the name of the file when it gets templated? I would prefer to have, for example, a ‘config.template’ that gets committed to the repo with the #{} placeholders and a final substituted file of ‘config’ that gets deployed on the filesystem. This would allow developers with local versions of the repo to have a custom ‘config’ file without messing with the ‘config.template’

Hi Joe,

To change the name of the file do a rename in a post deploy script. Commit your template as config.template and then add a script called PostDeploy.sh with contents mv config.template config.

You can read more about custom scripts here: https://octopus.com/docs/deploying-applications/custom-scripts

Cheers,
Shane: