Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy usage for Windows agent install #547

Closed
bmphbWV0 opened this issue Feb 14, 2024 · 3 comments · Fixed by #553
Closed

Add proxy usage for Windows agent install #547

bmphbWV0 opened this issue Feb 14, 2024 · 3 comments · Fixed by #553

Comments

@bmphbWV0
Copy link

Hello,
I have tried to install Datadog Agent on a Windows Server that has no direct access to internet. It is available through a Proxy.
When trying to run the playbook to install Datadog Agent on a Windows Server, it fails because of this :

fatal: [myserver]: FAILED! => {
    "changed": false, 
    "dest": "C:\\Users\\MyUser\\AppData\\Local\\Temp\\fix_6_14.ps1", 
    "elapsed": 0, 
    "invocation": {
        "module_args": {
            "checksum": null, 
            "checksum_algorithm": "sha1", 
            "checksum_url": null, 
            "dest": "C:\\Users\\MyUser\\AppData\\Local\\Temp\\fix_6_14.ps1", 
            "force": true, 
            "force_basic_auth": false, 
            "headers": {}, 
            "proxy_password": null, 
            "proxy_url": null, 
            "proxy_username": null, 
            "timeout": 10, 
            "url": "https://s3.amazonaws.com/ddagent-windows-stable/scripts/fix_6_14.ps1", 
            "url_password": null, 
            "url_username": null, 
            "use_proxy": true, 
            "validate_certs": true
        }
    }, 
    "msg": "Error requesting 'https://s3.amazonaws.com/ddagent-windows-stable/scripts/fix_6_14.ps1'. Unable to connect to the remote server", 
    "status_code": 0, 
    "url": "https://s3.amazonaws.com/ddagent-windows-stable/scripts/fix_6_14.ps1"
}

Your role is executed from this playbook (with a requirements.yml file that points on the main branch of this repository) :

- hosts: all
  gather_facts: true
  roles:
  - datadog
  environment:
    HTTP_PROXY: "{{ http_proxy | default('') }}"
    HTTPS_PROXY: "{{ http_proxy | default('') }}"

The playbook is executed using this command :

ansible-playbook playbook.yml -i /my-inventory -l myserver -f 5 --private-key mykey.key -u myuser -vvvvvvvv -e http_proxy=http://myproxy:proxyport/ -e HTTP_PROXY=http://myproxy:proxyport/ -e HTTPS_PROXY=http://myproxy:proxyport/

These environment variables are visible in the Gather Facts command that runs at the beginning of the Playbook execution, but it is not used by the win_get_url module.

Is it possible to add a way to use a proxy in win_get_url commands you run for a Windows install ?

Thanks by advance.

Regards.

@bmphbWV0
Copy link
Author

To give more information, I tried forking your repo and change "pkg-windows.yml" file to use a proxy like that :

- name: Download windows datadog agent 614 fix script
  win_get_url:
    url: "{{ datadog_windows_614_fix_script_url }}"
    dest: '%TEMP%\fix_6_14.ps1'
    proxy_url: "{{ HTTP_PROXY }}"
  when: not agent_datadog_skip_install and datadog_apply_windows_614_fix

# ...

- name: Download windows datadog agent
  win_get_url:
    url: "{{ agent_dd_download_url }}"
    dest: '%TEMP%\ddagent.msi'
    proxy_url: "{{ HTTP_PROXY }}"
  register: agent_download_msi_result
  when: (not agent_datadog_skip_install) and (not ansible_check_mode)
  
  # ...

Changing this and running back my playbook command (ansible-playbook playbook.yml -i my-inventory -l myserver -f 5 --private-key my.key -u myuser -v -e HTTP_PROXY=http://proxy.fqdn:proxy.port/ -e HTTPS_PROXY=http://proxy.fqdn:proxy.port/) is working for an unauthenticated proxy usage.

@bkabrda
Copy link
Contributor

bkabrda commented Feb 22, 2024

Hi @njt-cla 👋. I put together PR #553 that should help you - I'd be curious if you could provide feedback on it. First of all, it uses lowercase environment variable names (as recommended in official Ansible docs). Second, it also tells Ansible to omit the proxy_url value if http_proxy is not defined.

Let me know if you think this makes sense, thanks!

@bmphbWV0
Copy link
Author

Hello, thanks for your fast answer.
It seems to correct the issue I had. I close the Issue. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants