Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
blog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
blog
Commits
94ec9caa
Commit
94ec9caa
authored
9 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
- New post about Ansible modules sharing with git submodule.
parent
a3195365
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
content/ansible-modules.rst
+49
-0
49 additions, 0 deletions
content/ansible-modules.rst
with
49 additions
and
0 deletions
content/ansible-modules.rst
0 → 100644
+
49
−
0
View file @
94ec9caa
Sharing Ansible modules
#######################
:date: 2015-11-15
:summary: How to share Ansible modules
With Ansible you're expected to share roles with the Ansible Galaxy tool (either
through the `Ansible Galaxy hub <https://galaxy.ansible.com/>`_ or just using
straight git repositories). This works well enough (and personally I am using
``ansible-galaxy init`` to start each new role, even those that I'm not going to
share with the community). However, for sharing modules there is no such easy
solution, or is it?
Sharing with git submodule
--------------------------
I'd like to start by saying that git submodule is the poor man's package
manager and it's lack of popularity is (somewhat) justified. However, this is a
nice demostration of a case where there is no package manager available and of
using git submodule instead. Also, I've only been able to use this technique for
modules written in Python, which is nice considering the lack of boiler-plate
that Ansible provides and that Python is my personal preference.
The whole stroy is really quite simple, create a seperate git repository with
the modules in it. You can put them in subdirectories and as a far as I know,
there's no restriction on the hierarchy depth. In your playbook directory create
a ``library`` directory (the Ansible default, so you can change this in
``ansible.cfg``) and create an empty ``__init__.py`` file inside that directory.
Add a git submodule inside that directory and you're done. Let's see an
example::
git init ansible-modules
cd ansible-modules
# Write great module
git commit -a
git push
cd /path/to/your/ansible/playbook/repository
mkdir library
touch library/__init__.py
git submodule add host:/path/to/ansible-modules library/my_modules
git add .gitmodules
git commit
git push
Really, not that complicated. The only magic (undocumented) bit is creating a
``__init__.py`` file inside the ``library`` directory, which is a shame that the
Ansible documentation doesn't cover that. If you want to see a real-life
example, checkout my `ansible-playbooks
<https://www.shore.co.il/cgit/ansible-playbooks>`_ and `ansible-modules
<https://www.shore.co.il/cgit/ansible-modules>`_ git repos.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment