Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable is expanded at unpredictable way #1968

Open
EugenKon opened this issue Jul 17, 2024 · 1 comment
Open

Variable is expanded at unpredictable way #1968

EugenKon opened this issue Jul 17, 2024 · 1 comment

Comments

@EugenKon
Copy link

EugenKon commented Jul 17, 2024

Consul Template version

consul-template v0.37.6 (358ff54)

Configuration

      template {
        destination = "local/script.sh"
        data        = <<-EOH
          set -ex
          cmd='bash -c "source \${NOMAD_ALLOC_DIR}/creds.env; backup"'
          nomad alloc exec -task postgres-task "${DB_ALLOC_ID}" ${cmd}  || {
            exit 1;
          };
        EOH
      }

Debug output

+ cmd='bash -c "source \${NOMAD_ALLOC_DIR}/creds.env; backup"'
+ nomad alloc exec -task postgres-task a4ecf71b-3a7e-5a3b-cabd-2df187852011 bash -c '"source' '\${NOMAD_ALLOC_DIR}/creds.env;' 'backup"'
\${NOMAD_ALLOC_DIR}/creds.env;: -c: line 1: unexpected EOF while looking for matching `"'

Expected behavior

The command should be:

"source" "\${NOMAD_ALLOC_DIR}/creds.env;" "backup"

Actual behavior

"source' '\${NOMAD_ALLOC_DIR}/creds.env;' 'backup"

Steps to reproduce

  1. Nomad plan
  2. Nomad run
  3. "View logs" for the task.

Thoughts

Also it could be

+ nomad alloc exec -task postgres-task a4ecf71b-xx bash -c 'source ${NOMAD_ALLOC_DIR}/creds.env; backup'

Notice, in the case above the string is 'source ${NOMAD_ALLOC_DIR}/creds.env; backup'
For the template:

          nomad alloc exec -task postgres-task "${db_alloc_id}" \
            bash -c "source \${NOMAD_ALLOC_DIR}/creds.env; backup"  || {
              exit 1;
          };

It should be the same for the case when I used $cmd.

@EugenKon
Copy link
Author

Another example from my draft:

+ cmd='bash -c '\''source ${NOMAD_ALLOC_DIR}/creds.env; backup'\'''
+ nomad alloc exec -task postgres-task a4ecf71b-3a7e-5a3b-cabd-2df187852011 bash -c ''\''source' '${NOMAD_ALLOC_DIR}/creds.env;' 'backup'\'''

Notice how single ' is doubled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant