provisioners/ansible: apply @sethvargo comments
Follow-up of code review of PR #6529
This commit is contained in:
parent
819c9b6425
commit
5659c3f2a0
|
@ -3,6 +3,8 @@ module VagrantPlugins
|
|||
module Config
|
||||
class Base < Vagrant.plugin("2", :config)
|
||||
|
||||
GALAXY_COMMAND_DEFAULT = "ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force"
|
||||
|
||||
attr_accessor :extra_vars
|
||||
attr_accessor :galaxy_role_file
|
||||
attr_accessor :galaxy_roles_path
|
||||
|
@ -40,22 +42,22 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def finalize!
|
||||
@extra_vars = nil if @extra_vars == UNSET_VALUE
|
||||
@galaxy_role_file = nil if @galaxy_role_file == UNSET_VALUE
|
||||
@galaxy_roles_path = nil if @galaxy_roles_path == UNSET_VALUE
|
||||
@galaxy_command = "ansible-galaxy install --role-file=%{ROLE_FILE} --roles-path=%{ROLES_PATH} --force" if @galaxy_command == UNSET_VALUE
|
||||
@groups = {} if @groups == UNSET_VALUE
|
||||
@inventory_path = nil if @inventory_path == UNSET_VALUE
|
||||
@limit = nil if @limit == UNSET_VALUE
|
||||
@playbook = nil if @playbook == UNSET_VALUE
|
||||
@raw_arguments = nil if @raw_arguments == UNSET_VALUE
|
||||
@skip_tags = nil if @skip_tags == UNSET_VALUE
|
||||
@start_at_task = nil if @start_at_task == UNSET_VALUE
|
||||
@sudo = false if @sudo != true
|
||||
@sudo_user = nil if @sudo_user == UNSET_VALUE
|
||||
@tags = nil if @tags == UNSET_VALUE
|
||||
@vault_password_file = nil if @vault_password_file == UNSET_VALUE
|
||||
@verbose = false if @verbose == UNSET_VALUE
|
||||
@extra_vars = nil if @extra_vars == UNSET_VALUE
|
||||
@galaxy_role_file = nil if @galaxy_role_file == UNSET_VALUE
|
||||
@galaxy_roles_path = nil if @galaxy_roles_path == UNSET_VALUE
|
||||
@galaxy_command = GALAXY_COMMAND_DEFAULT if @galaxy_command == UNSET_VALUE
|
||||
@groups = {} if @groups == UNSET_VALUE
|
||||
@inventory_path = nil if @inventory_path == UNSET_VALUE
|
||||
@limit = nil if @limit == UNSET_VALUE
|
||||
@playbook = nil if @playbook == UNSET_VALUE
|
||||
@raw_arguments = nil if @raw_arguments == UNSET_VALUE
|
||||
@skip_tags = nil if @skip_tags == UNSET_VALUE
|
||||
@start_at_task = nil if @start_at_task == UNSET_VALUE
|
||||
@sudo = false if @sudo != true
|
||||
@sudo_user = nil if @sudo_user == UNSET_VALUE
|
||||
@tags = nil if @tags == UNSET_VALUE
|
||||
@vault_password_file = nil if @vault_password_file == UNSET_VALUE
|
||||
@verbose = false if @verbose == UNSET_VALUE
|
||||
end
|
||||
|
||||
# Just like the normal configuration "validate" method except that
|
||||
|
|
|
@ -133,12 +133,12 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def get_galaxy_role_file(basedir)
|
||||
Pathname.new(config.galaxy_role_file).expand_path(basedir)
|
||||
File.expand_path(config.galaxy_role_file, basedir)
|
||||
end
|
||||
|
||||
def get_galaxy_roles_path(basedir)
|
||||
if config.galaxy_roles_path
|
||||
Pathname.new(config.galaxy_roles_path).expand_path(basedir)
|
||||
File.expand_path(config.galaxy_roles_path, basedir)
|
||||
else
|
||||
File.join(Pathname.new(config.playbook).expand_path(basedir).parent, 'roles')
|
||||
end
|
||||
|
|
|
@ -66,8 +66,8 @@ module VagrantPlugins
|
|||
|
||||
def execute_ansible_galaxy_on_guest
|
||||
command_values = {
|
||||
:ROLE_FILE => get_galaxy_role_file(config.provisioning_path),
|
||||
:ROLES_PATH => get_galaxy_roles_path(config.provisioning_path)
|
||||
:role_file => get_galaxy_role_file(config.provisioning_path),
|
||||
:roles_path => get_galaxy_roles_path(config.provisioning_path)
|
||||
}
|
||||
remote_command = config.galaxy_command % command_values
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ module VagrantPlugins
|
|||
|
||||
protected
|
||||
|
||||
VAGRANT_ARG_SEPARATOR = 'VAGRANT_ARG_SEP'
|
||||
|
||||
def warn_for_unsupported_platform
|
||||
if Vagrant::Util::Platform.windows?
|
||||
@machine.env.ui.warn(I18n.t("vagrant.provisioners.ansible.windows_not_supported_for_control_machine"))
|
||||
|
@ -86,16 +88,15 @@ module VagrantPlugins
|
|||
|
||||
def execute_ansible_galaxy_from_host
|
||||
command_values = {
|
||||
:ROLE_FILE => get_galaxy_role_file(machine.env.root_path),
|
||||
:ROLES_PATH => get_galaxy_roles_path(machine.env.root_path)
|
||||
:role_file => get_galaxy_role_file(machine.env.root_path),
|
||||
:roles_path => get_galaxy_roles_path(machine.env.root_path)
|
||||
}
|
||||
arg_separator = '__VAGRANT_ARG_SEPARATOR__'
|
||||
command_template = config.galaxy_command.gsub(' ', arg_separator)
|
||||
command_template = config.galaxy_command.gsub(' ', VAGRANT_ARG_SEPARATOR)
|
||||
str_command = command_template % command_values
|
||||
|
||||
ui_running_ansible_command "galaxy", str_command.gsub(arg_separator, ' ')
|
||||
ui_running_ansible_command "galaxy", str_command.gsub(VAGRANT_ARG_SEPARATOR, ' ')
|
||||
|
||||
command = str_command.split(arg_separator)
|
||||
command = str_command.split(VAGRANT_ARG_SEPARATOR)
|
||||
command << {
|
||||
# Write stdout and stderr data, since it's the regular Ansible output
|
||||
notify: [:stdout, :stderr],
|
||||
|
|
|
@ -2043,6 +2043,12 @@ en:
|
|||
Vagrant does not support detecting whether Ansible is installed
|
||||
for the guest OS running in the machine. Vagrant will assume it is
|
||||
installed and attempt to continue.
|
||||
|
||||
If you'd like this provisioner to be improved, please
|
||||
take a look at the Vagrant source code linked below and try
|
||||
to contribute back support. Thank you!
|
||||
|
||||
https://github.com/mitchellh/vagrant
|
||||
errors:
|
||||
ansible_command_failed: |-
|
||||
Ansible failed to complete successfully. Any error output should be
|
||||
|
@ -2054,7 +2060,7 @@ en:
|
|||
If you haven't installed Ansible yet, please install Ansible
|
||||
on your Vagrant basebox, or enable the automated setup with the
|
||||
`install` option of this provisioner. Please check
|
||||
http://docs.vagrantup.com/v2/provisioning/ansible_local.html
|
||||
https://docs.vagrantup.com/v2/provisioning/ansible_local.html
|
||||
for more information.
|
||||
ansible_not_found_on_host: |-
|
||||
The Ansible software could not be found! Please verify
|
||||
|
@ -2063,12 +2069,12 @@ en:
|
|||
If you haven't installed Ansible yet, please install Ansible
|
||||
on your host system. Vagrant can't do this for you in a safe and
|
||||
automated way.
|
||||
Please check http://docs.ansible.com for more information.
|
||||
Please check https://docs.ansible.com for more information.
|
||||
ansible_version_not_found_on_guest: |-
|
||||
The requested Ansible version (%{required_version}) was not found on the guest.
|
||||
Please check the ansible installation on your guest system,
|
||||
or adapt the `version` option of this provisioner in your Vagrantfile.
|
||||
See http://docs.vagrantup.com/v2/provisioning/ansible_local.html
|
||||
See https://docs.vagrantup.com/v2/provisioning/ansible_local.html
|
||||
for more information.
|
||||
extra_vars_invalid: |-
|
||||
`extra_vars` must be a hash or a path to an existing file. Received: %{value} (as %{type})
|
||||
|
@ -2087,7 +2093,7 @@ en:
|
|||
running_playbook: "Running ansible-playbook..."
|
||||
windows_not_supported_for_control_machine: |-
|
||||
Windows is not officially supported for the Ansible Control Machine.
|
||||
Please check http://docs.ansible.com/intro_installation.html#control-machine-requirements
|
||||
Please check https://docs.ansible.com/intro_installation.html#control-machine-requirements
|
||||
|
||||
docker:
|
||||
not_running: "Docker is not running on the guest VM."
|
||||
|
|
|
@ -53,17 +53,15 @@ Some of these options are for advanced usage only and should not be used unless
|
|||
|
||||
- `galaxy_command` (template string) - The command pattern used to install Galaxy roles when `galaxy_role_file` is set.
|
||||
|
||||
The following placeholders can be used in this command pattern:
|
||||
- `%{ROLE_FILE}` is replaced by the absolute path to the `galaxy_role_file` option
|
||||
- `%{ROLES_PATH}` is
|
||||
* replaced by the absolute path to the `galaxy_roles_path` option when such option is defined
|
||||
* replaced by the absolute path to a `roles` subdirectory sitting in the parent directory of the configured `playbook` file otherwise.
|
||||
The following (optional) placeholders can be used in this command pattern:
|
||||
- `%{role_file}` is replaced by the absolute path to the `galaxy_role_file` option
|
||||
- `%{roles_path}` is
|
||||
- replaced by the absolute path to the `galaxy_roles_path` option when such option is defined, or
|
||||
- replaced by the absolute path to a `roles` subdirectory sitting in the `playbook` parent directory.
|
||||
|
||||
By default, this option is set to
|
||||
|
||||
```
|
||||
ansible-galaxy install --role-file=%{ROLE_FILE} --roles-path=%{ROLES_PATH} --force
|
||||
```
|
||||
`ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force`
|
||||
|
||||
- `galaxy_role_file` (string) - The path to the Ansible Galaxy role file.
|
||||
|
||||
|
|
Loading…
Reference in New Issue