Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ansible-galaxy handling of role versions #12904

Merged
merged 2 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions lib/ansible/cli/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,19 @@ def execute_install(self):
display.vvv('Installing role %s ' % role.name)
# query the galaxy API for the role data

if role.install_info is not None and not force:
display.display('- %s is already installed, skipping.' % role.name)
continue
if role.install_info is not None:
if role.install_info['version'] != role.version:
if force:
display.display('- changing role %s from %s to %s' %
(role.name, role.install_info['version'], role.version or "unspecified"))
role.remove()
else:
display.warning('- %s (%s) is already installed - use --force to change version to %s' %
(role.name, role.install_info['version'], role.version or "unspecified"))
continue
else:
display.display('- %s is already installed, skipping.' % str(role))
continue

try:
installed = role.install()
Expand All @@ -411,14 +421,18 @@ def execute_install(self):
# we know we can skip this, as it's not going to
# be found on galaxy.ansible.com
continue
if dep_role.install_info is None or force:
if dep_role.install_info is None:
if dep_role not in roles_left:
display.display('- adding dependency: %s' % dep_role.name)
display.display('- adding dependency: %s' % str(dep_role))
roles_left.append(dep_role)
else:
display.display('- dependency %s already pending installation.' % dep_role.name)
else:
display.display('- dependency %s is already installed, skipping.' % dep_role.name)
if dep_role.install_info['version'] != dep_role.version:
display.warning('- dependency %s from role %s differs from already installed version (%s), skipping' %
(str(dep_role), role.name, dep_role.install_info['version']))
else:
display.display('- dependency %s is already installed, skipping.' % dep_role.name)

if not installed:
display.warning("- %s was NOT installed successfully." % role.name)
Expand Down
11 changes: 10 additions & 1 deletion lib/ansible/galaxy/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def __init__(self, galaxy, name, src=None, version=None, scm=None, path=None):
self.paths = [x for x in galaxy.roles_paths]
self.paths = [os.path.join(x, self.name) for x in self.paths]

def __repr__(self):
"""
Returns "rolename (version)" if version is not null
Returns "rolename" otherwise
"""
if self.version:
return "%s (%s)" % (self.name, self.version)
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho, this else is not usefull ?.

if self.version:
    return xxxx
return xxxx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lujeni meh, it's really not that important. I prefer it the way it is, and you're entitled to your preference.

Unless you can point to actual documentation backing up your preferences though (PEP-8, Ansible coding standards, etc.), I'm unlikely to change my code.

return self.name

def __eq__(self, other):
return self.name == other.name
Expand Down Expand Up @@ -321,7 +330,7 @@ def install(self):
raise AnsibleError("Could not update files in %s: %s" % (self.path, str(e)))

# return the parsed yaml metadata
display.display("- %s was installed successfully" % self.name)
display.display("- %s was installed successfully" % str(self))
if not local_file:
try:
os.unlink(tmp_file)
Expand Down