Commit Graph

126 Commits

Author SHA1 Message Date
Gilles Cornu 4e451c6e99 provisioners/ansible_local: fix #6763
Before this change, the detection of a non-existing path on the guest
machine was considered as an error and lead to interrupt the current vagrant
action. This was actually a mistake to do so, since the config checks
are performed before many other vagrant actions than `provision`.
The config.validate phase is also intended to primarily check the options
sanity, but it cannot be too strict with the guest state (which can easily
get "out of automatic control").

With this change, we still apply these checks (when possible), but only warn
about possible configuration problems. This way, the subsequent
statements will happen anyway (e.g. ansible commands will be
executed, vagrant machine will be destroyed, etc.)
2016-01-17 11:27:23 +01:00
Gilles Cornu c2c1a443fd Merge commit 'refs/pull/upstream/6869' into gildegoma/ansible-bug-fixes
Fix #6793
2016-01-14 00:05:33 +01:00
Daniel Schreiber 9dbdb9397a fixing incorrect missing ansible error
At least for ansible 2.0.0.1 the command `ansible-galaxy --help` is inappropriate for testing if ansible is installed, as it yields an error:

```
vagrant@vagrant-ubuntu-trusty-64:~$ ansible-galaxy --help && echo "OK"          
Usage: ansible-galaxy [delete|import|info|init|install|list|login|remove|search|setup] [--help] [options] ...

Options:
  -h, --help     show this help message and exit
  -v, --verbose  verbose mode (-vvv for more, -vvvv to enable connection
                 debugging)
  --version      show program's version number and exit
ERROR! Missing required action
```
2016-01-13 23:05:39 +01:00
Gilles Cornu 1e38be237e provisioners/ansible: fix galaxy paths on Windows
Close #6757 and update previous fix for #6740 (#6741).

See also these places where the same regexp is used to address similar
"Windows cases":

 - ec85548bd6/plugins/provisioners/chef/provisioner/chef_solo.rb (L99-L103)
 - ec85548bd6/plugins/guests/windows/cap/rsync.rb (L6-L9)
2016-01-05 08:22:10 +01:00
char16t 07f3d0b00d Fix #6740: Ansible local provisioner: remove windows drive letter from path 2015-12-27 12:01:45 +03:00
Gilles Cornu ddbd2a4cfc provisioners/ansible: prefer ssh '-i' argument
In cd93721, I relied on a suprising combination of quotes to protect ssh
execution to strip the quoted path to the private key file.
Since any ssh command line argument can be passed via
`ANSIBLE_SSH_ARGS`, it is quite more readable and easy to rely on the
`-i` argument, which is not affected like `-o IdentityFile=...` and also
supports multiple occurences.

See also http://sourceforge.net/p/fuse/mailman/message/30498048/

Finally fix #6671

Note that I decided to not squash both commits for better
documentation and traceability.
2015-12-16 10:29:13 +01:00
Gilles Cornu cd93721f8f provisioners/ansible: use quotes for the IdentityFile OpenSSH command line arguments
Surprisingly (to me at least), a simple quote enclosure was not enough
to fix the problem.

Caveat: the stringified ansible-playbook command logged in verbose mode
is wrongly formatted (no quotes are escaped).

Fix #6671
2015-12-16 09:54:53 +01:00
Gilles Cornu 25ff027b08 provisioners/ansible_local: use the inventory directory
Like in the (remote) `ansible` provisioner, it is preferred to pass the
directory that contains the generated inventory file. This way, advanced
inventory usages can be achieved by adding more inventory files into the
same directory.

Related to #2103 and #6500

[ci skip]
2015-12-08 23:02:58 +01:00
Gilles Cornu a8d0c225c6 Merge pull request #6649 from rickard-von-essen:issue-6636
Close #6636

Note that there is no CHANGELOG entry for this bug fix, since the
`ansible_local` provisioner [#2103] has not been released yet.
2015-12-07 22:41:06 +01:00
Gilles Cornu a0980aa8be provisioners/ansible: minor code formatting change
[ci skip]
2015-12-07 22:30:13 +01:00
Gilles Cornu 850716b220 provisioners/ansible: remove erroneous comment
[ci skip]
2015-12-07 22:28:23 +01:00
Rickard von Essen 9f3ebef810 Support ansible install on RedHat derivates and Fedora.
Fixes #6636
2015-12-07 15:44:20 +01:00
Kamjar Gerami b7e9437a77
#3539 - Fixed syntax, language and logic according to comments made by reviewer in PR #6639 2015-12-04 10:05:07 +01:00
Kamjar Gerami 5cbbbb5e28 #3539 - Can't use alphanumeric patterns for box names in ansible.groups: Changed iteration logic for warning message and fixed regex typo 2015-12-04 01:29:22 +01:00
Kamjar Gerami 934bcf9419 #3539 - Can't use alphanumeric patterns for box names in ansible.groups: Host Range Pattern Regex, notification and updates to provisioning web source 2015-12-04 01:13:59 +01:00
Gilles Cornu 4c137a9b6b provisioners/ansible: fix comment indentation
[ci skip]
2015-12-03 09:36:57 +01:00
Gilles Cornu 9867281971 provisioners/ansible: allow symbol in `groups` key
After c49a146467, it makes even more sense
to support Symbol datatypes in `groups` option handling.
2015-12-03 09:34:53 +01:00
Gilles Cornu c49a146467 provisioners/ansible(both): alias String-to-Symbol
String and Symbol types are different when used as a Hash key. By
default the Vagrant machine names are set in Symbol format, but users
may write their `host_vars` entries with String keys. This is a very
simple way to ensure smooth experience, without having to coerce the
data types during the config validation (e.g. with a library like
Hashie, which is currently not in the Vagrant dependencies)

See also:
- https://bugs.ruby-lang.org/issues/5964#note-17
- https://github.com/intridea/hashie#keyconversion
2015-12-02 08:37:41 +01:00
Christian Henz 77b11a989c Implemented host_vars option. 2015-12-01 18:56:28 +01:00
Christian Henz dd4ae1a51c Parse and insert group variables into the generated inventory. 2015-12-01 18:56:28 +01:00
Gilles Cornu ee55379736 provisioner/ansible: support winrm connection mode
This is a first cut to resolve #5086.
2015-11-21 05:34:50 +01:00
Gilles Cornu 2384032446 provisioners/ansible: freeze a constant value
Kudos @sethvargo :)

[skip ci]
2015-11-20 00:21:41 +01:00
Gilles Cornu 6dbc74d814 provisioners/ansible: fix code indentation 2015-11-20 00:13:01 +01:00
Gilles Cornu c9fe02cea5 provisioners/ansible_local: remove repetitions 2015-11-20 00:11:44 +01:00
Gilles Cornu 74eb3109cf provisioners/ansible_local: fix a lame bug
I missed to rename the refactored exceptions as AnsibleCommandFailed in
the guest-based parts. The lack of unit tests for these parts hurts...
on my agenda, I swear!
See c1f3d114f5
2015-11-20 00:07:34 +01:00
Gilles Cornu 5659c3f2a0 provisioners/ansible: apply @sethvargo comments
Follow-up of code review of PR #6529
2015-11-19 23:42:01 +01:00
Gilles Cornu 819c9b6425 provisioners/ansible_local: align console outputs
Use "info" level for main tasks (installing ansible, running galaxy,
running playbook).
Use "detail" level for subsequent details.
2015-11-18 09:37:27 +01:00
Gilles Cornu c1f3d114f5 provisioners/ansible(both): add galaxy support
Close #2718
2015-11-17 22:08:29 +01:00
Gilles Cornu a0576349fe provisioners/ansible(both): reorganize i18n texts
These adaptations will make even more sense with the upcoming
introduction of `ansible-galaxy` support.
2015-11-17 22:08:18 +01:00
Gilles Cornu 75cc6ef8d3 provisioners/ansible_local: fix a str-to-sym bug
Without this change `ansible.version = "latest"` is not considered as
equivalent to `ansible.version = :latest`.
2015-11-12 09:14:35 +01:00
Gilles Cornu a3c077cbe0 Merge branch 'gildegoma/ansible-force-ssh-user'
Resolved conflicts in
  plugins/provisioners/ansible/config.rb
  plugins/provisioners/ansible/provisioner.rb
  test/unit/plugins/provisioners/ansible/provisioner_test.rb
  website/docs/source/v2/provisioning/ansible.html.md

ref #6348
2015-11-08 14:01:23 +01:00
Gilles Cornu 9bfdaf7e75 provisioners/ansible: introduce ansible_local
With this change, the existing host-based Ansible provisioner is
refactored to share a maximum of code with this new guest-based Ansible
provisioner.

At this stage of development, the existing unit tests are intentionally
modified as little as possible, to keep safe the existing funtionalities.

Other issues resolved by this changeset:
 - Display a warning when running from a Windows host [GH-5292]
 - Do not run `ansible-playbook` in verbose mode when the `verbose` option
   is set to an empty string.
2015-11-08 10:42:48 +01:00
Gilles Cornu dde94a3ce7 provisioners/ansible: add force_remote_user option
The benefits of the following "breaking change" are the following:
- default behaviour naturally fits with most common usage (i.e. always
  connect with Vagrant SSH settings)
- the autogenerated inventory is more consistent by providing both the
  SSH username and private key.
- no longer needed to explain how to override Ansible `remote_user` parameters

Important: With the `force_remote_user` option, people still can fall
back to the former behavior (prior to Vagrant 1.8.0), which means that
Vagrant integration capabilities are still quite open and flexible.
2015-11-02 09:03:15 +01:00
konomae ad9a7324c5 Fix invalid ini entry error when ansible_ssh_private_key_file contains spaces 2015-08-29 18:00:20 +09:00
Gilles Cornu 3842a1f710 provisioners/ansible: provide ssh identities via ANSIBLE_SSH_ARGS (when necessary)
When provisioning multiple machines in sequence (the default vagrant
behaviour), it doesn't make sense to require to provide the private ssh
key(s) via the custom ansible inventory script/file.

To align with the handling of multiple ssh keys per machine, we won't
rely any longer on `--private-key` command line argument, but only pass
the keys via `ANSIBLE_SSH_ARGS` environment variable.

Note that when vagrant generates the ansible inventory and that only one
key is associated to a VM, this step would be redundant, and therefore
won't be applied.

This change fixes the breaking change introduced by 3d62a91.
2015-07-10 08:51:17 +02:00
Luis Pabón f0718d620d provisioners/ansible: Put ssh key in the inventory
Vagrant 1.7.1 creates and injects new ssh keys for each virtual machine.
When it started ansible with the "parallel provisioning trick",
it would only send the ssh key of the targeted virtual machine.
With this change, vagrant now stores the ssh key for each virtual
machines directly in the generated ansible inventory, and thus allow
ansible parallelism.

Note that this change is not sufficient, as it would break vagrant
configuration based on a custom inventory (file or script). This issue
will be addressed in a next commit.

Signed-off-by: Luis Pabón <lpabon@redhat.com>
2015-07-10 08:39:49 +02:00
Nicholas Randon eb6aa2ac8c Allow Ansible provisioner to run reliably in parallel
The Ansible Vagrant provisioner has a race where the inventory file is
updated every time the provisioner runs unless a file is provided.

Therefore if Ansible attempts to provision two nodes in parallel, you
may see the following race:
   * System A writes the inventory file and calls Ansible.
   * System B starts to provision and truncates the file before
     creating a new one.
   * Ansible on system A now attempts to read the inventory
     file, which is blank. Ansible bombs out with "ERROR: provided
     hosts list is empty".

To fix this, we only allow Vagrant to update the inventory file if
it needs to.
2015-07-10 00:53:59 +02:00
Gilles Cornu 839a2e6fa6 provisioners/ansible: show ansible-playbook only when the verbose option is enabled
Revert 1c884fa4e5 which introduced the
following bug:

Instead of allowing to dump the `ansible-playbook` command details when
VAGRANT_LOG=debug was defined, it was then impossible to disable this
console output when VAGRANT_LOG was undefined (in such case,
``@logger.debug? systematically returns `true`)

In order to keep things simple and focused, it is preferable to drop the
bad idea to mix Ansible verbosity and Vagrant log level.

Fix #5803
2015-07-07 22:37:06 +02:00
Seth Vargo b92d4b21a1 Add UI::Interface#color? 2015-06-01 11:49:09 -04:00
Gilles Cornu f7894d9c8c provisioners/ansible: fix broken colorized output
After #5532 (e745436df3), it was no longer
possible to enable ansible colorized output. Even though
`ANSIBLE_NOCOLOR` has no effect *at the moment* in vagrant+ansible
integration, I agree to keep it for clarity and consistence.

The new `--no-color` behaviour (bug fix #5531) is now covered by a unit
test.

//cc @marsam, @sethvargo
2015-06-01 08:36:09 +02:00
Mario Rodas e745436df3 provisioners/ansible: disable color if Vagrant has no color [GH-5531] 2015-03-28 19:05:54 -05:00
Gilles Cornu cdd5d54208 provisioners/ansible: fix a typo in a comment
[ci skip]
2015-01-13 18:52:47 +01:00
Gilles Cornu 28e0646dc2 Fix typo error in CHANGELOG
Close #4860

[ci skip]
2015-01-12 10:59:07 +01:00
Gilles Cornu 2ecad8bb93 provisioners/ansible: increase connection timeout
This change helps to avoid troubles like reported in #5018 and #4860.

Note that for sake of configuration simplicity, no new `ansible.timeout`
option has been added. The users who want to set a different value can
rely on `ansible.raw_arguments`.
2015-01-12 10:54:01 +01:00
Gilles Cornu c3cae3d235 provisioners/ansible: add `IdentitiesOnly=yes`
This SSH option is always set, except when Vagrant is running from an
operating system fo the Solaris-family, as this parameter is not
supported by SunSSH. Logic taken from
bed1f8335f/lib/vagrant/util/ssh.rb (L116-L121)

Fix #5017
2015-01-12 08:58:29 +01:00
Gilles Cornu 118e223c33 provisioners/ansible: use Docker proxy when needed
Close #4071

Credits and best thanks to @jabclab
2014-12-08 21:43:21 +01:00
Gilles Cornu 3800103228 provisioners/ansible: improve comment wording
Get rid of the Joker, thanks to @maspwr :)
2014-12-07 22:34:19 +01:00
Gilles Cornu f96636587a provisioners/ansible: don't read/write known_hosts
Like Vagrant's default SSH behaviors (e.g ssh or ssh-config commands),
the Ansible provisioner should by default not modify or read the user
known host file (e.g. ~/.ssh/known_hosts).

Given that `UserKnownHostsFile=/dev/null` SSH option is usually combined
with `StrictHostKeyChecking=no`, it seems quite reasonable to bind the
activation/disactivation of both options to `host_key_checking`
provisioner attribute.

For the records, a discussion held in Ansible-Development mailing list
clearly confirmed that there is no short-term plan to adapt Ansible to
offer an extra option or change the behavior of
ANSIBLE_HOST_KEY_CHECKING. For this reason, the current implementation
seems reasonable and should be stable on the long run.

Close #3900

Related References:

- https://groups.google.com/forum/#!msg/ansible-devel/iuoZs1oImNs/6xrj5oa1CmoJ
- https://github.com/ansible/ansible/issues/9442
2014-11-30 09:55:48 +01:00
Gilles Cornu 178942cf27 provisioners/ansible: change arguments arrangement
- force `--connection=ssh` (any other modes like paramiko or smart are not
  supported)
- give the highest priority to `raw_arguments` for sake of simplicity (in
  usage, in code and in documentation)
- fix position of the `--limit` argument (the generated inventory could be
  shadowed by `raw_arguments`, while ansible.limit was able to override
  `raw_arguments`

ref #3396
2014-11-30 09:50:50 +01:00
Gilles Cornu 306c4f7eda provisioners/ansible: force --connection=ssh
When `--connection` argument is not specified, Ansible will use the
'smart' mode, which can either use `ssh` or `paramiko` transports,
depending of the version of OpenSSH available. If OpenSSH version is new
enough to support ControlPersist technology, `ssh` will be used.
See also http://docs.ansible.com/intro_configuration.html#transport.

In order to support some advanced features of Vagrant (e.g. multiple ssh
private key identities or ssh forwarding), the Ansible provisioner
already must force `ssh` connection mode.

Having to deal with the possible fallback to `paramiko` increase the
burden of special cases that Ansible provisioner must handle, without
any added value, as Vagrant is based on OpenSSH and its users are
usually using modern operating systems.

With this change, the Ansible provisioner will officially only support
`ssh`. It will still be possible to switch to another connection mode
via `raw_arguments`, but it will breach the "contract", and no
(community) support can be expected in such use case.

ref #3900, #3396
2014-11-30 09:50:50 +01:00