Ansible run command with updated PATH version
I am doing the following:
tasks:
- name: Output env vars
shell: echo $PATH $ANDROID_HOME > path.txt
environment:
ANDROID_HOME: "/home/{{ deploy_user }}/android-sdk-linux"
PATH: "{{ ansible_env.ANDROID_HOME }} /tools:/platform-tools:{{ ansible_env.PATH }}"
Server output:
$ less path.txt
{{ ansible_env.ANDROID_HOME }}/tools:/platform-tools:{{ ansible_env.PATH }} /home/azureuser/android-sdk-linux}}
It seems that the string is not interpolated.
Exactly the same tutorial with the task:
tasks:
- name: Output $PATH
shell: echo $PATH $ANDROID_HOME > path.txt
environment:
ANDROID_HOME: "/home/{{ deploy_user }}/android-sdk-linux"
PATH: "/tools:/platform-tools:{{ ansible_env.PATH }}"
gives
$ less path.txt
/tools:/platform-tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games /home/azureuser/android-sdk-linux
which I expected.
+3
source to share
1 answer
You cannot use undefined variable, in your case
PATH: "{{ansible_env.ANDROID_HOME}} / tools: / platform-tools: {{ansible_env.PATH}}"
I assume you don't have a "ANDROID_HOME" variable on the remote node, so the whole line is not interpreted.
You need to replace "{{ansible_env.ANDROID_HOME}} with" {{ANDROID_HOME}} "or use some other logic.
+3
source to share