If you wish to contribute code, please consider the following:
- Code should be reasonably PEP8-like. I'm not too strict on this.
- One logical change per merge request.
- By putting in a merge request or putting code in comments, you automatically grant me permission to include this code in ansible-cmdb under the license (GPLv3) that ansible-cmdb uses.
- Please don't be disappointed or angry if your contributions end up unused. It's not that they aren't appreciated, but I can be somewhat strict when it comes to code quality, feature-creep, etc.
When in doubt, just open a pull-request and post a comment on what you're unclear of, and we'll figure it out.
Here's a quick introduction on how ansible-cmdb works internally.
- The main section in
ansible-cmdb
reads the commandline params and instantiates anAnsible
object. - The
Ansible
object first reads in all the facts by callingAnsible.parse_fact_dir()
for each argument. This includes the user-extended facts. - If hosts file(s) should be parsed (
-i
option), ansible callsAnsible.parse_hosts_inventory()
. This first reads in all found hosts files into one big string, and then it parses it. For this it uses theAnsibleHostParser
class. - The
AnsibleHostParser
class first parses the inventory and then creates a dictionary with all known ansible node names (hosts) as the keys, but with empty values. It then goes through the 'children', 'vars' and normal sections from the inventory and applies the found information to the hosts dictionary. - When
AnsibleHostParser
is done, theAnsible
class takes all the parsed hosts information and updates its own version of the hosts dictionary. - Finally, the output is generated by the main section.
Updating a host in the Ansible
object is done using the Ansible.update_host
method. This method does a deep-update of a dictionary. This lets ansible-cmdb
overlay information from the facts dir, extended / manual facts and hosts
inventory files.
If you want to run ansible-cmdb directly from the Git repo:
$ cd ansible-cmdb
$ export PYTHONPATH="$(readlink -f lib)"
$ src/ansible-cmdb
For building, make
is used. Here are some useful targets:
make test
: build some tests.make release
: build a release.make clean
: remove build and other artifacts.
To build Debian, RedHat and source-packages for ansible-cmdb you'll need a Debian based operating system and you'll have to install the following dependencies:
- git
- make
- python-markdown
- zip
- fakeroot
- alien
- Python 'wheel' package
You can then build the packages with
make release REL_VERSION=$VERSION
where $VERSION
is a (arbitrary) version number.
In order to build releases, your repository will have to be completely clean: everything must be commited and there must be no untracked files. If you want to build a test release, you can temporary stash your untracked changes:
git stash -u
Testing releases:
Running from github source:
$ cd ansible-cmdb
$ export PYTHONPATH=lib
$ src/ansible-cmdb examples/out > ~/cmdb.html
$ src/ansible-cmdb -i examples/hosts examples/out > ~/cmdb.html
$ src/ansible-cmdb -p local_js=1 -i examples/hosts examples/out > ~/cmdb.html
Installing from github source:
$ cd ansible-cmdb
$ sudo python ./setup.py install
$ ansible-cmdb ansible-cmdb/examples/out > ~/cmdb.html
$ ansible-cmdb -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html
$ ansible-cmdb -p local_js=1 -i ansible-cmdb/examples/hosts ansible-cmdb/examples/out > ~/cmdb.html
$ sudo pip uninstall mako
$ sudo pip uninstall pyyaml
$ sudo pip uninstall ansible-cmdb
$ sudo rm /usr/local/bin/ansible-cmdb
Installing from source tarbal:
$ tar -vxzf ansible-cmdb-*.tar.gz
$ cd ansible-cmdb-*
$ sudo make install
$ ansible-cmdb out > ~/cmdb.html
$ ansible-cmdb -i hosts out > ~/cmdb.html
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
$ cd ansible-cmdb-*
$ sudo make uninstall
Installing from .deb file:
$ dpkg -i -i ansible-cmdb-*.deb
$ ansible-cmdb out > ~/cmdb.html
$ ansible-cmdb -i hosts out > ~/cmdb.html
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
$ sudo dpkg --purge ansible-cmdb
Installing from .rpm file:
$ sudo yum install ansible-cmdb*.rpm
$ ansible-cmdb out > ~/cmdb.html
$ ansible-cmdb -i hosts out > ~/cmdb.html
$ ansible-cmdb -p local_js=1 -i hosts out > ~/cmdb.html
$ sudo yum uninstall ansible-cmdb