Commit 8d3ae2c2 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[feature] add basic ansible appliance management

This is not ideal. Ansible has tons of issues when we launch it from
there, and the configuration become tedious.

It might be easier to deploy ansible on the frontend and rerun
everything inside, or to create a python script that deals with ansible
parent fddad11c
......@@ -38,3 +38,20 @@ required*
> ./ create
> ./ show
> ./ delete
# Appliance Management
Once a lease is active, you can manage an appliance on it using ansible. First,
output the required extra variables for ansible.
> ./ ansible-extra-vars <lease_name> <stack_name> <template_file> <chameleon_key> <image> > myextravars
Then call the ansible playbooks.
> ansible-playbook -e @myextravars --connection=local stack-create.yaml
Use can then ssh onto the front node and run your experiments.
To destroy the stack, before deleting the lease:
> ansible-playbook -e @myextravars --connection=local stack-delete.yaml
......@@ -9,6 +9,13 @@ import os
import os_client_config
from blazarclient import client as blazar_client
import keystoneauth1
import shade
def get_cloud_config(cloud=None):
"""Retrieve the config in clouds.yaml."""
config = os_client_config.OpenStackConfig()
return config.get_one(cloud)
def get_client(cloud=None):
......@@ -94,6 +101,27 @@ def do_list(argv):
print("No leases.")
def do_ansible_extra_vars(argv):
"""Output a JSON dict with parameters for ansible config."""
cloud = get_cloud_config(
client = get_client(
lease_list =
leases = [l for l in lease_list if l['name'] ==]
lease = leases.pop()
if leases:
print("WARNING: more than one lease with that name, using the first.")
reservation = lease['reservations'][0]
extra_vars = {'cloud_name':,
'stack_name': argv.stack,
'template_file': os.path.abspath(argv.template),
'key_name': argv.key,
'reservation_id': reservation['id'],
'node_count': reservation['min'],
'image': argv.image
print(json.dumps(extra_vars, indent=4))
def main():
parser = argparse.ArgumentParser(description='Chameleon Lease Helper')
parser.add_argument('--cloud', default=os.environ.get('OS_CLOUD'),
......@@ -126,6 +154,15 @@ def main():
parser_list = subparsers.add_parser("list", help="List all leases")
parser_extra = subparsers.add_parser("ansible-extra-vars",
help="generate extra-vars file")
parser_extra.add_argument("lease", help="Lease name")
parser_extra.add_argument("stack", help="Stack name")
parser_extra.add_argument("template", help="appliance template")
parser_extra.add_argument("key", help="User key name")
parser_extra.add_argument("image", help="Image name")
args = parser.parse_args()
if args.debug:
logger = logging.getLogger('keystoneauth')
# ansible
- hosts: localhost
- name: make stack available
name: "{{ stack_name }}"
state: present
cloud: "{{ cloud_name }}"
template: "{{ template_file }}"
key_name: "{{ key_name }}"
reservation_id: "{{ reservation_id }}"
node_count: "{{ node_count }}"
image: "{{ image }}"
# ansible
- hosts: localhost
- name: make stack unavailable
name: "{{ stack_name }}"
state: absent
cloud: "{{ cloud_name }}"
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