Commit Graph

762 Commits

Author SHA1 Message Date
Gilles Cornu 6bc0c85e90
provisioners/ansible_local: Optimize SSH commands
With this change, the same remote command is used to:
- verify that ansible is available
- gather the ansible version details
2017-09-06 17:12:46 +02:00
Gilles Cornu 9996ed6259
provisioners/ansible_local: Fix an obsolete comment
[ci skip]
2017-09-06 17:12:44 +02:00
Gilles Cornu dc3b6341e2
provisioners/ansible: Check compatibility conflicts
Vagrant will verify that the current Ansible version does support the
requested compatibility mode (only applicable if not "auto", of course).

As mentioned in the documentation, there is no sanity checks between
`version` option and `compatibility_mode` option.

With this change, the host-based provisioner is also improved to
execute only once the "ansible" command (and store the gathered
information for multiple usages like version requirement and
compatibility checks). On the other hand, the guest-based provisioner
can still potentially execute "ansible" twice (once in the
AnsibleInstalled cap, and via "gather_ansible_version" function via
Base::set_compatibility_mode).
2017-09-06 17:12:40 +02:00
Gilles Cornu 36616fb208
provisioners/ansible: Add @control_machine instance variable
This minor addition will be used for upcoming shared code in base
superclass and avoid "guest"/"host" repetitions.
2017-09-06 17:12:39 +02:00
Gilles Cornu 8c0df3d046
provisioners/ansible: Move `version` to common options
Before this change, only the ansible_local provisioner supported this
option (for ansible version requirement, and pip installation). Now, the
ansible host-based provisioner can also require a exact ansible version.

Resolve #8914

Note: this has been added as part of #6570 resolution, since the
introduction of the `compatibility_mode` auto-detection made both
provisioners made capable to detect ansible version.

Pending: optimize the code to avoid duplicated executions of "ansible
--version" command.
2017-09-06 17:12:35 +02:00
Gilles Cornu a327e34861
provisioners/ansible: Validate compatibility_mode
- Use `'auto'` instead of `nil` for the auto-detection mode
- Add strict validation and related error message
2017-09-06 17:12:32 +02:00
Gilles Cornu 8834afbd8e
provisioners/ansible(both): Add compatibility mode
With this change, it is now possible to get rid of many deprecation
messages successively introduced in Ansible 1.9, and 2.0. More
interesting, the generated inventory will contain the recommended
variable names (e.g. `ansible_host` instead of `ansible_ssh_host`)
when the compatibility mode is set to '2.0'.

Details:

- Add `compatibility_mode` option to control the Ansible parameters
  format to be used. The value corresponds to the minimal version
  supported. For the moment, possible values are '1.8' (corresponding to
  Vagrant's former behaviour) or '2.0'.
  Note that a dynamic inventory generated in compatibility mode '2.0'
  is not supported by Ansible 1.x. On the other hand, Ansible 2.x so far
  supports inventory format generated by the compatibility mode '1.8'.

- Add compatibility mode auto-detection, based on the available Ansible
  version. This is the default behaviour in order to bring a maximum of
  user friendliness. The drawback of this approach is to let potential
  compatibility breaking risks, for `ansible` provisioner setups that
  already integrate Ansible 2.x **AND** rely on the existence of
  the generated `_ssh` variable names. Thanks to the vagrant warnings
  (and its release notes), I argue that it is worth to offer
  auto-detection by default, which offers a sweet transition to most
  users.

- Add `become`, `become_user` and `ask_become_pass` options and their
  backwards compatible aliases. The legacy options are now deprecated.

Note that we intentionally didn't provide a '1.9' compatibility mode,
as it would add extra-complexity for practically no added-value.
To my knowledge, the Ansible 2.x series haven't introduced yet any major
changes or deprecations that would motivate to introduce a higher
version compatibility mode (to be confirmed/verified).

Resolve GH-6570

Still Pending:

- Optimization: Reduce the number of `ansible` command executions.
  Currently two exec calls will be performed when the compatibility
  mode auto-detection is enabled (i.e. by default). We could make the
  provisioner a little bit smarter to only execute `ansible` only once
  in any situation (by combining "presence" and "version" checks).

- User-friendliness: Add better validator on `compatibility_mode`
  option, and shows a warning or an error instead of the silent
  fallback on the auto-detection modus.

- Test coverage: All the added behaviours are not fully covered yet.
2017-09-06 17:12:22 +02:00
Gilles Cornu e09848ca59
provisioners/ansible_local: Shellescape extra-vars
Fix #7735

Further work for proper shell-escaping of other ansible-playbook and
ansible-galaxy command line arguments will be addressed via #8949.
2017-09-06 16:30:40 +02:00
Brian Cain 089117bc0f Merge pull request #8939 from briancain/8933/master/source-path-file-prov
Align file provisioner functionality on all platforms
2017-09-05 15:54:52 -07:00
Gilles Cornu b741ff7999
provisoners/ansible(both): Accept 'all:vars'
The patterns "all" is a special keyword that target all hosts in the
inventory. Therefore it makes sense to accept "all:vars" as a group
variable name. Note that "*:vars" pattern is not valid in an Ansible
inventory.
See http://docs.ansible.com/ansible/latest/intro_patterns.html#patterns

Fix #7730
2017-09-03 18:41:06 +02:00
Brian Cain a9564b2137 (#8933) Align file provisioner functionality on all platforms
This commit aligns how the file provisioner should work on all host
machines. It ensures that a `/.` is only applied if the user intended
to upload a folder to a destination under a different name. It ensures
that if uploading to a windows guest with a different destination folder
name, it does not nest the source folder under that name so that it
works the same as it does on linux platforms. It also updates the
behavior of the winrm upload communicator by allowing an array of paths
to be uploaded instead of a single file or folder to allow for this new
functionality for windows guests.
2017-08-31 15:57:53 -07:00
Brian Cain 432cb8d915 (#7826) Add salt_arg option for passing flags to salt tool
This commit introduces the salt_arg option that allows a user to pass
additional command line flags to the `salt` tool when provisioning with
a master setup.

It also adds additional config validation to ensure that both
`salt_args` and `salt_call_args` is an array.
2017-08-29 14:11:06 -07:00
Brian Cain 9a29d7be6b (#7836) Introduce salt_call_args option for salt provisioner
This config option for the salt provisioner allows you to pass
additional arguments to the salt-call executable.
2017-08-29 11:17:29 -07:00
Peter Parkkali 8e4f0444e8 Hide duplicate errors in Saltstack provisioner when verbose mode is on 2017-08-26 01:38:06 +02:00
Brian Cain c0b54f74ea Merge pull request #8875 from briancain/8716/master/dup-string-if-frozen-for-line-endings
Dup string if frozen for line endings
2017-08-15 10:04:34 -07:00
Brian Cain 01528689fd (#8716) Dup string if frozen for line endings
Prior to this commit, if a user passed in a script that was frozen,
the shell provisioner would fail to modify the script to replace line
endings for windows because the string was immutable. This commit fixes
that by dup'ing the string so that it can have its line endings replaced
2017-08-15 08:38:30 -07:00
Brian Cain 61c501cc65 Ensure paths with spaces are preserved
Prior to this commit, if a user set the `destination` path to include a
space, the `shell_expand_guest_path` function would remove that space
and return a partial path. This commit updates that to quote the path to
be expanded to preserve the entire path.
2017-08-14 15:34:10 -07:00
Brian Cain 40eaef08b7 (#8603) Ensure remote folder exists prior to scp in file provisioner
Prior to this commit, if a file provisioner block was ran twice with a
folder on a remote host, due to how scp works, it would first copy over
that folder, and then on the second action it would copy an identical
folder nested within the first one. While this is 'intended' behavior
with scp, it is unexpected behavior for the file provisioner. This
commit updates the file provisioner to first ensure that the directory
to be copied exists on the remote host prior to copying, and then the
destination dir has been changed to the directory that the destination
will be copied to, rather than the exact directly that includes the
folder from the host to prevent the nested folder behavior.
2017-08-11 11:49:39 -07:00
Brian Cain 7a7506cd00 (#8789) Remove curl pipe bash install for salt provisioner
Prior to this commit, because of how the bootstrap salt shell file
worked, if github could not be resolved, the installer script would fail
silently with an exit code 0 because `sh` would evalute without any
errors and the curl exit code would be ignored. This commit splits out
the installer to first attempt to save the bash installer, and if it
exists, execute it.
2017-08-09 10:23:13 -07:00
Brian Cain 623b117208 Merge pull request #8682 from Telekom-PD/omnibus-url
Add config option omnibus_url for chef provisioners
2017-08-03 09:19:13 -07:00
Artem Sidorenko 875c2edc62 Add config option omnibus_url for chef provisioners
This option is useful for internal setups, where own customized
omnibus installation script is used (e.g. to get chef from a mirror)
2017-08-03 10:06:27 +02:00
Brian Cain a2d39742a7 Merge pull request #8775 from lucky-sideburn/master
Added exception if chef.node_path is defined on Vagrantfile but the directory does not exist locally
2017-08-01 13:22:23 -07:00
Eugenio Marzo 7e436c6971 fixed warnings about missing folders for Chef Solo and Zero 2017-08-01 21:37:11 +02:00
Eugenio Marzo c9b65bd129 produce error when node_path is defined but the directory does not exist on disk locally 2017-07-22 11:05:34 +02:00
Eugenio Marzo 94a94648dd change requested after a PR review 2017-07-22 07:58:38 +02:00
Brian Cain 4ed93fb9ef (#8743) Fix puppet provisioner by removing manifestdir flag
Prior to this commit, the puppet provisioner would use the manifest dir
flag when running `puppet apply`. Not only is this flag redundant due to
how puppet apply works, but it is also deprecated in Puppet 4 and
removed in Puppet 5. This commit simply removes the flag when invoking
`puppet apply`.
2017-07-19 09:59:59 -07:00
Brian Cain 773c4fff13 Fixup util/ssh and ansible/provisioner tests 2017-07-17 10:21:26 -07:00
Tomoyuki Sakurai a76dfc7b37 as `key` is a file path, it must be quoted 2017-07-14 10:38:07 -07:00
Tomoyuki Sakurai fe3674e169 another '-i' was used here 2017-07-14 10:34:57 -07:00
Eugenio Marzo 3a5331cbb2 replaced not with ! in the if 2017-07-12 15:32:39 +02:00
Eugenio Marzo dd3d782659 Added exception if chef.node_path is defined on Vagrantfile but the directory does not exist locally 2017-07-12 15:27:10 +02:00
Brian Cain a05d95bd0a (#7139) Add post-install provisioner to docker provisioner
Prior to this commit, if a user attempted to configure
`/etc/default/docker` through vagrant prior to installation, the package
manager would not override an existing configuration and installing
docker would then fail. This commit fixes this by introducing a
`post_install_provisioner` that allows users to define a provisioner
block that will run after docker has been installed, allowing users to
configure `/etc/default/docker` how they want.
2017-06-27 16:01:23 -07:00
Chris Roberts d260fe7d38 Merge pull request #7865 from DavidWittman/7454-fix-salt-minion-id-config
Fix minion_id config for salt provisioner
2017-06-15 16:01:33 -07:00
Chris Roberts 6906dbc558 Merge pull request #8467 from MartinNowak/patch-1
fix `config.ssh.keys_only = false` for ansible
2017-06-14 16:54:24 -07:00
Andreas Olsson f6a9dcdd6f Catch pip_args in FreeBSD's and SUSE's ansible_install
While neither the FreeBSD provisioner nor the SUSE provisioner support
installing Ansible using pip their ansible_install methods still get
called with that fourth argument. The result being these errors when
Vagrant tries to install Ansible.

    /opt/vagrant/embedded/gems/gems/vagrant-1.9.5/plugins/provisioners/ansible/cap/guest/freebsd/ansible_install.rb:10:in `ansible_install': wrong number of arguments (4 for 3) (ArgumentError)
    /opt/vagrant/embedded/gems/gems/vagrant-1.9.5/plugins/provisioners/ansible/cap/guest/suse/ansible_install.rb:9:in `ansible_install': wrong number of arguments (4 for 3) (ArgumentError)

The Arch provider, it too without pip support, already catches the
pip_args argument this way.
2017-06-14 21:01:44 +02:00
Chris Roberts 71bfe7c884 Fix shell provisioner to execute batch files correctly
Call cmd.exe explicitly when running batch files to easily
manage special characters that may be within the path.

Fixes #8535
2017-04-28 15:05:08 -07:00
Chris Roberts 0e89fdf182 Merge pull request #8498 from chrisroberts/win/spaces
Quote exec_path to properly handle spaces in path
2017-04-20 16:08:24 -07:00
Chris Roberts c963532d6e Use configured upload path for winssh communicator 2017-04-20 16:05:41 -07:00
Chris Roberts 82e268a3e2 Quote exec_path to properly handle spaces in path
Fixes #7234
2017-04-19 12:23:55 -07:00
Chris Roberts 232a44f46d Merge pull request #8485 from chrisroberts/communicators/win-ssh
Add winssh communicator
2017-04-17 08:21:33 -07:00
Chris Roberts 9c127a4401 Merge pull request #8443 from anandsuresh/feature/freebsd-chef-installed
Add chef_install(ed?) guest capability for freebsd
2017-04-16 08:23:16 -07:00
Chris Roberts c56acfab94 Add WinSSH communicator 2017-04-15 07:12:58 -07:00
Dafydd Jones 71216cf4f9 update latest salt minion version for windows 2017-04-13 12:36:45 -07:00
Martin Nowak 1ca247f516 fix `config.ssh.keys_only = false` for ansible
Also see #5017.
2017-04-12 12:31:00 +02:00
Anand Suresh 30f4eb62ea Add chef_install(ed?) guest capability for freebsd 2017-04-04 22:10:02 -07:00
knbnnate 8c31a0c3ff Salt ver year.month can have 2-digit month 2017-03-30 17:00:46 -04:00
Gilles Cornu 80d105cf8c
ansible_local: Add the :pip_args_only install mode
With the introduction of `pip_args` option, you can easily extend the
`:pip` installation mode behaviour. But some interesting/advanced usages
are still not possible because of the auto-generated parts ("ansible"
package, version selection, and the `--upgrade` flag).

By adding this "pip_args_only" install mode, it will be for instance
possible to:
- install unofficial releases, like release candidates published at
  https://releases.ansible.com/
- install more pip packages (e.g. via a `requirements.txt` file), with
  hash validation, etc.

Note that there is no config validation that requires `pip_args` option
to be defined when the :pip_args_only mode is selected. This would be
more elegant, and user friendly to raise a configuration error, but this
can wait. At least, running with an empty `pip_args` won't lead to any
command crash, since the rather dummy "pip install" shows an helper
notice and terminates with a zero (0) exit code.

This change is thought as a complement to the changes originally
proposed in pull request GH-8170.
2017-03-24 17:35:34 +01:00
Gilles Cornu b40d347944
ansible_local: Polish the new `pip_args` option
Ref GH-8170
2017-03-24 00:01:17 +01:00
James Carr 7e2e5654ed
ansible_local: Add `pip_args` option
With this new option, it is now possible to pass additional arguments to
pip command when the `install_mode` is "pip".

(@gildegoma reworded the original commit message of pull request GH-8170)
2017-03-24 00:01:14 +01:00
Chris Roberts 7a03c6e013 Add /bin/docker to path list for installation verification 2017-03-20 11:38:44 -07:00