digitalocean-inventory

An Ansible dynamic inventory for DigitalOcean.

MIT License

Downloads
72
Stars
2
Committers
1

DigitalOcean inventory

An Ansible dynamic inventory for DigitalOcean.

Installing

pip install digitalocean-inventory

Documentation

Documentation and more detailed examples are hosted on Github Pages.

Usage

Export the project environment variables:

export DO_PROJECT=example
export DO_ENV=production
export DO_SSH_DIR=/Users/joel/.ssh/example

Export an access token:

export DO_ACCESS_TOKEN=<token>

The packages exposes the executable:

digitalocean-inventory --list

Tags and inventory metadata are compiled into the output:

{
  "meta": {
    "hostvars": {
      "123.123.123.123": {
        "ansible_python_interpreter": "/usr/bin/python3",
        "ansible_ssh_extra_args": "-o StrictHostKeyChecking=no",
        "ansible_ssh_private_key_file": "/Users/joel/.ssh/example/example-production-0"
      }
    }
  },
  "all": {
    "hosts": ["123.123.123.123"],
    "vars": {},
    "children": {}
  },
  "production": {
    "hosts": ["123.123.123.123"]
  },
  "manager": {
    "hosts": ["123.123.123.123"]
  }
}

The executable has support for host, list and debug flags:

usage: Digital ocean inventory [-h] [--host [HOST]] [--list [LIST]] [--debug [DEBUG]]
                               [--private-ips [PRIVATE_IPS]]

optional arguments:
  --host [HOST]
  --list [LIST]
  --debug [DEBUG]
  --private-ips [PRIVATE_IPS]

To use with the ansible-playbook cli:

inventory.py:

#!/usr/bin/env python

from digitalocean_inventory import fetch

if __name__ == '__main__':
    fetch()
ansible-playbook -i inventory.py <playbook>

You can consume the inventory in order to mutate it before outputting:

#!/usr/bin/env python

from digitalocean_inventory import fetch

if __name__ == '__main__':
    inventory = fetch(stdout=False)
    print(inventory)

Tooling

Dependencies

To install dependencies:

yarn install
pip install .[all]

Tests

To run tests:

thx test

Documentation

To generate the documentation locally:

thx docs

Linters

To run linters:

thx lint

Formatters

To run formatters:

thx format

Contributing

Please read this repository's Code of Conduct which outlines our collaboration standards and the Changelog for details on breaking changes that have been made.

This repository adheres to semantic versioning standards. For more information on semantic versioning visit SemVer.

Bump2version is used to version and tag changes. For example:

bump2version patch

Contributors

Remarks

Lots of love to the open source community!

Package Rankings
Top 24.12% on Pypi.org
Related Projects