Create configuration files using templates that receive
Project description
DigitalOcean APIv2 data and droplet metadata, plus user variables, for example, to create SSH config files or ansible host inventories. Home-page: https://github.com/buanzo/digitalocean-metawrite Author: Arturo “Buanzo” Busleiman Author-email: buanzo@buanzo.com.ar License: GPLv3 Description: # DigitalOcean Meta-Write
dometawrite is a tool that helps system administrators take information from the DigitalOcean API and/or Dropleta Metadata API to create text files such as configuration files, status pages or anything else that can be coded in a template.
Templates are written using the most-excellent Jinja2 library for Python.
# Example: Create SSH client configuration
dometawrite can be used to create an OpenSSH SSH Client configuration file that can be included from ~/.ssh/config for easy access to your droplets. Picture this:
- ~ $ dometawrite –template ssh-config
–api-key $DO_API_KEY –output /home/example/.ssh/digitalocean_droplets –template-var=user:root –template-var=keyfile:/home/example/id_rsa_digitalocean
The above command will render the ssh-config dometawrite template, and write the output to the /home/example/.ssh/digitalocean_droplets file.
It will use the indicated DigitalOcean API KEY, and will also provide some additional variables to the template. If any variables are missing from the command line, dometawrite will let you know.
The resulting output may look like this:
Host droplet-name HostName droplet_ip_address User root IdentityFile /home/example/id_rsa_digitalocean
Host another_droplet HostName yet_another_ip User root IdentityFile /home/example/id_rsa_digitalocean
As long as the id_rsa_digitalocean.pub file has been added to the droplet, either during creation or afterwards, then you will be able to simply:
# Example: Create ansible inventory
Maybe you use ansible, and you want to update your hosts inventory dynamically:
- dometawrite –template ansible-inventory
–api-key $DO_API_KEY –output /etc/ansible/hosts/digitaloceaninventory
The template will receive a python dictionary with all necessary information. Jinja2 supports advanced logic, so it can easily contain all the required code to output a valid Ansible Inventory file.
# Templating Ideas
Templates will have to indicate endpoint requirements. For example, for the ssh-config template:
{% set required_endpoints = [‘/v2/droplets’] %} {% for droplet in droplets.droplets %} Host {{ droplet.name }} etcetc
{% endfor %}
Keywords: configuration,api,templates,digitalocean,devops,sysadmin Platform: UNKNOWN Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: Intended Audience :: System Administrators Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Natural Language :: English Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: POSIX :: Other Classifier: Operating System :: POSIX Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: Implementation :: PyPy Requires-Python: >=3.6
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dometawrite-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 444607eaced1bfb9c932a1caf8c37fda94c2fa47f077bd0b7c3efa4cc66cf0db |
|
MD5 | ef4095a7e0fc92902ddc449c2df93967 |
|
BLAKE2b-256 | 93a14d5b50829268249ec05a1aa7429c5ee5c13eabc728700635e8a834a7482c |