Skip to content

Latest commit

 

History

History
224 lines (189 loc) · 7.66 KB

Ansible_Ravello_module.adoc

File metadata and controls

224 lines (189 loc) · 7.66 KB

Requirements & Instructions on Using the Ansible Ravello Module

1. Requirements

  1. Install Ansible http://docs.ansible.com/ansible/intro_installation.html

  2. Install the Ravello SDK via pip

    Note
    For manual setup instructions see https://github.com/ravello/python-sdk and for additional documentation see http://ravello-sdk.readthedocs.io/en/ravello-sdk-1.4/
    pip install ravello-sdk

1.1. Test Ravello SDK

  1. Clone the ravello-sdk locally to use the example scripts

    cd <desired_dir>
    git clone https://github.com/ravello/python-sdk.git
  2. Change to the examples directory

    cd python-sdk/examples
  3. Set up credentials file for Ravello using your username and password

    ./set-creds
    Enter username: [email protected]
    Enter a Password:
  4. Verify saved credentials

    Note
    This will display your login into on the terminal however the password is hashed.
    cat ~/.ravello_login
    <username>
    <password>
  5. Test the script to get all blueprints you have access to

    ./bp-get-all
    <all blueprints you have access to>

1.2. Test Capture of Ravello Environment Metadata to JSON

  1. Test the script to get all applications you have access to

    ./app-get-all
    <all apps you have access to>
  2. Test the script to get all metadata for a specific application and write it to a JSON file

    Note
    The option -a is for a full JSON dump of extended application metadata
    ./app-get-data -a <one app name from output in previous step > myapp.json

2. Using the Ravello Ansible Module

2.1. Clone the Ansible Ravello Repository

  1. Change to a directory of your chosing

    git clone https://github.com/RedHatDemos/ansible-ravello.git

2.2. Create YAML Template

  1. Within the cloned repository directory, create template from existing app:

    ./app-get-data -a <your_application> 2>/dev/null|python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' > out.yaml
  2. Remove everything that is not in the design: section. This is at the beginning and end of the file.

  3. Under design: remove all subsections except vms:

  4. Remove any line with applicationId:, creationTime:, loadingStatus:, loadingPercentage:, fqdn:, allocatedIp:, externalAccessState:, ipConfigLuid:, and useLuidForIpConfig:.

2.3. Deploy an Environment

  1. This playbook will create a blueprint based on a set of virtual machines described in app_template.yml. It will then create an application from this blueprint and wait for it to start.

  2. To use the default values just run the *deploy_environment.yml.

    ansible-playbook deploy_environment.yml
    Note
    It is likely there may be a conflict if the default names have already been used. Instead, specify a unique_name and optionally a version which will be used to make sure your blueprints and applications have unique names
  3. Specify unique_name and version if desired:

    ansible-playbook deploy_environment.yml -e "unique_name=vvaldez-demo version=1.6"
  4. It is also possible to load your own variables from a yaml file:

    ansible-playbook deploy_environment.yml -e @vars.yml
  5. Contents of vars.yml:

    unique_name=vvaldez-demo
    version=1.6
  6. To skip the blueprint creation phase, just provide an existing blueprint_id:

    ansible-playbook deploy_environment.yml -e "blueprint_id=12345678"
  7. Example deploy_environment.yml playbook template provided in this repo:

    ---
    - hosts: localhost
      tasks:
          # Create app, based on blueprint, start it and wait for started
        - local_action:
            module: ravello_app
            # Make sure you update the version number as the name must be unique
            name: 'example_app-v1.0'
            description: 'Example blueprint created by ansible'
            app_template: '/home/user/ansible-ravello/app_template.yml'
            state: design
    Note
    The name field must be unique. All blueprints must have a unique name. Typically this is achieved by changing the version number in the name.

2.4. Create Blueprint From Template

ansible-playbook design.yml -vvv
Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available


PLAYBOOK: design.yml ***********************************************************
1 plays in design.yml

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.6/site-packages/ansible/modules/core/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: prutledg
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1481666189.73-18007598170313 `" && echo ansible-tmp-1481666189.73-18007598170313="` echo $HOME/.ansible/tmp/ansible-tmp-1481666189.73-18007598170313 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmp7TPuB1 TO /home/prutledg/.ansible/tmp/ansible-tmp-1481666189.73-18007598170313/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/prutledg/.ansible/tmp/ansible-tmp-1481666189.73-18007598170313/ /home/prutledg/.ansible/tmp/ansible-tmp-1481666189.73-18007598170313/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2.6 /home/prutledg/.ansible/tmp/ansible-tmp-1481666189.73-18007598170313/setup.py; rm -rf "/home/prutledg/.ansible/tmp/ansible-tmp-1481666189.73-18007598170313/" > /dev/null 2>&1 && sleep 0'
ok: [localhost]

TASK [ravello_app] *************************************************************
task path: /home/prutledg/ansible-ravello/design.yml:5
Using module file /home/prutledg/ansible-ravello/library/ravello_app.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: prutledg
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1481666190.57-63460892520707 `" && echo ansible-tmp-1481666190.57-63460892520707="` echo $HOME/.ansible/tmp/ansible-tmp-1481666190.57-63460892520707 `" ) && sleep 0'
<localhost> PUT /tmp/tmp7TPuB1 TO /home/prutledg/.ansible/tmp/ansible-tmp-1481666190.57-63460892520707/ravello_app.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/prutledg/.ansible/tmp/ansible-tmp-1481666190.57-63460892520707/ /home/prutledg/.ansible/tmp/ansible-tmp-1481666190.57-63460892520707/ravello_app.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python2.6 /home/prutledg/.ansible/tmp/ansible-tmp-1481666190.57-63460892520707/ravello_app.py; rm -rf "/home/prutledg/.ansible/tmp/ansible-tmp-1481666190.57-63460892520707/" > /dev/null 2>&1 && sleep 0'
changed: [localhost -> localhost] => {
    "blueprint_id": "76743737",
    "changed": true,
    "invocation": {
        "module_args": {
            "app_template": "/home/prutledg/ansible-ravello/app_template.yml",
            "application_ttl": -1,
            "blueprint_description": null,
            "blueprint_id": null,
            "blueprint_name": null,
            "cloud": null,
            "description": "Example blueprint created by ansible",
            "name": "example_app-v1.0",
            "password": null,
            "publish_optimization": "cost",
            "region": null,
            "service_name": "ssh",
            "state": "design",
            "url": null,
            "username": null,
            "wait": true,
            "wait_timeout": 1200
        },
        "module_name": "ravello_app"
    },
    "name": "example_app-v1.0"
}

2.5. Check for Blueprint

  1. Log into Ravello and check if the blueprint exists.

  2. The next steps would be to deploy the blueprint with this ansible module as a new application, inventory the app, and apply final playbook(s) to the resulting VMs then create final blueprint from that.