Skip to content

Commit

Permalink
#98 Follow-up: ensure wildcard version range constraint does work for…
Browse files Browse the repository at this point in the history
… Ansible
  • Loading branch information
T2L committed Oct 24, 2019
1 parent b07c798 commit 8ad073b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions default.vm-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ virtualbox:

# Ansible local configuration.
ansible:
# Ansible version to use for the provisioning. Supported version formats:
# - exact version constraint, like 2.6.16, 2.9.0rc2 etc
# - wildcard version range (.*): you can specify a pattern with a * wildcard.
# For example 2.6.* is the equivalent of >=2.6.0 <2.7.0. This option
# installs the latest available Ansible version within the given range
# constraint. This is the default option.
#
# This project has been successfully tested with Ansible 2.6.
version: 2.6.*

# List of features to install. Some roles depend on each other, be careful.
Expand Down
26 changes: 26 additions & 0 deletions provisioning/src/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def merge_default_settings
self.set("vagrant.hostname", self.get("vagrant.hostname") + '.test');
# Symbolize synced folder options.
self.symbolize_synced_folder_options
# Set correct Ansible version to install when wildcard version constraint
# has been provided.
self.set_ansible_version
end

# Internal: Generate IP addres based on a Vagrant host name value (in the most
Expand Down Expand Up @@ -170,4 +173,27 @@ def get_git_credentials
self.set("git_user_email", `git config --get user.email`.strip)
end

# Internal: Vagrant doesn't support wildcards in Ansible version, but pip does.
# This method fixes this by looking up for the latest Ansible version within
# the given range constraint and setting up exact version to install.
#
# Returns nothing.
protected
def set_ansible_version
version = self.get("ansible.version").split(".")
if (version.length === 3 && version.last === "*")
require 'net/https'
uri = URI('https://releases.ansible.com/ansible/')
available_releases = Net::HTTP.get(uri)

latest_release = available_releases
.scan(/>ansible-(#{version[0]}\.#{version[1]}\.\d+[a-zA-Z0-9\-\.]*)\.tar.gz</)
.flatten
.sort_by { |v| Gem::Version.new(v) }
.last

self.set("ansible.version", latest_release)
end
end

end

0 comments on commit 8ad073b

Please sign in to comment.