"Fossies" - the Fresh Open Source Software Archive

Member "vagrant-2.2.14/website/pages/docs/provisioning/ansible.mdx" (20 Nov 2020, 6778 Bytes) of package /linux/misc/vagrant-2.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ---
    2 layout: docs
    3 page_title: Ansible - Provisioning
    4 sidebar_title: Ansible
    5 description: |-
    6   The Vagrant Ansible provisioner allows you to provision the guest using
    7   Ansible playbooks by executing "ansible-playbook" from the Vagrant host.
    8 ---
    9 
   10 # Ansible Provisioner
   11 
   12 **Provisioner name: `ansible`**
   13 
   14 The Vagrant Ansible provisioner allows you to provision the guest using [Ansible](http://ansible.com) playbooks by executing **`ansible-playbook` from the Vagrant host**.
   15 
   16 ~> **Warning:**
   17 If you are not familiar with Ansible and Vagrant already, we recommend starting with the [shell provisioner](/docs/provisioning/shell). However, if you are comfortable with Vagrant already, Vagrant is a great way to learn Ansible.
   18 
   19 ## Setup Requirements
   20 
   21 - **[Install Ansible](https://docs.ansible.com/intro_installation.html#installing-the-control-machine) on your Vagrant host**.
   22 
   23 - Your Vagrant host should ideally provide a recent version of OpenSSH that [supports ControlPersist](https://docs.ansible.com/faq.html#how-do-i-get-ansible-to-reuse-connections-enable-kerberized-ssh-or-have-ansible-pay-attention-to-my-local-ssh-config-file).
   24 
   25 If installing Ansible directly on the Vagrant host is not an option in your development environment, you might be looking for the [Ansible Local provisioner](/docs/provisioning/ansible_local) alternative.
   26 
   27 ## Usage
   28 
   29 This page only documents the specific parts of the `ansible` (remote) provisioner. General Ansible concepts like Playbook or Inventory are shortly explained in the [introduction to Ansible and Vagrant](/docs/provisioning/ansible_intro).
   30 
   31 ### Simplest Configuration
   32 
   33 To run Ansible against your Vagrant guest, the basic `Vagrantfile` configuration looks like:
   34 
   35 ```ruby
   36 Vagrant.configure("2") do |config|
   37 
   38   #
   39   # Run Ansible from the Vagrant Host
   40   #
   41   config.vm.provision "ansible" do |ansible|
   42     ansible.playbook = "playbook.yml"
   43   end
   44 
   45 end
   46 ```
   47 
   48 ## Options
   49 
   50 This section lists the _specific_ options for the Ansible (remote) provisioner. In addition to the options listed below, this provisioner supports the [**common options** for both Ansible provisioners](/docs/provisioning/ansible_common).
   51 
   52 - `ask_become_pass` (boolean) - require Ansible to [prompt for a password](https://docs.ansible.com/intro_getting_started.html#remote-connection-information) when switching to another user with the [become/sudo mechanism](http://docs.ansible.com/ansible/become.html).
   53 
   54   The default value is `false`.
   55 
   56 - `ask_sudo_pass` (boolean) - Backwards compatible alias for the [ask_become_pass](#ask_become_pass) option.
   57 
   58   ~> **Deprecation:**
   59   The `ask_sudo_pass` option is deprecated and will be removed in a future release. Please use the [**`ask_become_pass`**](#ask_become_pass) option instead.
   60 
   61 * `ask_vault_pass` (boolean) - require Ansible to [prompt for a vault password](https://docs.ansible.com/playbooks_vault.html#vault).
   62 
   63   The default value is `false`.
   64 
   65 * `force_remote_user` (boolean) - require Vagrant to set the `ansible_ssh_user` setting in the generated inventory, or as an extra variable when a static inventory is used. All the Ansible `remote_user` parameters will then be overridden by the value of `config.ssh.username` of the [Vagrant SSH Settings](/docs/vagrantfile/ssh_settings).
   66 
   67   If this option is set to `false` Vagrant will set the Vagrant SSH username as a default Ansible remote user, but `remote_user` parameters of your Ansible plays or tasks will still be taken into account and thus override the Vagrant configuration.
   68 
   69   The default value is `true`.
   70 
   71   -> **Compatibility Note:** This option was introduced in Vagrant 1.8.0. Previous Vagrant versions behave like if this option was set to `false`.
   72 
   73 - `host_key_checking` (boolean) - require Ansible to [enable SSH host key checking](https://docs.ansible.com/intro_getting_started.html#host-key-checking).
   74 
   75   The default value is `false`.
   76 
   77 - `raw_ssh_args` (array of strings) - require Ansible to apply a list of OpenSSH client options.
   78 
   79   Example: `['-o ControlMaster=no']`.
   80 
   81   It is an _unsafe wildcard_ that can be used to pass additional SSH settings to Ansible via `ANSIBLE_SSH_ARGS` environment variable, overriding any other SSH arguments (e.g. defined in an [`ansible.cfg` configuration file](https://docs.ansible.com/intro_configuration.html#ssh-args)).
   82 
   83 ## Tips and Tricks
   84 
   85 ### Ansible Parallel Execution
   86 
   87 Vagrant is designed to provision [multi-machine environments](/docs/multi-machine) in sequence, but the following configuration pattern can be used to take advantage of Ansible parallelism:
   88 
   89 ```ruby
   90 # Vagrant 1.7+ automatically inserts a different
   91 # insecure keypair for each new VM created. The easiest way
   92 # to use the same keypair for all the machines is to disable
   93 # this feature and rely on the legacy insecure key.
   94 # config.ssh.insert_key = false
   95 #
   96 # Note:
   97 # As of Vagrant 1.7.3, it is no longer necessary to disable
   98 # the keypair creation when using the auto-generated inventory.
   99 
  100 N = 3
  101 (1..N).each do |machine_id|
  102   config.vm.define "machine#{machine_id}" do |machine|
  103     machine.vm.hostname = "machine#{machine_id}"
  104     machine.vm.network "private_network", ip: "192.168.77.#{20+machine_id}"
  105 
  106     # Only execute once the Ansible provisioner,
  107     # when all the machines are up and ready.
  108     if machine_id == N
  109       machine.vm.provision :ansible do |ansible|
  110         # Disable default limit to connect to all the machines
  111         ansible.limit = "all"
  112         ansible.playbook = "playbook.yml"
  113       end
  114     end
  115   end
  116 end
  117 ```
  118 
  119 -> **Tip:**
  120 If you apply this parallel provisioning pattern with a static Ansible inventory,
  121 you will have to organize the things so that [all the relevant private keys are
  122 provided to the `ansible-playbook` command](https://github.com/hashicorp/vagrant/pull/5765#issuecomment-120247738).
  123 The same kind of considerations applies if you are using multiple private keys
  124 for a same machine (see [`config.ssh.private_key_path` SSH setting](/docs/vagrantfile/ssh_settings)).
  125 
  126 ### Force Paramiko Connection Mode
  127 
  128 The Ansible provisioner is implemented with native OpenSSH support in mind, and there is no official support for [paramiko](https://github.com/paramiko/paramiko/) (A native Python SSHv2 protocol library).
  129 
  130 If you really need to use this connection mode though, it is possible to enable paramiko as illustrated in the following configuration examples:
  131 
  132 With auto-generated inventory:
  133 
  134 ```ruby
  135 ansible.raw_arguments = ["--connection=paramiko"]
  136 ```
  137 
  138 With a custom inventory, the private key must be specified (e.g. via an `ansible.cfg` configuration file, `--private-key` argument, or as part of your inventory file):
  139 
  140 ```ruby
  141 ansible.inventory_path = "./my-inventory"
  142 ansible.raw_arguments  = [
  143   "--connection=paramiko",
  144   "--private-key=/home/.../.vagrant/machines/.../private_key"
  145 ]
  146 ```