Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using ansible modules from git repository?

I have a playbook and a bunch of modules I wrote.

Now I want to reuse the same modules in my next playbook for a different project.

I really want to push those modules to a public git repository and then somehow tell ansible to use the modules from the git repository.

(kinda like npm package.json referencing github)

I can't seem to find any documentation on how to do that.

For now, I am using a workaround where I tell people to npm install the repository, and then define ANSIBLE_LIBRARY variable.

How can I tell the playbook to load modules from a github repository or some other remote location?

like image 561
guy mograbi Avatar asked Jan 21 '16 07:01

guy mograbi


People also ask

How do I run Ansible from GitHub?

In the navigation pane, choose Run Command. If the AWS Systems Manager home page opens first, choose the menu icon ( ) to open the navigation pane, and then choose Run Command. Choose Run command. In the Command document list, choose AWS-RunRemoteScript .

How do I clone a git repository in Ansible?

Cloning a Git Repository with Ansible playbook In the playbook above, you started by defining a new task and gave it the name “Clone a GitHub repository". Next, you are using the git module to specify the link to the SQLite GitHub repository. You then proceed to define the destination for the cloned repository.

How do you use Ansible pull?

The ansible-pull command, which is part of Ansible, allows you to download your configuration from a Git repository and apply it immediately. You won't need to maintain a server or an inventory list; you simply run the ansible-pull command, feed it a Git repository URL, and it will do the rest for you.


1 Answers

Actually modules can be nested inside roles since quite a long time. Since Ansible 2 this even is possible with most of the plugins.

The folders where the modules & plugins need to be stored inside the role is the same as on playbook level. Modules go into library, plugins go into *_plugins (action_plugins, callback_plugins, filter_plugins etc)

To make the module/plugin then available the role has to be applied to the playbook (or added as a dependency of another role)

Only exception known to me are variable plugins and that perfectly makes sense. Since variable plugins are executed when the inventory is read, which happens before roles are interpreted.

vars_plugins still can be distributed in roles, but the path needs to be added in the ansible.cfg. Fortunately you can also use wildcards in paths:

vars_plugins = roles/*/vars_plugins

And no, all of this is not documented in any way. :)

Finally, to distribute roles you can use Ansible Galaxy:

ansible-galaxy install foo

Nothing wrong with directly using git. Ansible Galaxy actually only is a tool to install git repositories. But since Galaxy is the Ansible standard I suggest to at least provide a Galaxy compatible format. A good (best?) practice how to install Galaxy roles separate from the projects roles can be found here.

Here's an example for an action plugin: https://galaxy.ansible.com/udondan/ssh-reconnect/

like image 156
udondan Avatar answered Oct 03 '22 12:10

udondan