Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
a4fce481
Commit
a4fce481
authored
Aug 01, 2014
by
Luke Sneeringer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for environment variables in GCE module.
parent
27a73f2c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
+22
-4
lib/ansible/module_utils/gce.py
+22
-4
No files found.
lib/ansible/module_utils/gce.py
View file @
a4fce481
...
...
@@ -38,19 +38,37 @@ def gce_connect(module):
pem_file
=
module
.
params
.
get
(
'pem_file'
,
None
)
project_id
=
module
.
params
.
get
(
'project_id'
,
None
)
# If any of the values are not given as parameters, check the appropriate
# environment variables.
if
not
service_account_email
:
service_account_email
=
os
.
environ
.
get
(
'GCE_EMAIL'
,
None
)
if
not
project_id
:
project_id
=
os
.
environ
.
get
(
'GCE_PROJECT'
,
None
)
if
not
pem_file
:
pem_file
=
os
.
environ
.
get
(
'GCE_PEM_FILE_PATH'
,
None
)
# If we still don't have one or more of our credentials, attempt to
# get the remaining values from the libcloud secrets file.
if
service_account_email
is
None
or
pem_file
is
None
:
# Load in the libcloud secrets file
try
:
import
secrets
except
ImportError
:
secrets
=
None
service_account_email
,
pem_file
=
getattr
(
secrets
,
'GCE_PARAMS'
,
(
None
,
None
))
if
hasattr
(
secrets
,
'GCE_PARAMS'
):
if
not
service_account_email
:
service_account_email
=
secrets
.
GCE_PARAMS
[
0
]
if
not
pem_file
:
pem_file
=
secrets
.
GCE_PARAMS
[
1
]
keyword_params
=
getattr
(
secrets
,
'GCE_KEYWORD_PARAMS'
,
{})
project_id
=
keyword_params
.
get
(
'project'
,
None
)
if
not
project_id
:
project_id
=
keyword_params
.
get
(
'project'
,
None
)
# If we *still* don't have the credentials we need, then it's time to
# just fail out.
if
service_account_email
is
None
or
pem_file
is
None
or
project_id
is
None
:
module
.
fail_json
(
msg
=
'Missing GCE connection parameters in libcloud secrets file.'
)
module
.
fail_json
(
msg
=
'Missing GCE connection parameters in libcloud '
'secrets file.'
)
return
None
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment