{ "info": { "author": "Alexandros Solanos", "author_email": "solanosalex@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Digital ocean -> ssh config\n\nInstallation\n\n```\npython3 -m pip install python-digitalocean-ssh\n```\n\nRunning standalone, this python 3 script will help you keep your ssh config in sync with your digital ocean droplets\n\n```bash\n$ python3 -m digitalocean_ssh production\n\n\u00b7 Reading /home/alex/.config/python-digitalocean-ssh/production.json\n\u00b7 Parsing /home/alex/.ssh/config\n\u00b7 Fetching droplets from DO\n\u00b7 Writing into your ssh config file\n\n\u2713 Done, 11 droplets synced\n```\n\n## Features\n\n* Supports different ssh keys for each droplet, depending on the DO tags of the droplet\n* Works with different configurations and can write in different sections of your ssh config\n\n## How to\n\n### Step 1: Create the json configuration file\nSave this at `~/.config/python-digitalocean-ssh/.json`, where `` is how you want to call it, e.g. `production` or `testing` or anything else. For this example I will use `production`.\n\n```json\n{\n \"token\": \"DIGITAL_OCEAN_READ_ONLY_TOKEN_HERE\",\n \"keys\": {\n \"tagToKey\": {\n },\n \"default\": {\n \"key\": \"common\",\n \"priority\": 0\n }\n },\n \"startMark\": \"# DO production\",\n \"endMark\": \"# /DO production\",\n \"hostPrefix\": \"do-prod-\"\n}\n```\n*Note*: This is the simplest possible configuration file that uses the same key for every droplet and the droplet name as `Host`, for more options, read on.\n\n1. Generate a new personal DO API read-only access token [here](https://cloud.digitalocean.com/account/api/tokens)\n2. `hostPrefix` is what prefix to add in the `Host` key in your ssh config for each droplet loaded through this configuration, can be anything you want\n\n### Step 2: Add the 2 marks in your ssh config\nThe above json configuration contains the `startMark` and `endMark`. These should be somewhere inside your ssh configuration and can be whatever you want (start with `#` for ssh config comments, though):\n```ssh\n# DO production\n# /DO production\n```\n\nBetween these 2 marks the script will **delete** everything and add the new entries. Be careful not to add your own hosts between these 2 marks.\n\n

\n \n

\n\n### Step 3: Run the script\n\n```bash\n$ python3 -m digitalocean_ssh production\n\n\u00b7 Reading /home/alex/.config/python-digitalocean-ssh/production.json\n\u00b7 Parsing /home/alex/.ssh/config\n\u00b7 Fetching droplets from DO\n\u00b7 Writing into your ssh config file\n\n\u2713 Done, 11 droplets synced\n```\n\nNow your ssh config will look like this:\n```ssh\n# DO production\nHost do-prod-control-center1517024146\n # control-center1517024146\n Hostname X.X.X.X\n IdentityFile ~/.ssh/common\n User user\nHost do-prod-control-center1517027030\n # control-center1517027030\n Hostname X.X.X.X\n IdentityFile ~/.ssh/common\n User user\n... 9 more entries\n# /DO production\n```\n\nIf you have autogenerated ugly `Host` names derived from the droplet names, you can make it work with the droplet tags instead; read on.\n\n# Use this as a module\n\nWith the configuration files at the appropriate place, you can use this as a module to create powerful python scripts:\n```python\nfrom digitalocean_ssh import DO\nimport sys\n\nclient = DO(True) # enable debugging\n\nconfig_type = sys.argv[1] # must pass the configuration type as an argument, e.g. 'production'\n\nconfig = client.get_config(config_type)\nssh_config = client.parse_ssh_config(config)\ndroplets = client.fetch_droplets(config)\n\nprint(droplets) # DO droplets with combined ip/tags/ssh config information\n```\n\n## I want to use a different ssh key, not `common`!\n\n* Change the `keys.default.key` setting\n\n## I want to use a different ssh key per droplet tag!\n\n* Change the `keys.tagToKey` setting and add in it entries like:\n\n```json\n\"control-center\": {\n \"key\": \"cc_prv\",\n \"priority\": 7\n},\n\"consul-server\": {\n \"key\": \"cs_prv\",\n \"priority\": 6\n},\n\"postgres-master\": {\n \"key\": \"common\",\n \"priority\": 5\n}\n```\n\nThe final config will look like this:\n\n```json\n{\n \"token\": \"DIGITAL_OCEAN_READ_ONLY_TOKEN_HERE\",\n \"keys\": {\n \"tagToKey\": {\n \"control-center\": {\n \"key\": \"cc_prv\",\n \"priority\": 7\n },\n \"consul-server\": {\n \"key\": \"cs_prv\",\n \"priority\": 6\n },\n \"postgres-master\": {\n \"key\": \"common\",\n \"priority\": 5\n }\n },\n \"default\": {\n \"key\": \"common\",\n \"priority\": 0\n }\n },\n \"startMark\": \"# DO production\",\n \"endMark\": \"# /DO production\",\n \"hostPrefix\": \"do-prod-\"\n}\n```\n\n*Important*: A droplet can have more than 1 tag, that's why there's a field called `priority` there. In the above example, if a droplet has both the `control-center` and `consul-server` tags, it will use the key with the higher priority (here `control-center`). If a droplet has no tags or its tags do not appear in `tagToKey`, it will use the default key.\n\nFor the droplets that match a specific tag, now the `Host` in the ssh config will have the name of the tag, not the droplet name:\n\n```ssh\n# DO production\nHost do-prod-control-center\n # control-center1517024146\n Hostname X.X.X.X\n IdentityFile ~/.ssh/cc_prv\n User user\nHost do-prod-control-center2\n # control-center1517027030\n Hostname X.X.X.X\n IdentityFile ~/.ssh/cc_prv\n User user\n... more entries\n# /DO production\n```\n\nThis is convenient for large environments where the droplet names are autogenerated\n\n*Note*: The droplet name is still visible as a comment in the first line of each entry\n\n*Note*: As shown in the above example, if 2 or more droplets share the same tag, an ascending number is appended to the `Host` value.\n\nNow you can see everything easily using ssh's tab completion, and connect anywhere:\n```\n$ ssh do-prod- \n\ndo-prod-control-center do-prod-mongodb do-prod-load-balancer do-prod-nodejs2 do-prod-postgres-slave do-prod-blog\ndo-prod-control-center2 do-prod-landing-page do-prod-nodejs do-prod-postgres-master do-prod-redis \n```\n\n## I have production *and* testing and I work in 10 different companies!\n\nSimply create different configuration files under `~/.config/python-digitalocean-ssh/`, one for each use case of yours, like `production.json` and `testing.json`. It will be useful to have a different `hostPrefix` for each use case.\n\nAlso, add the different markings in your ssh config file, e.g.:\n\n```ssh\n# DO production\n# /DO production\n\n# DO testing\n# /DO testing\n```\n\nNow if you run\n```bash\n$ python3 -m digitalocean_ssh production\n```\nit will go on and read from `production.json` and write in the corresponding marking inside your ssh config. And if you run\n```bash\n$ python3 -m digitalocean_ssh testing\n```\nit will go on and read from `testing.json` and write in the corresponding marking.\n\n\n## Can I safely re-run the script any times I want?\n\nYes, provided that you haven't included any entries of yours between the markings you've specified in the configuration. Everything between the markings is deleted each time the script runs.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hytromo/digital-ocean-to-ssh-config", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "python-digitalocean-ssh", "package_url": "https://pypi.org/project/python-digitalocean-ssh/", "platform": "", "project_url": "https://pypi.org/project/python-digitalocean-ssh/", "project_urls": { "Homepage": "https://github.com/hytromo/digital-ocean-to-ssh-config" }, "release_url": "https://pypi.org/project/python-digitalocean-ssh/0.0.8/", "requires_dist": [ "python-digitalocean" ], "requires_python": "", "summary": "Combine DO droplets with your ssh configuration", "version": "0.0.8" }, "last_serial": 4257815, "releases": { "0.0.8": [ { "comment_text": "", "digests": { "md5": "fd5bbe96bee6bab7f4be987848e3e826", "sha256": "fabe74d266a8ac8bda6467df63db046d12bd25bc3c559cdc792767ee0089a844" }, "downloads": -1, "filename": "python_digitalocean_ssh-0.0.8-py3-none-any.whl", "has_sig": false, "md5_digest": "fd5bbe96bee6bab7f4be987848e3e826", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5947, "upload_time": "2018-09-10T14:01:00", "url": "https://files.pythonhosted.org/packages/ad/f1/d499cb686d439b410792978877679cb7cf20c6c6a6ace601b643e73bab6d/python_digitalocean_ssh-0.0.8-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "54fb62db7901a8fdabca24b894a273e8", "sha256": "058b5ebb203384a45fdecee5eeee4aee2469578f734b1c4129854f2614de45b3" }, "downloads": -1, "filename": "python-digitalocean-ssh-0.0.8.tar.gz", "has_sig": false, "md5_digest": "54fb62db7901a8fdabca24b894a273e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5668, "upload_time": "2018-09-10T14:01:02", "url": "https://files.pythonhosted.org/packages/21/d6/82f054d8e2074521e52d28027ff310e1943c2cac693bc29007cda7568f56/python-digitalocean-ssh-0.0.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fd5bbe96bee6bab7f4be987848e3e826", "sha256": "fabe74d266a8ac8bda6467df63db046d12bd25bc3c559cdc792767ee0089a844" }, "downloads": -1, "filename": "python_digitalocean_ssh-0.0.8-py3-none-any.whl", "has_sig": false, "md5_digest": "fd5bbe96bee6bab7f4be987848e3e826", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5947, "upload_time": "2018-09-10T14:01:00", "url": "https://files.pythonhosted.org/packages/ad/f1/d499cb686d439b410792978877679cb7cf20c6c6a6ace601b643e73bab6d/python_digitalocean_ssh-0.0.8-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "54fb62db7901a8fdabca24b894a273e8", "sha256": "058b5ebb203384a45fdecee5eeee4aee2469578f734b1c4129854f2614de45b3" }, "downloads": -1, "filename": "python-digitalocean-ssh-0.0.8.tar.gz", "has_sig": false, "md5_digest": "54fb62db7901a8fdabca24b894a273e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5668, "upload_time": "2018-09-10T14:01:02", "url": "https://files.pythonhosted.org/packages/21/d6/82f054d8e2074521e52d28027ff310e1943c2cac693bc29007cda7568f56/python-digitalocean-ssh-0.0.8.tar.gz" } ] }