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
2a50957a
Commit
2a50957a
authored
Sep 15, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix galaxy install dep failure
Also fixes issue where force does not force reinstall of deps Fixes #10425
parent
1a39e32a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
113 deletions
+133
-113
lib/ansible/cli/galaxy.py
+14
-15
lib/ansible/galaxy/__init__.py
+5
-3
lib/ansible/galaxy/role.py
+15
-2
lib/ansible/playbook/role/requirement.py
+99
-93
No files found.
lib/ansible/cli/galaxy.py
View file @
2a50957a
...
@@ -352,6 +352,7 @@ class GalaxyCLI(CLI):
...
@@ -352,6 +352,7 @@ class GalaxyCLI(CLI):
raise
AnsibleOptionsError
(
"- please specify a user/role name, or a roles file, but not both"
)
raise
AnsibleOptionsError
(
"- please specify a user/role name, or a roles file, but not both"
)
no_deps
=
self
.
get_opt
(
"no_deps"
,
False
)
no_deps
=
self
.
get_opt
(
"no_deps"
,
False
)
force
=
self
.
get_opt
(
'force'
,
False
)
roles_path
=
self
.
get_opt
(
"roles_path"
)
roles_path
=
self
.
get_opt
(
"roles_path"
)
roles_done
=
[]
roles_done
=
[]
...
@@ -389,6 +390,9 @@ class GalaxyCLI(CLI):
...
@@ -389,6 +390,9 @@ class GalaxyCLI(CLI):
role
=
roles_left
.
pop
(
0
)
role
=
roles_left
.
pop
(
0
)
role_path
=
role
.
path
role_path
=
role
.
path
if
role
.
install_info
is
not
None
and
not
force
:
self
.
display
.
display
(
'-
%
s is already installed, skipping.'
%
role
.
name
)
continue
if
role_path
:
if
role_path
:
self
.
options
.
roles_path
=
role_path
self
.
options
.
roles_path
=
role_path
...
@@ -443,25 +447,20 @@ class GalaxyCLI(CLI):
...
@@ -443,25 +447,20 @@ class GalaxyCLI(CLI):
os
.
unlink
(
tmp_file
)
os
.
unlink
(
tmp_file
)
# install dependencies, if we want them
# install dependencies, if we want them
if
not
no_deps
and
installed
:
if
not
no_deps
and
installed
:
if
not
role_data
:
role_dependencies
=
role
.
metadata
.
get
(
'dependencies'
,
[])
role_data
=
gr
.
get_metadata
(
role
.
get
(
"name"
),
options
)
role_dependencies
=
role_data
[
'dependencies'
]
else
:
role_dependencies
=
role_data
[
'summary_fields'
][
'dependencies'
]
# api_fetch_role_related(api_server, 'dependencies', role_data['id'])
for
dep
in
role_dependencies
:
for
dep
in
role_dependencies
:
self
.
display
.
debug
(
'Installing dep
%
s'
%
dep
)
self
.
display
.
debug
(
'Installing dep
%
s'
%
dep
)
if
isinstance
(
dep
,
basestring
):
dep_req
=
RoleRequirement
()
dep
=
ansible
.
utils
.
role_spec_parse
(
dep
)
__
,
dep_name
,
__
=
dep_req
.
parse
(
dep
)
else
:
dep_role
=
GalaxyRole
(
self
.
galaxy
,
name
=
dep_name
)
dep
=
ansible
.
utils
.
role_yaml_parse
(
dep
)
if
dep_role
.
install_info
is
None
or
force
:
if
not
get_role_metadata
(
dep
[
"name"
],
options
):
if
dep_role
not
in
roles_left
:
if
dep
not
in
roles_left
:
self
.
display
.
display
(
'- adding dependency:
%
s'
%
dep_name
)
self
.
display
.
display
(
'- adding dependency:
%
s'
%
dep
[
"name"
])
roles_left
.
append
(
GalaxyRole
(
self
.
galaxy
,
name
=
dep_name
))
roles_left
.
append
(
dep
)
else
:
else
:
self
.
display
.
display
(
'- dependency
%
s already pending installation.'
%
dep
[
"name"
]
)
self
.
display
.
display
(
'- dependency
%
s already pending installation.'
%
dep
_name
)
else
:
else
:
self
.
display
.
display
(
'- dependency
%
s is already installed, skipping.'
%
dep
[
"name"
]
)
self
.
display
.
display
(
'- dependency
%
s is already installed, skipping.'
%
dep
_name
)
if
not
tmp_file
or
not
installed
:
if
not
tmp_file
or
not
installed
:
self
.
display
.
warning
(
"-
%
s was NOT installed successfully."
%
role
.
name
)
self
.
display
.
warning
(
"-
%
s was NOT installed successfully."
%
role
.
name
)
...
...
lib/ansible/galaxy/__init__.py
View file @
2a50957a
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
import
os
import
os
from
six
import
string_types
from
ansible.errors
import
AnsibleError
from
ansible.errors
import
AnsibleError
from
ansible.utils.display
import
Display
from
ansible.utils.display
import
Display
...
@@ -40,9 +42,9 @@ class Galaxy(object):
...
@@ -40,9 +42,9 @@ class Galaxy(object):
self
.
display
=
display
self
.
display
=
display
self
.
options
=
options
self
.
options
=
options
self
.
roles_path
=
getattr
(
self
.
options
,
'roles_path'
,
None
)
roles_paths
=
getattr
(
self
.
options
,
'roles_path'
,
[]
)
if
self
.
roles_path
:
if
isinstance
(
roles_paths
,
string_types
)
:
self
.
roles_path
=
os
.
path
.
expanduser
(
self
.
roles_path
)
self
.
roles_path
s
=
[
os
.
path
.
expanduser
(
roles_path
)
for
roles_path
in
roles_paths
.
split
(
os
.
pathsep
)]
self
.
roles
=
{}
self
.
roles
=
{}
...
...
lib/ansible/galaxy/role.py
View file @
2a50957a
...
@@ -39,7 +39,7 @@ class GalaxyRole(object):
...
@@ -39,7 +39,7 @@ class GalaxyRole(object):
ROLE_DIRS
=
(
'defaults'
,
'files'
,
'handlers'
,
'meta'
,
'tasks'
,
'templates'
,
'vars'
)
ROLE_DIRS
=
(
'defaults'
,
'files'
,
'handlers'
,
'meta'
,
'tasks'
,
'templates'
,
'vars'
)
def
__init__
(
self
,
galaxy
,
name
,
src
=
None
,
version
=
None
,
scm
=
None
):
def
__init__
(
self
,
galaxy
,
name
,
src
=
None
,
version
=
None
,
scm
=
None
,
role_path
=
None
):
self
.
_metadata
=
None
self
.
_metadata
=
None
self
.
_install_info
=
None
self
.
_install_info
=
None
...
@@ -52,7 +52,20 @@ class GalaxyRole(object):
...
@@ -52,7 +52,20 @@ class GalaxyRole(object):
self
.
src
=
src
or
name
self
.
src
=
src
or
name
self
.
scm
=
scm
self
.
scm
=
scm
self
.
path
=
(
os
.
path
.
join
(
galaxy
.
roles_path
,
self
.
name
))
if
role_path
is
not
None
:
self
.
path
=
role_path
else
:
for
path
in
galaxy
.
roles_paths
:
role_path
=
os
.
path
.
join
(
path
,
self
.
name
)
if
os
.
path
.
exists
(
role_path
):
self
.
path
=
role_path
break
else
:
# use the first path by default
self
.
path
=
os
.
path
.
join
(
galaxy
.
roles_paths
[
0
],
self
.
name
)
def
__eq__
(
self
,
other
):
return
self
.
name
==
other
.
name
def
fetch_from_scm_archive
(
self
):
def
fetch_from_scm_archive
(
self
):
...
...
lib/ansible/playbook/role/requirement.py
View file @
2a50957a
...
@@ -54,26 +54,26 @@ class RoleRequirement(RoleDefinition):
...
@@ -54,26 +54,26 @@ class RoleRequirement(RoleDefinition):
assert
type
(
ds
)
==
dict
or
isinstance
(
ds
,
string_types
)
assert
type
(
ds
)
==
dict
or
isinstance
(
ds
,
string_types
)
role_name
=
''
role_name
=
None
role_params
=
dict
()
role_params
=
dict
()
new_ds
=
dict
()
new_ds
=
dict
()
if
isinstance
(
ds
,
string_types
):
if
isinstance
(
ds
,
string_types
):
role_name
=
ds
role_name
=
ds
else
:
else
:
ds
=
self
.
_preprocess_role_spec
(
ds
)
(
new_ds
,
role_params
)
=
self
.
_split_role_params
(
self
.
_preprocess_role_spec
(
ds
))
(
new_ds
,
role_params
)
=
self
.
_split_role_params
(
ds
)
# pull the role name out of the ds
# pull the role name out of the ds
role_name
=
new_ds
.
get
(
'role_name'
)
role_name
=
new_ds
.
pop
(
'role_name'
,
new_ds
.
pop
(
'role'
,
None
))
del
ds
[
'role_name'
]
if
role_name
is
None
:
raise
AnsibleError
(
"Role requirement did not contain a role name!"
,
obj
=
ds
)
return
(
new_ds
,
role_name
,
role_params
)
return
(
new_ds
,
role_name
,
role_params
)
def
_preprocess_role_spec
(
self
,
ds
):
def
_preprocess_role_spec
(
self
,
ds
):
if
'role'
in
ds
:
if
'role'
in
ds
:
# Old style: {role: "galaxy.role,version,name", other_vars: "here" }
# Old style: {role: "galaxy.role,version,name", other_vars: "here" }
role_info
=
self
.
_
role_spec_parse
(
ds
[
'role'
])
role_info
=
role_spec_parse
(
ds
[
'role'
])
if
isinstance
(
role_info
,
dict
):
if
isinstance
(
role_info
,
dict
):
# Warning: Slight change in behaviour here. name may be being
# Warning: Slight change in behaviour here. name may be being
# overloaded. Previously, name was only a parameter to the role.
# overloaded. Previously, name was only a parameter to the role.
...
@@ -96,7 +96,7 @@ class RoleRequirement(RoleDefinition):
...
@@ -96,7 +96,7 @@ class RoleRequirement(RoleDefinition):
ds
[
"role"
]
=
ds
[
"name"
]
ds
[
"role"
]
=
ds
[
"name"
]
del
ds
[
"name"
]
del
ds
[
"name"
]
else
:
else
:
ds
[
"role"
]
=
self
.
_
repo_url_to_role_name
(
ds
[
"src"
])
ds
[
"role"
]
=
repo_url_to_role_name
(
ds
[
"src"
])
# set some values to a default value, if none were specified
# set some values to a default value, if none were specified
ds
.
setdefault
(
'version'
,
''
)
ds
.
setdefault
(
'version'
,
''
)
...
@@ -104,96 +104,102 @@ class RoleRequirement(RoleDefinition):
...
@@ -104,96 +104,102 @@ class RoleRequirement(RoleDefinition):
return
ds
return
ds
def
_repo_url_to_role_name
(
self
,
repo_url
):
def
repo_url_to_role_name
(
repo_url
):
# gets the role name out of a repo like
# gets the role name out of a repo like
# http://git.example.com/repos/repo.git" => "repo"
# http://git.example.com/repos/repo.git" => "repo"
if
'://'
not
in
repo_url
and
'@'
not
in
repo_url
:
if
'://'
not
in
repo_url
and
'@'
not
in
repo_url
:
return
repo_url
return
repo_url
trailing_path
=
repo_url
.
split
(
'/'
)[
-
1
]
trailing_path
=
repo_url
.
split
(
'/'
)[
-
1
]
if
trailing_path
.
endswith
(
'.git'
):
if
trailing_path
.
endswith
(
'.git'
):
trailing_path
=
trailing_path
[:
-
4
]
trailing_path
=
trailing_path
[:
-
4
]
if
trailing_path
.
endswith
(
'.tar.gz'
):
if
trailing_path
.
endswith
(
'.tar.gz'
):
trailing_path
=
trailing_path
[:
-
7
]
trailing_path
=
trailing_path
[:
-
7
]
if
','
in
trailing_path
:
if
','
in
trailing_path
:
trailing_path
=
trailing_path
.
split
(
','
)[
0
]
trailing_path
=
trailing_path
.
split
(
','
)[
0
]
return
trailing_path
return
trailing_path
def
_role_spec_parse
(
self
,
role_spec
):
def
role_spec_parse
(
role_spec
):
# takes a repo and a version like
# takes a repo and a version like
# git+http://git.example.com/repos/repo.git,v1.0
# git+http://git.example.com/repos/repo.git,v1.0
# and returns a list of properties such as:
# and returns a list of properties such as:
# {
# {
# 'scm': 'git',
# 'scm': 'git',
# 'src': 'http://git.example.com/repos/repo.git',
# 'src': 'http://git.example.com/repos/repo.git',
# 'version': 'v1.0',
# 'version': 'v1.0',
# 'name': 'repo'
# 'name': 'repo'
# }
# }
default_role_versions
=
dict
(
git
=
'master'
,
hg
=
'tip'
)
default_role_versions
=
dict
(
git
=
'master'
,
hg
=
'tip'
)
role_spec
=
role_spec
.
strip
()
role_spec
=
role_spec
.
strip
()
role_version
=
''
role_version
=
''
if
role_spec
==
""
or
role_spec
.
startswith
(
"#"
):
if
role_spec
==
""
or
role_spec
.
startswith
(
"#"
):
return
(
None
,
None
,
None
,
None
)
return
(
None
,
None
,
None
,
None
)
tokens
=
[
s
.
strip
()
for
s
in
role_spec
.
split
(
','
)]
tokens
=
[
s
.
strip
()
for
s
in
role_spec
.
split
(
','
)]
# assume https://github.com URLs are git+https:// URLs and not
# assume https://github.com URLs are git+https:// URLs and not
# tarballs unless they end in '.zip'
# tarballs unless they end in '.zip'
if
'github.com/'
in
tokens
[
0
]
and
not
tokens
[
0
]
.
startswith
(
"git+"
)
and
not
tokens
[
0
]
.
endswith
(
'.tar.gz'
):
if
'github.com/'
in
tokens
[
0
]
and
not
tokens
[
0
]
.
startswith
(
"git+"
)
and
not
tokens
[
0
]
.
endswith
(
'.tar.gz'
):
tokens
[
0
]
=
'git+'
+
tokens
[
0
]
tokens
[
0
]
=
'git+'
+
tokens
[
0
]
if
'+'
in
tokens
[
0
]:
if
'+'
in
tokens
[
0
]:
(
scm
,
role_url
)
=
tokens
[
0
]
.
split
(
'+'
)
(
scm
,
role_url
)
=
tokens
[
0
]
.
split
(
'+'
)
else
:
scm
=
None
role_url
=
tokens
[
0
]
if
len
(
tokens
)
>=
2
:
role_version
=
tokens
[
1
]
if
len
(
tokens
)
==
3
:
role_name
=
tokens
[
2
]
else
:
role_name
=
self
.
_repo_url_to_role_name
(
tokens
[
0
])
if
scm
and
not
role_version
:
role_version
=
default_role_versions
.
get
(
scm
,
''
)
return
dict
(
scm
=
scm
,
src
=
role_url
,
version
=
role_version
,
role_name
=
role_name
)
def
role_yaml_parse
(
role
):
if
'role'
in
role
:
# Old style: {role: "galaxy.role,version,name", other_vars: "here" }
role_info
=
role_spec_parse
(
role
[
'role'
])
if
isinstance
(
role_info
,
dict
):
# Warning: Slight change in behaviour here. name may be being
# overloaded. Previously, name was only a parameter to the role.
# Now it is both a parameter to the role and the name that
# ansible-galaxy will install under on the local system.
if
'name'
in
role
and
'name'
in
role_info
:
del
role_info
[
'name'
]
role
.
update
(
role_info
)
else
:
else
:
# New style: { src: 'galaxy.role,version,name', other_vars: "here" }
scm
=
None
if
'github.com'
in
role
[
"src"
]
and
'http'
in
role
[
"src"
]
and
'+'
not
in
role
[
"src"
]
and
not
role
[
"src"
]
.
endswith
(
'.tar.gz'
):
role_url
=
tokens
[
0
]
role
[
"src"
]
=
"git+"
+
role
[
"src"
]
if
'+'
in
role
[
"src"
]:
if
len
(
tokens
)
>=
2
:
(
scm
,
src
)
=
role
[
"src"
]
.
split
(
'+'
)
role_version
=
tokens
[
1
]
role
[
"scm"
]
=
scm
role
[
"src"
]
=
src
if
'name'
not
in
role
:
if
len
(
tokens
)
==
3
:
role
[
"name"
]
=
repo_url_to_role_name
(
role
[
"src"
])
role_name
=
tokens
[
2
]
else
:
role_name
=
repo_url_to_role_name
(
tokens
[
0
])
if
'version'
not
in
role
:
if
scm
and
not
role_version
:
role
[
'version'
]
=
''
role_version
=
default_role_versions
.
get
(
scm
,
''
)
if
'scm'
not
in
role
:
return
dict
(
scm
=
scm
,
src
=
role_url
,
version
=
role_version
,
role_name
=
role_name
)
role
[
'scm'
]
=
None
return
role
# FIXME: all of these methods need to be cleaned up/reorganized below this
def
get_opt
(
options
,
k
,
defval
=
""
):
"""
Returns an option from an Optparse values instance.
"""
try
:
data
=
getattr
(
options
,
k
)
except
:
return
defval
if
k
==
"roles_path"
:
if
os
.
pathsep
in
data
:
data
=
data
.
split
(
os
.
pathsep
)[
0
]
return
data
def
get_role_path
(
role_name
,
options
):
"""
Returns the role path based on the roles_path option
and the role name.
"""
roles_path
=
get_opt
(
options
,
'roles_path'
)
roles_path
=
os
.
path
.
join
(
roles_path
,
role_name
)
roles_path
=
os
.
path
.
expanduser
(
roles_path
)
return
roles_path
def
get_role_metadata
(
role_name
,
options
):
"""
Returns the metadata as YAML, if the file 'meta/main.yml'
exists in the specified role_path
"""
role_path
=
os
.
path
.
join
(
get_role_path
(
role_name
,
options
),
'meta/main.yml'
)
try
:
if
os
.
path
.
isfile
(
role_path
):
f
=
open
(
role_path
,
'r'
)
meta_data
=
yaml
.
safe_load
(
f
)
f
.
close
()
return
meta_data
else
:
return
None
except
:
return
None
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