3

I have this Ansible code:

- name: Installing project files
  shell: |
    cd /opt/ewd-server
    npm install
  become_user: prod-{{SITE}}

Every time I run the code and it reaches that part it keeps saying that the server doesn't have the proxy up. Even thought I executed 2 commands before that:

npm config set https-proxy
npm config set proxy

The values are actually the companies IP's, but redacted for obvious reasons.

The code keeps running until it reaches the 'npm install' task, stays for about half an hour, then Ansible gives the error 'ENOENT'.

NOTE: when I run the npm install command in the server without Ansible it works.

If anyone knows any replacement for npm that works with Ansible, or a solution for this issue please help.

Kevin C
  • 4,851
  • 8
  • 30
  • 64
  • If you don't use the `-g` option to `npm config set` you are only setting the proxy for npm for the current user. Are you sure you ran that command while logged in as `prod-{{USER}}`? Why don't you simply issue those commands with ansible so you are sure to set the values for the correct user? Did you issue an `npm config get ...` command from ansible (basically to find out your proxy is actually not set)? It would be much easier to push an npmrc file in the user's home as a template or add the needed lines with `lineinfile`. Setting the environment as proposed by Kevin C. is also an option. – Zeitounator Dec 13 '21 at 13:26
  • i did check the .npmrc on both root and the prod user to see if it's set, and it is – Shaheen Ahmad Apr 13 '22 at 06:03

1 Answers1

1

Try configuring the environment variables 'http_proxy' and 'https_proxy':

 - name: Installing project files, using a specific proxy
     shell: |
              cd /opt/ewd-server
              npm install
     become_user: prod-{{SITE}}
     environment:
       http_proxy: http://proxy.adres
       https_proxy: http://proxy.adres

Of course, edit the proxy values.

Kevin C
  • 4,851
  • 8
  • 30
  • 64
  • Trying this solution as soon as i get a testing server from my team so we can test the code. – Shaheen Ahmad Dec 14 '21 at 07:29
  • alright so after all this time, finally got a chance to test this solution, it actually stays on that npm install step forever, i used -vvv option to verbose the output, there is no error yet, i might let it run for quite some time to see if it's either slow or that it will output an error, but i dont a change in the code you sent me. – Shaheen Ahmad Apr 12 '22 at 11:50
  • instead of using the environment option down there i just copied the 2 npm set config commands into the same installation steps, hopefully it does the same job. – Shaheen Ahmad Apr 12 '22 at 11:52