ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
784 stars 1.45k forks source link

gitlab_project - missing ability to set HTTP proxy #8540

Closed agrimal closed 2 weeks ago

agrimal commented 2 weeks ago

Summary

Hello, I'm behind a HTTP proxy for accessing gitlab and I can't see a way to set it for this module. As far as I can see, I can't use this module.

Issue Type

Bug Report

Component Name

gitlab_project

Ansible Version

$ ansible --version
ansible [core 2.16.8]
  config file = /xxx/ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /xxx/lib/python3.11/site-packages/ansible
  ansible collection location = /home/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /xxx/bin/ansible
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/xxx/bin/python)
  jinja version = 3.1.3
  libyaml = False

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 8.6.1  

Configuration

No response

OS / Environment

Debian 12

Steps to Reproduce

- name: Create gitlab project
  environment:
    http_proxy: "{{ proxy }}"
    http_proxys: "{{ proxy }}"
  community.general.gitlab_project:
    api_url: "{{ api_url }}"
    api_token: "{{ api_token }}"
    name: "{{ name }}"
    group: "{{ group }}"
    initialize_with_readme: true
  delegate_to: localhost
  become: false

Expected Results

the module uses the configured proxy

Actual Results

It's not working, the module is trying to access directly instead of using the proxy

Code of Conduct

ansibullbot commented 2 weeks ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 2 weeks ago

cc @Lunik @Shaps @lgatellier @marwatk @metanovii @nejch @scodeman @sh0shin @suukit @waheedi @zanssa click here for bot help

nejch commented 2 weeks ago

@agrimal while I'm sure it'd be a nice to have to also explicitly set proxy via arguments, the de-facto standard way to configure this is via the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables.

The gitlab modules use python-gitlab under the hood, which in turn uses requests, and this respects the standard environment variables (https://requests.readthedocs.io/en/latest/user/advanced/#proxies). So IMO it's best to just do that, but maybe others disagree. Just consider that (from a quick search) no other module in this collection provides an explicit argument for this, so I think that's just what people do.

Source: I do this at work using gitlab modules as well.

agrimal commented 2 weeks ago

Thanks for your answer. I can't set the variables directly on the command line as I have to use different proxies depending on the destination.

nejch commented 2 weeks ago

@agrimal you don't need to set them on the CLI, you do it in ansible. E.g.

- hosts: your_hosts
  vars:
    ansible_become: true
  environment:
    http_proxy: "{{ proxy_server }}"
    https_proxy: "{{ proxy_server }}"
    no_proxy: "{{ no_proxy }}"

I'm fairly sure you can even do it at the task level if needed.

agrimal commented 2 weeks ago

These are already set in my task :

- name: Create gitlab project
  environment:
    http_proxy: "{{ proxy }}"
    http_proxys: "{{ proxy }}"
  community.general.gitlab_project:
    api_url: "{{ api_url }}"
    api_token: "{{ api_token }}"
    name: "{{ name }}"
    group: "{{ group }}"
    initialize_with_readme: true
  delegate_to: localhost
  become: false
nejch commented 2 weeks ago

@agrimal haha sorry I misread the initial description.

So you just have a typo. It should be https_proxy, not http_proxys. Since your GitLab instance is likely served over HTTPS that's the one that matters.

agrimal commented 2 weeks ago

OMG thanks for pointing out this typo... Works better now ! I'm closing this non-issue