@ -32,10 +32,18 @@ options:
- Indicate desired state of the resource
- Indicate desired state of the resource
choices: ['present', 'active', 'absent', 'deleted']
choices: ['present', 'active', 'absent', 'deleted']
default: present
default: present
creds_file :
credentials :
description:
description:
- File to find the Rackspace Public Cloud credentials in
- File to find the Rackspace credentials in (ignored if C(api_key) and
C(username) are provided)
default: null
default: null
aliases: ['creds_file']
api_key:
description:
- Rackspace API key (overrides C(credentials))
username:
description:
- Rackspace username (overrides C(credentials))
name:
name:
description:
description:
- Name to give the instance
- Name to give the instance
@ -64,7 +72,7 @@ options:
region:
region:
description:
description:
- Region to create an instance in
- Region to create an instance in
default: null
default: DFW
wait:
wait:
description:
description:
- wait for the instance to be in state 'running' before returning
- wait for the instance to be in state 'running' before returning
@ -77,16 +85,19 @@ options:
requirements: [ "pyrax" ]
requirements: [ "pyrax" ]
author: Jesse Keating
author: Jesse Keating
notes:
notes:
- Two environment variables can be used, RAX_CREDS and RAX_REGION.
- The following environment variables can be used, C(RAX_USERNAME),
- RAX_CREDS points to a credentials file appropriate for pyrax
C(RAX_API_KEY), C(RAX_CREDS), C(RAX_CREDENTIALS), C(RAX_REGION).
- RAX_REGION defines a Rackspace Public Cloud region (DFW, ORD, LON, ...)
- C(RAX_CREDENTIALS) and C(RAX_CREDS) points to a credentials file
appropriate for pyrax
- C(RAX_USERNAME) and C(RAX_API_KEY) obviate the use of a credentials file
- C(RAX_REGION) defines a Rackspace Public Cloud region (DFW, ORD, LON, ...)
'''
'''
EXAMPLES = '''
EXAMPLES = '''
# Create a server
# Create a server
- local_action:
- local_action:
module: rax
module: rax
creds_file : ~/.raxpub
credentials : ~/.raxpub
service: cloudservers
service: cloudservers
name: rax-test1
name: rax-test1
flavor: 5
flavor: 5
@ -208,7 +219,9 @@ def main():
service = dict(default='cloudservers', choices=SUPPORTEDSERVICES),
service = dict(default='cloudservers', choices=SUPPORTEDSERVICES),
state = dict(default='present', choices=['active', 'present',
state = dict(default='present', choices=['active', 'present',
'deleted', 'absent']),
'deleted', 'absent']),
creds_file = dict(),
credentials = dict(aliases = ['creds_file']),
api_key=dict(),
username=dict(),
name = dict(),
name = dict(),
flavor = dict(),
flavor = dict(),
image = dict(),
image = dict(),
@ -223,7 +236,9 @@ def main():
service = module.params.get('service')
service = module.params.get('service')
state = module.params.get('state')
state = module.params.get('state')
creds_file = module.params.get('creds_file')
credentials = module.params.get('credentials')
api_key = module.params.get('api_key')
username = module.params.get('username')
name = module.params.get('name')
name = module.params.get('name')
flavor = module.params.get('flavor')
flavor = module.params.get('flavor')
image = module.params.get('image')
image = module.params.get('image')
@ -234,24 +249,27 @@ def main():
wait = module.params.get('wait')
wait = module.params.get('wait')
wait_timeout = int(module.params.get('wait_timeout'))
wait_timeout = int(module.params.get('wait_timeout'))
# Setup the credentials file
# Setup the credentials and region
if not creds_file:
try:
try:
username = username or os.environ.get('RAX_USERNAME')
creds_file = os.environ['RAX_CREDS_FILE']
api_key = api_key or os.environ.get('RAX_API_KEY')
except KeyError, e:
credentials = credentials or os.environ.get('RAX_CREDENTIALS') or \
module.fail_json(msg = 'Unable to load %s' % e.message)
os.environ.get('RAX_CREDS_FILE')
region = region or os.environ.get('RAX_REGION')
# Define the region
except KeyError, e:
if not region:
module.fail_json(msg = 'Unable to load %s' % e.message)
try:
region = os.environ['RAX_REGION']
except KeyError, e:
module.fail_json(msg = 'Unable to load %s' % e.message)
# setup the auth
# setup the auth
try:
try:
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credential_file(creds_file, region=region)
if api_key and username:
pyrax.set_credentials(username, api_key=api_key, region=region)
elif credentials:
credentials = os.path.expanduser(credentials)
pyrax.set_credential_file(credentials, region=region)
else:
raise Exception('No credentials supplied!')
except Exception, e:
except Exception, e:
module.fail_json(msg = '%s' % e.message)
module.fail_json(msg = '%s' % e.message)