@@ -45,43 +45,57 @@ def load_config(files)
4545 resolve_jinja_variables ( vconfig )
4646end
4747
48+ # Return the path to the ansible-playbook executable.
49+ def ansible_bin
50+ @ansible_bin ||= which ( 'ansible-playbook' )
51+ end
4852
4953# Return the ansible version parsed from running the executable path provided.
50- def get_ansible_version ( exe )
51- /^[^\s ]+ (.+)$/ . match ( `#{ exe } --version` ) { |match | return match [ 1 ] }
54+ def ansible_version
55+ /^[^\s ]+ (.+)$/ . match ( `#{ ansible_bin } --version` ) { |match | return match [ 1 ] }
5256end
5357
5458# Require that if installed, the ansible version meets the requirements.
5559def require_ansible_version ( requirement )
56- if !( ansible_bin = which ( 'ansible-playbook' ) )
57- return
58- end
59- ansible_version = get_ansible_version ( ansible_bin )
60+ return unless ansible_bin
6061 req = Gem ::Requirement . new ( requirement )
61- if req . satisfied_by? ( Gem ::Version . new ( ansible_version ) )
62- return
63- end
64- raise Vagrant ::Errors ::VagrantError . new , "You must install an Ansible version #{ requirement } to use this version of Drupal VM."
62+ return if req . satisfied_by? ( Gem ::Version . new ( ansible_version ) )
63+ raise_message "You must install an Ansible version #{ requirement } to use this version of Drupal VM."
64+ end
65+
66+ def raise_message ( msg )
67+ raise Vagrant ::Errors ::VagrantError . new , msg
6568end
6669
6770# Return which Vagrant provisioner to use.
68- def get_provisioner
69- which ( 'ansible-playbook' ) ? :ansible : :ansible_local
71+ def vagrant_provisioner
72+ ansible_bin ? :ansible : :ansible_local
73+ end
74+
75+ def get_apache_vhosts ( vhosts )
76+ aliases = [ ]
77+ vhosts . each do |host |
78+ aliases . push ( host [ 'servername' ] )
79+ aliases . concat ( host [ 'serveralias' ] . split ) if host [ 'serveralias' ]
80+ end
81+ aliases
82+ end
83+
84+ def get_nginx_vhosts ( vhosts )
85+ aliases = [ ]
86+ vhosts . each do |host |
87+ aliases . push ( host [ 'server_name' ] )
88+ aliases . concat ( host [ 'server_name_redirect' ] . split ) if host [ 'server_name_redirect' ]
89+ end
90+ aliases
7091end
7192
7293# Return a list of all virtualhost server names and aliases from a config hash.
7394def get_vhost_aliases ( vconfig )
74- aliases = [ ]
7595 if vconfig [ 'drupalvm_webserver' ] == 'apache'
76- vconfig [ 'apache_vhosts' ] . each do |host |
77- aliases . push ( host [ 'servername' ] )
78- aliases . concat ( host [ 'serveralias' ] . split ) if host [ 'serveralias' ]
79- end
96+ aliases = get_apache_vhosts ( vconfig [ 'apache_vhosts' ] )
8097 else
81- vconfig [ 'nginx_hosts' ] . each do |host |
82- aliases . concat ( host [ 'server_name' ] . split )
83- aliases . concat ( host [ 'server_name_redirect' ] . split ) if host [ 'server_name_redirect' ]
84- end
98+ aliases = get_nginx_vhosts ( vconfig [ 'nginx_hosts' ] )
8599 end
86100 aliases = aliases . uniq - [ vconfig [ 'vagrant_ip' ] ]
87101 # Remove wildcard subdomains.
0 commit comments