Commit 51d80e52 authored by Florian Kempenich's avatar Florian Kempenich
Browse files

Move location of the generated inventory

parent 513ca043
# This is a generated ansible inventory of all droplet created with the `ansible-droplet` tool
#
# You can link this inventory in your own playbook, and run tasks/roles out of the box.
#
......@@ -54,9 +54,9 @@
Hostname {{ created.droplet.ip_address }}
User root
- name: "Add Droplet as Ansible Host in `inventory/ansible-machines`"
- name: "Add Droplet as Ansible Host in `~/.ansible-droplet-inventory`"
blockinfile:
path: "{{ ansible_env.PWD }}/inventory/ansible-machines"
path: "{{ ansible_env.HOME }}/.ansible-droplet-inventory"
state: present
create: yes
marker: "# {mark} Ansible-managed DigitalOcean Droplet: '{{ droplet_name }}'"
......
......@@ -35,9 +35,8 @@
state: absent
marker: "# {mark} Ansible-managed DigitalOcean Droplet: '{{ droplet_name }}'"
- name: "Remove Droplet from Ansible Host in `inventory/ansible-machines`"
- name: "Remove Droplet from Ansible Host in `~/.ansible-droplet-inventory`"
blockinfile:
path: "{{ ansible_env.PWD }}/inventory/ansible-machines"
path: "{{ ansible_env.HOME }}/.ansible-droplet-inventory"
state: absent
marker: "# {mark} Ansible-managed DigitalOcean Droplet: '{{ droplet_name }}'"
import click
import os.path
from os import symlink
import subprocess
SCRIPT_DIR = os.path.dirname(__file__)
......@@ -8,6 +9,9 @@ ANSIBLE = os.path.join(SCRIPT_DIR, 'ansible')
REQUIREMENTS = 'roles/roles-on-droplet/roles-from-ansible-galaxy'
CONFIGURATION = 'group_vars'
CONFIGURATION_FILE = 'all'
INVENTORY = 'inventory'
INVENTORY_DROPLETS_LINK = 'ansible-droplets'
INVENTORY_DROPLETS_FILE = '.ansible-droplet-inventory'
CREATE_PLAYBOOK = 'create-droplet-playbook.yml'
DESTROY_PLAYBOOK = 'delete-droplet-playbook.yml'
......@@ -34,6 +38,9 @@ def _set_configuration_if_needed():
ssh_key, do_token = _ask_for_configuration()
_create_configuration_file(ssh_key, do_token)
if not _has_droplet_inventory_symlink():
_create_droplet_inventory_symlink()
def _is_configured():
return os.path.isfile(os.path.join(ANSIBLE, CONFIGURATION, CONFIGURATION_FILE))
......@@ -51,6 +58,21 @@ def _create_configuration_file(ssh_key, do_token):
file.write('ssh_pub_key_to_load_on_droplet_location: "{0}"\n'.format(ssh_key))
file.write('digitalocean_token_location: "{0}"\n'.format(do_token))
def _has_droplet_inventory_symlink():
return os.path.islink(os.path.join(ANSIBLE, INVENTORY, INVENTORY_DROPLETS_LINK))
def _create_droplet_inventory_symlink():
inventory_link = os.path.join(ANSIBLE, INVENTORY, INVENTORY_DROPLETS_LINK)
inventory_file = os.path.join(os.path.expanduser("~"), INVENTORY_DROPLETS_FILE)
if not os.path.isfile(inventory_file):
raise AssertionError(
"Please ensure you didn't delete the generated inventory in the HOME dir\n" +
"In case you did, just create a new empty file at '{0}'".format(inventory_file)
)
symlink(inventory_file, inventory_link)
def _delete_current_configuration():
try:
os.remove(os.path.join(ANSIBLE, CONFIGURATION, CONFIGURATION_FILE))
......
from setuptools import setup
from os.path import expanduser
HOME = expanduser("~")
def readme():
with open('README.md') as f:
......@@ -6,7 +9,7 @@ def readme():
setup(
name='ansible-droplet',
version='0.1.3',
version='0.2.0',
description='A cli to Create / Destroy DigitalOcean Droplets',
long_description=readme(),
keywords='digitalocean digital ocean droplet ansible ssh provision',
......@@ -29,7 +32,7 @@ setup(
'dopy==0.3.5',
'click'
],
data_files=[(HOME, ['.ansible-droplet-inventory'])],
include_package_data=True,
zip_safe=False
)
# TODO: Investigate the `zip_safe` option
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment