Shields: Support for Ansible Galaxy

Created on 22 Oct 2014  Â·  14Comments  Â·  Source: badges/shields

There's a REST API available at.

good first issue service-badge

Most helpful comment

@smiller171 here's a one-liner for finding your role's ID once it's on Galaxy:

$ ansible-galaxy info YourUser.RoleName | grep -E 'id: [0-9]' | awk {'print $2'}

This works on Ansible 2.2.2.0 but I recon it's working on older versions, too.

All 14 comments

All this information is greatly appreciated!

Lacking knowledge about Ansible, however, it is difficult for me to understand which kind of badge I can provide.

How thoughtful of me :-) I will look into it...

Hi, @espadrine!
For example, I have some ansible role at https://github.com/ansible-roles/ansible-role-sublimetext3_packagecontrol and published at Galaxy https://galaxy.ansible.com/list#/roles/3078

So, 3078 is the role ID that used in API calls.

I think there will be cool if next badges for ansible will be available at shields.io:

| Badge Name | API Call URL | Keys used to generate result | Result / Badge Value example |
| --- | --- | --- | --- |
| Role name | https://galaxy.ansible.com/api/v1/roles/3078/ | summary_fields->owner->username + '.' + name | igor_mukhin.sublimetext3_packagecontrol |
| Minimum ansible version | https://galaxy.ansible.com/api/v1/roles/3078/ | min_ansible_version | 1.4 |
| Versions count (not sure this badge will be popular, but who knows) | https://galaxy.ansible.com/api/v1/roles/3078/versions/ | count | 3 |
| Latest version | https://galaxy.ansible.com/api/v1/roles/3078/versions/ | first(results)->name | v0.2.0 |

To generate all this badges we need get only role ID from user. Or even just role's galaxy URL and then automatically extract ID from hash.

Thanks a lot for this information! That is tremendously helpful.

I notice that they send a cookie (Set-Cookie: sessionid=oxd81rvw70noo42xqwg594t6ngc8ncsq; expires=Mon, 25-May-2015 19:16:28 GMT; httponly; Max-Age=1209600; Path=/), that is a bit odd. Otherwise, it all seems straightforward.

@espadrine Don't think that cookies matter something.
You can just get information and not care about cookies.

Try wget -qO - https://galaxy.ansible.com/api/v1/roles/3078/versions/.

@espadrine Hi. How can I help you to force some progress on this?

I tried making the first one, with this kind of style:

I am unsure of whether that suits the notion of "role" that users are familiar with, or how easy it is to figure out where to find the role id.

Oh, cool :)

Role Id assigned to role once it added to galaxy.
For example this is list of my roles: https://galaxy.ansible.com/list#/users/9737

@igormukhingmailcom does getting the information like this still work? I can't find IDs on my roles.

Ansible galaxy 2 uses "name based" urls now, but old urls should be
redirected.

On Friday, 19 February 2016, Scott Miller [email protected] wrote:

@igormukhingmailcom https://github.com/igormukhingmailcom does getting
the information like this still work? I can't find IDs on my roles.

—
Reply to this email directly or view it on GitHub
https://github.com/badges/shields/issues/286#issuecomment-186050323.

Sounds like we probably need a PR to fix this functionality then

@smiller171 here's a one-liner for finding your role's ID once it's on Galaxy:

$ ansible-galaxy info YourUser.RoleName | grep -E 'id: [0-9]' | awk {'print $2'}

This works on Ansible 2.2.2.0 but I recon it's working on older versions, too.

Since this issue comes up at the top of the result list when searching for how to get a badge that shows the latest version of a collection on Ansible Galaxy, I'll post our solution for that.

Ansible Galaxy returns the latest version of a collection using an HTTP GET on
https://galaxy.ansible.com/api/v2/collections/{NS}/{COLL}/ as follows:

{
    . . .
    "latest_version": {
        "version": "1.0.0-dev1",
    }
}

That allows using the dynamic badge creation feature of shields.io, e.g. in Markdown syntax:

![Version on Galaxy](https://img.shields.io/badge/dynamic/json?style=flat&label=galaxy&prefix=v&url=https://galaxy.ansible.com/api/v2/collections/ibm/ibm_zos_core/&query=latest_version.version)

Resulting in this badge:

Version on Galaxy

Thanks for sharing @andy-maier! Given the above, it seems like we should be able to add a native version badge if you or anyone else would be interested in submitting a PR

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rominf picture rominf  Â·  3Comments

chadwhitacre picture chadwhitacre  Â·  4Comments

calebcartwright picture calebcartwright  Â·  3Comments

niccokunzmann picture niccokunzmann  Â·  3Comments

paulmelnikow picture paulmelnikow  Â·  3Comments