title: ansible - Nothing happens when executing InstallHalyard.sh script via ansible-playbook
body: <p>I'm trying to make a playbook to install halyard on a remote host using ansible-playbook. One of the tasks is to execute the "InstallHalyard.sh" wrapper scripts to the actual installer (reference: <a href="https://www.spinnaker.io/setup/install/halyard/" rel="nofollow noreferrer">https://www.spinnaker.io/setup/install/halyard/</a>).</p>
  
  <p>No error / failure present, but also nothing has changed, as if the InstallHalyard.sh script is not executed. Though, it's fine if I do it by typing manual command. The other similar task works perfectly.</p>
  
  <p>You can see the InstallHalyard.sh script implementation: <a href="https://raw.githubusercontent.com/spinnaker/halyard/master/install/stable/InstallHalyard.sh" rel="nofollow noreferrer">here</a></p>
  
  <p><strong>Any idea about what is happening?</strong></p>
  
  <p>Here is the task in my playbook:</p>
  
  <pre><code>name: Run InstallHalyard.sh
    become: yes
    become_user: sudo
    shell: "{{ ansible_env.HOME }}/.spinnaker/InstallHalyard.sh"
  </code></pre>
  
  <p>Any help would be appreciated, thank you very much :)</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Already tried using script, command, and shell module.</p>
  
  <p>FYI, the InstallHalyard.sh script will call itself by passing an env variable and needs to do curl -O</p>
  
  <p>I'm suspecting the "export" operation inside the script doesn't work as Ansible has a different  understandings for environment vars. (For example, ansible will not recognize "$HOME" instead it uses "{{ ansible_env.HOME }}".)</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I found the script does an operation that makes a fork, does ansible handle this kind of operation?</p>
  
  <p>Tested on localhost, got the same result.</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>It is because of the different interpretation of environment vars of ansible. If I executed the script manually, the wrapper sets the environment variable and pass it to the next script calls, which ansible not able to do. So what I do is setting the environment var manually with ansible module before executing the script (just adding 2 lines)</p>
  
  <p>Here is my revised task:</p>
  
  <pre><code>name: Run InstallHalyard.sh
    become: yes
    become_user: sudo
    environment:
      HAL_USER: "{{ ansible_env.USER }}"
    shell: "{{ ansible_env.HOME }}/.spinnaker/InstallHalyard.sh"
  </code></pre>