Ansible Docs: Review and Adapt PR #9864

- Remove undesired blank characters
- The examples attached to a specific option must be concise
- The original example is a tip for a non-standard use case
This commit is contained in:
Gilles Cornu 2018-05-25 08:29:12 +02:00
parent 57f12d115c
commit f9f0a9ac0d
2 changed files with 28 additions and 17 deletions

View File

@ -80,32 +80,20 @@ Some of these options are for advanced usage only and should not be used unless
`ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force`
Example:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "/vagrant/playbook.yml"
ansible.galaxy_role_file = "/vagrant/requirements.yml"
ansible.galaxy_role_path = "/etc/ansible/roles"
ansible.galaxy_command = "sudo ansible-galaxy install --force --ignore-certs --role-file=%{role_file} --roles-path=%{roles_path}"
end
end
```
- `galaxy_role_file` (string) - The path to the Ansible Galaxy role file.
By default, this option is set to `nil` and Galaxy support is then disabled.
Note: if an absolute path is given, the `ansible_local` provisioner will assume that it corresponds to the exact location on the guest system.
```ruby
ansible.galaxy_role_file = "requirements.yml"
```
- `galaxy_roles_path` (string) - The path to the directory where Ansible Galaxy roles must be installed
By default, this option is set to `nil`, which means that the Galaxy roles will be installed in a `roles` subdirectory located in the parent directory of the `playbook` file.
Be careful that `ansible-galaxy` command is by default run as vagrant user. Setting `galaxy_roles_path` to a folder like `/etc/ansible/roles` will fail silently : unable to write there, `ansible-galaxy` will extract the role a second time in a `/home/vagrant/.ansible/roles/`. Then if your playbook uses become: true user: root, it will fail with a "role was not found". To work around that, use `ansible.galaxy_command` to include a `sudo ansible-galaxy ...`.
- `groups` (hash) - Set of inventory groups to be included in the [auto-generated inventory file](/docs/provisioning/ansible_intro.html).
Example:

View File

@ -143,6 +143,29 @@ This section lists the _specific_ options for the Ansible Local provisioner. In
## Tips and Tricks
### Install Galaxy Roles in a path owned by root
<div class="alert alert-warning">
<strong>Disclaimer:</strong> This tip is not a recommendation to install galaxy roles out of the vagrant user space, especially if you rely on ssh agent forwarding to fetch the roles.
</div>
Be careful that `ansible-galaxy` command is executed by default as vagrant user. Setting `galaxy_roles_path` to a folder like `/etc/ansible/roles` will fail, and `ansible-galaxy` will extract the role a second time in `/home/vagrant/.ansible/roles/`. Then if your playbook uses `become` to run as `root`, it will fail with a _"role was not found"_ error.
To work around that, you can use `ansible.galaxy_command` to prepend the command with `sudo`, as illustrated in the example below:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.provision "ansible_local" do |ansible|
ansible.become = true
ansible.playbook = "playbook.yml"
ansible.galaxy_role_file = "requirements.yml"
ansible.galaxy_roles_path = "/etc/ansible/roles"
ansible.galaxy_command = "sudo ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force"
end
end
```
### Ansible Parallel Execution from a Guest
With the following configuration pattern, you can install and execute Ansible only on a single guest machine (the `"controller"`) to provision all your machines.