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
77c76e63
Commit
77c76e63
authored
Jun 12, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch etcd and url lookup plugins to verify ssl certificates
parent
4161d78a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
17 deletions
+27
-17
lib/ansible/plugins/lookup/etcd.py
+9
-5
lib/ansible/plugins/lookup/url.py
+18
-12
No files found.
lib/ansible/plugins/lookup/etcd.py
View file @
77c76e63
...
@@ -18,23 +18,25 @@ from __future__ import (absolute_import, division, print_function)
...
@@ -18,23 +18,25 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__
=
type
__metaclass__
=
type
import
os
import
os
import
urllib2
try
:
try
:
import
json
import
json
except
ImportError
:
except
ImportError
:
import
simplejson
as
json
import
simplejson
as
json
from
ansible.plugins.lookup
import
LookupBase
from
ansible.plugins.lookup
import
LookupBase
from
ansible.module_utils.urls
import
open_url
# this can be made configurable, not should not use ansible.cfg
# this can be made configurable, not should not use ansible.cfg
ANSIBLE_ETCD_URL
=
'http://127.0.0.1:4001'
ANSIBLE_ETCD_URL
=
'http://127.0.0.1:4001'
if
os
.
getenv
(
'ANSIBLE_ETCD_URL'
)
is
not
None
:
if
os
.
getenv
(
'ANSIBLE_ETCD_URL'
)
is
not
None
:
ANSIBLE_ETCD_URL
=
os
.
environ
[
'ANSIBLE_ETCD_URL'
]
ANSIBLE_ETCD_URL
=
os
.
environ
[
'ANSIBLE_ETCD_URL'
]
class
etcd
()
:
class
Etcd
:
def
__init__
(
self
,
url
=
ANSIBLE_ETCD_URL
):
def
__init__
(
self
,
url
=
ANSIBLE_ETCD_URL
,
validate_certs
):
self
.
url
=
url
self
.
url
=
url
self
.
baseurl
=
'
%
s/v1/keys'
%
(
self
.
url
)
self
.
baseurl
=
'
%
s/v1/keys'
%
(
self
.
url
)
self
.
validate_certs
=
validate_certs
def
get
(
self
,
key
):
def
get
(
self
,
key
):
url
=
"
%
s/
%
s"
%
(
self
.
baseurl
,
key
)
url
=
"
%
s/
%
s"
%
(
self
.
baseurl
,
key
)
...
@@ -42,7 +44,7 @@ class etcd():
...
@@ -42,7 +44,7 @@ class etcd():
data
=
None
data
=
None
value
=
""
value
=
""
try
:
try
:
r
=
urllib2
.
urlopen
(
url
)
r
=
open_url
(
url
,
validate_certs
=
self
.
validate_certs
)
data
=
r
.
read
()
data
=
r
.
read
()
except
:
except
:
return
value
return
value
...
@@ -67,7 +69,9 @@ class LookupModule(LookupBase):
...
@@ -67,7 +69,9 @@ class LookupModule(LookupBase):
if
isinstance
(
terms
,
basestring
):
if
isinstance
(
terms
,
basestring
):
terms
=
[
terms
]
terms
=
[
terms
]
etcd
=
etcd
()
validate_certs
=
kwargs
.
get
(
'validate_certs'
,
True
)
etcd
=
Etcd
(
validate_certs
=
validate_certs
)
ret
=
[]
ret
=
[]
for
term
in
terms
:
for
term
in
terms
:
...
...
lib/ansible/plugins/lookup/url.py
View file @
77c76e63
...
@@ -17,30 +17,36 @@
...
@@ -17,30 +17,36 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
__metaclass__
=
type
from
ansible.plugins.lookup
import
LookupBase
import
urllib2
import
urllib2
from
ansible.errors
import
AnsibleError
from
ansible.plugins.lookup
import
LookupBase
from
ansible.module_utils.urls
import
open_url
,
ConnectionError
,
SSLValidationError
from
ansible.utils.unicode
import
to_unicode
class
LookupModule
(
LookupBase
):
class
LookupModule
(
LookupBase
):
def
run
(
self
,
terms
,
inject
=
None
,
**
kwargs
):
def
run
(
self
,
terms
,
variables
=
None
,
**
kwargs
):
if
isinstance
(
terms
,
basestring
):
if
isinstance
(
terms
,
basestring
):
terms
=
[
terms
]
terms
=
[
terms
]
validate_certs
=
kwargs
.
get
(
'validate_certs'
,
True
)
ret
=
[]
ret
=
[]
for
term
in
terms
:
for
term
in
terms
:
try
:
try
:
r
=
urllib2
.
Request
(
term
)
response
=
open_url
(
term
,
validate_certs
=
validate_certs
)
response
=
urllib2
.
urlopen
(
r
)
except
urllib2
.
URLError
as
e
:
except
URLError
as
e
:
raise
AnsibleError
(
"Failed lookup url for
%
s :
%
s"
%
(
term
,
str
(
e
)))
utils
.
warnings
(
"Failed lookup url for
%
s :
%
s"
%
(
term
,
str
(
e
)))
except
urllib2
.
HTTPError
as
e
:
continue
raise
AnsibleError
(
"Received HTTP error for
%
s :
%
s"
%
(
term
,
str
(
e
)))
except
HTTPError
as
e
:
except
SSLValidationError
as
e
:
utils
.
warnings
(
"Received HTTP error for
%
s :
%
s"
%
(
term
,
str
(
e
)))
raise
AnsibleError
(
"Error validating the server's certificate for
%
s:
%
s"
%
(
term
,
str
(
e
)))
continue
except
ConnectionError
as
e
:
raise
AnsibleError
(
"Error connecting to
%
s:
%
s"
%
(
term
,
str
(
e
)))
for
line
in
response
.
read
()
.
splitlines
():
for
line
in
response
.
read
()
.
splitlines
():
ret
.
append
(
line
)
ret
.
append
(
to_unicode
(
line
))
return
ret
return
ret
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