How to specify author and version of a dependency of a role?

Here in the docs the way to define dependencies for a role is described.

But since role is often a reusable module, it must specify its exact dependencies to be independent from whatever roles user have in his “roles” folder. If I define dependency like postgres in my role how would I ensure, that the postgres role is exactly that role what I used when built my dependent role - so it takes all variables which I expected and works as expected in general?

You control which roles are installed on your system, so that is really a matter of personal preference. If you use the ansible-galaxy tool to install roles from galaxy.ansible.com, you can specify both the version of the role (if the author is using versions) as well as the directory to save the role. That way, you could have multiple versions of the same role if you needed to.

The author and other information about each role is stored in the roles meta/main.yml, but is not used when declaring the dependency.

Yes, but I can't control what user of my role will have installed. And user do not want to dig through all downloaded roles guessing which exactly version from which author he need to be sure that nothing will break.
Is there some reason behind that Ansible does not take in attention versions like Pip for example? With Pip I can just set exact versions of dependencies that I need to run my project, and don't worry about anything, but this option is absent in Ansible, where there is a similar use case.

“Is there some reason behind that Ansible does not take in attention versions like Pip for example?”

Ansible-galaxy (you mean ansible-galaxy, not ansible) here, as a command line tool does take requirements files.

You can easily have one like

username1.rolename2,1.2.3
username3.rolename4,4.5.6

and use it just like a pip requirements file

We’ve also said we’re happy to entertain pull requests to add more features to the galaxy CLI, if you find something else in need of upgrades.

How pull requests for Ansible are happen? Do I need to create an issue on GitHub at first?

Thoughts on topic:

from the user perspective:

  • I want to have option to automatically install all needed dependencies to run my playbook (Berkshelf can do that, but it, as well as Chef - pretty unpythonic tool)

from roles developer perspective:

  • I want to specify dependencies in a way that user who will use it will be able to fetch them and run my role in same environent as I intend.

issues that that features lead to:

  • How to solve version clashes between roles?

PS
Can I specify versions in meta/main.yml in such format: username1.rolename2,1.2.3?

Hi,
Using a “galaxy.yml” file as describe by Michael is pretty useful. (check an example there: https://github.com/guillaumededrie/ansible-private-cloud).

PS
Can I specify versions in meta/main.yml in such format: username1.rolename2,1.2.3?

I don’t see any of this https://github.com/ansible/ansible/blob/devel/bin/ansible-galaxy#L707.

I’m adding a thought:

  • How to handle role which are not on the Galaxy repository ?

(gitmodule ? Galaxy command improvements to add direct link to meta/main.yml from a repository ? …)

Regards,

How pull requests for Ansible are happen? Do I need to create an issue on
GitHub at first?

No, just submit the pull request. Pull requests are also issue tickets for
GitHub.

Thoughts on topic:

from the user perspective:

- I want to have option to automatically install all needed dependencies
to run my playbook (Berkshelf can do that, but it, as well as Chef - pretty
unpythonic tool)

ansible-galaxy's CLI already does this.

I'm adding a thought:
- How to handle role which are not on the Galaxy repository ?
(gitmodule ? Galaxy command improvements to add direct link to
meta/main.yml from a repository ? ...)

I'd be very open to taking pull requests to teach ansible-galaxy about
dependencies outside of Galaxy, such as git repos.

I'd probably suggest a syntax like git:// and
ssh://user[:password]@hostname/foo/foo.git, etc.