I have this command which I want to variabilize. Particularly I want the latest argument presence to depend on an environment variable.
ansible-playbook --inventory inventories/ssg-dev deploy.yml --vault-id dev@~/ansible-password --skip-tags "clear-data"
Here is my attempt:
ansible-playbook --inventory inventories/ssg-$ENVIRONMENT deploy.yml --vault-id $ENVIRONMENT@~/ansible-password $( [ $DATA_SCHEMAS_MIGRATION == true ] && echo ' --skip-tags "clear-data"')
When I set my environment variables and run that command with an echo
before to check the output, it is the exact same as my original command. However, the argument doesn't seem to be passed when I run it, which makes me believe that the environment variable is not evaluated in the command substitution.
Why my code doesn't work and how to fix it?
bash
in both cases – Guerric P Mar 06 '23 at 19:59DATA_SCHEMAS_MIGRATION=true; ls -- $( [ $DATA_SCHEMAS_MIGRATION == true ] && echo ' --skip-tags "clear-data"')
– ShellCode Mar 06 '23 at 20:01