Problem: Ansible secret extra-vars are parsed incorrectly when values contain spaces
Issue
Variable Group secret variables are passed to Ansible differently from regular extra variables.
Regular extra variables are serialized into a JSON --extra-vars argument, but secret variables are currently appended separately as:
--extra-vars name=valueThis causes values containing spaces or other complex content to be parsed incorrectly by Ansible.
For example, a secret variable containing:
value with spacesis not transported in the same safe way as the existing JSON extra-vars payload.
This is especially problematic for values such as SSH public keys, tokens containing spaces, and other structured secret values.
Current behavior
Semaphore builds the normal extra-vars JSON payload first, then appends each Environment Secret Variable as another CLI argument:
--extra-vars name=valueExpected behavior
Environment Secret Variables of type var should be merged into the existing JSON extra-vars map before serialization.
This preserves the exact value and also keeps the existing secret-variable override precedence.
Environment secrets of type env should remain environment variables and should not be included in the Ansible JSON extra-vars payload.
Reproduction
- Create a Variable Group.
- Add a Secret Variable.
- Set its value to a string containing spaces.
- Attach the Variable Group to an Ansible template.
- Run a playbook that validates the complete variable value.
The value is not transported correctly when passed using name=value.
Tested fix
I tested a change that merges EnvironmentSecretVar values into getEnvironmentExtraVarsJSON() and removes the separate --extra-vars name=value arguments.
A regression test verifies:
- values containing spaces;
- multiline values;
- secret variable precedence over normal extra vars;
- exclusion of EnvironmentSecretEnv values.
The fix has also been verified end-to-end with an Ansible task.
Semaphore version
Originally reproduced on v2.19.7.
The same separate name=value transport is still present in the current develop branch.
Source: semaphoreui/semaphore