diff --git a/cloud/nova_compute b/cloud/nova_compute index 37df3665ea4..8a3725ed2fc 100644 --- a/cloud/nova_compute +++ b/cloud/nova_compute @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this software. If not, see . +import os + try: from novaclient.v1_1 import client as nova_client from novaclient import exceptions @@ -224,13 +226,32 @@ def _get_server_state(module, nova): def main(): + # Consume standard OpenStack environment variables. + # This is mainly only useful for ad-hoc command line operation as + # in playbooks one would assume variables would be used appropriately + OS_USERNAME=os.environ.get('OS_USERNAME', 'admin') + OS_PASSWORD=os.environ.get('OS_PASSWORD', None) + login_password_arg = dict() + if OS_PASSWORD: + login_password_arg['default'] = OS_PASSWORD + else: + login_password_arg['required'] = True + OS_TENANT_NAME=os.environ.get('OS_TENANT_NAME', None) + tenant_name_arg = dict() + if OS_TENANT_NAME: + tenant_name_arg['default'] = OS_TENANT_NAME + else: + tenant_name_arg['required'] = True + OS_REGION_NAME=os.environ.get('OS_REGION_NAME', None) + OS_AUTH_URL=os.environ.get('OS_AUTH_URL', 'http://127.0.0.1:35357/v2.0/') + module = AnsibleModule( argument_spec = dict( - login_username = dict(default='admin'), - login_password = dict(required=True), - login_tenant_name = dict(required='True'), - auth_url = dict(default='http://127.0.0.1:35357/v2.0/'), - region_name = dict(default=None), + login_username = dict(default=OS_USERNAME), + login_password = login_password_arg, + login_tenant_name = tenant_name_arg, + auth_url = dict(default=OS_AUTH_URL), + region_name = dict(default=OS_REGION_NAME), name = dict(required=True), image_id = dict(default=None), flavor_id = dict(default=1),