cloud66-oss / trackman

Execute commands as a workflow.
Apache License 2.0
197 stars 8 forks source link

set an environment variable not working #3

Closed shoneslab closed 4 years ago

shoneslab commented 5 years ago

Trying to set an environment variable in the workflow.yml It works when I set the environment variable directly in the console/terminal

- name: set ansible config
   command: export ANSIBLE_CONFIG=/home/shone/lab-demo/ansible.cfg 

Getting errors

ERRO[0000] Failed to run Step="set ansible config" ERRO[0000] exec: "export": executable file not found in $PATH Step="set ansible config" ERRO[0000] Calling a stop to run Step="set ansible config" ERRO[0000] Done with errors

khash commented 5 years ago

I think this is due to export being a builtin bash command. We need to fix this by adding support for passing environment variables into the commands and sourcing files. Since Trackman spins off new processes as a child process, a workaround is to run trackman with all the environment variables you'd need to pass into the child processes:

export FOO=bar trackman ...
shoneslab commented 5 years ago

Thanks.

Also pipe (|) not working in trackman config file command: ansible --version | head -n 1 | gawk '{ print $2 }'

khash commented 5 years ago

That's a good question and I don't have the answer! Will have to try. Given the way Trackman calls the executables, it doesn't have access to bash syntax, including pipes. One solution (which would cover the first issue on ENV as well) is to run bash as the command with the rest following as params. Example:

...
...
command: "bash '-c ansible --version | head n -1'"