Repository: ansible/ansible
Pull request: Deprecate support for the v2 galaxy API
##### SUMMARY

Deprecate support for the v2 galaxy API. Fixes #81781

##### ISSUE TYPE

- Bugfix Pull Request

##### ADDITIONAL INFORMATION

The v2 API is being removed in https://github.com/pulp/pulp_ansible/pull/1701

GalaxyNG and the new community galaxy do not include the v2 API.

The plan is likely to backport this to 2.16, and then just remove the functionality from devel for 2.17.

Problem statement:
Deprecate and remove Galaxy v2 API support
### Summary

With the migration of galaxy.ansible.com to GalaxyNG, the v2 API should no longer be used anywhere.  OG Galaxy was the only supported server that implemented the v2 API, and with it being decommissioned, it's probably best to remove it from our code.

I recommend deprecating first, if the client selects a v2 API endpoint, as there are some 3rd party servers that mimic the v2 API.

The v2 APIs we are using from `pulp_ansible` in CI, are largely unmaintained, except by @sivel to facilitate testing the v2 code paths in ansible-galaxy in core CI.

### Issue Type

Feature Idea

### Component Name

`ansible-galaxy`
`lib/ansible/galaxy/api.py`

### Additional Information

N/A

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct

Hints from issue discussion:
Files identified in the description:

* [`bin/ansible-galaxy`](https://github.com/ansible/ansible/blob/devel/bin/ansible-galaxy)

If these files are incorrect, please update the `component name` section of the description or use the [component](https://github.com/ansible/ansibotmini#ansibotmini) bot command.

<!--- boilerplate: components_banner --->

Commit message: clog frag

Patch to review:
diff --git a/changelogs/fragments/deprecate-v2-galaxy-api.yml b/changelogs/fragments/deprecate-v2-galaxy-api.yml
new file mode 100644
index 00000000000000..a0513da5063a01
--- /dev/null
+++ b/changelogs/fragments/deprecate-v2-galaxy-api.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- ansible-galaxy - Deprecate use of the Galaxy v2 API (https://github.com/ansible/ansible/issues/81781)
diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py
index d4508c041237c1..2bd99a424bc489 100644
--- a/lib/ansible/galaxy/api.py
+++ b/lib/ansible/galaxy/api.py
@@ -133,6 +133,15 @@ def wrapped(self, *args, **kwargs):
                                    % (method.__name__, ", ".join(versions), ", ".join(available_versions),
                                       self.name, self.api_server))
 
+            # Warn only when we know we are talking to a collections API
+            if 'v1' not in versions and {'v3'}.difference(available_versions) == {'v3'}:
+                display.deprecated(
+                    'The v2 Ansible Galaxy API is deprecated and no longer supported. '
+                    'Ensure that you have configured the ansible-galaxy CLI to utilize an '
+                    'updated and supported version of Ansible Galaxy.',
+                    version='2.17'
+                )
+
             return method(self, *args, **kwargs)
         return wrapped
     return decorator


Code review comments:
diff_hunk: @@ -133,6 +133,15 @@ def wrapped(self, *args, **kwargs):
                                    % (method.__name__, ", ".join(versions), ", ".join(available_versions),
                                       self.name, self.api_server))
 
+            # Warn only when we know we are talking to a collections API
+            if 'v1' not in versions and {'v3'}.difference(available_versions) == {'v3'}:
path: lib/ansible/galaxy/api.py
text: @user1:
```suggestion
            if common_versions == {'v2'}:
```
Wouldn't this be easier to read and also not trip a false error message on a hypothetical `v4` only server?

@author:
hrm, seems like it would be functional, just need to think it through again.