2013-09-29 16:56:43 -04:00
|
|
|
---
|
2015-07-22 22:31:00 -04:00
|
|
|
description: |
|
|
|
|
The `ansible-local` Packer provisioner configures Ansible to run on the machine
|
|
|
|
by Packer from local Playbook and Role files. Playbooks and Roles can be
|
|
|
|
uploaded from your local machine to the remote machine. Ansible is run in local
|
|
|
|
mode via the `ansible-playbook` command.
|
|
|
|
layout: docs
|
|
|
|
page_title: 'Ansible (Local) Provisioner'
|
|
|
|
...
|
2013-09-29 16:56:43 -04:00
|
|
|
|
|
|
|
# Ansible Local Provisioner
|
|
|
|
|
|
|
|
Type: `ansible-local`
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The `ansible-local` Packer provisioner configures Ansible to run on the machine
|
|
|
|
by Packer from local Playbook and Role files. Playbooks and Roles can be
|
|
|
|
uploaded from your local machine to the remote machine. Ansible is run in [local
|
|
|
|
mode](http://docs.ansible.com/playbooks_delegation.html#local-playbooks) via the
|
|
|
|
`ansible-playbook` command.
|
2013-09-29 16:56:43 -04:00
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
|
|
|
The example below is fully functional.
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.javascript}
|
2013-09-29 16:56:43 -04:00
|
|
|
{
|
2014-10-20 13:55:16 -04:00
|
|
|
"type": "ansible-local",
|
|
|
|
"playbook_file": "local.yml"
|
2013-09-29 16:56:43 -04:00
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-09-29 16:56:43 -04:00
|
|
|
|
|
|
|
## Configuration Reference
|
|
|
|
|
|
|
|
The reference of available configuration options is listed below.
|
|
|
|
|
|
|
|
Required:
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `playbook_file` (string) - The playbook file to be executed by ansible. This
|
|
|
|
file must exist on your local system and will be uploaded to the
|
2013-09-29 16:56:43 -04:00
|
|
|
remote machine.
|
|
|
|
|
|
|
|
Optional:
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `command` (string) - The command to invoke ansible. Defaults
|
|
|
|
to "ansible-playbook".
|
2014-01-22 07:40:06 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `extra_arguments` (array of strings) - An array of extra arguments to pass to
|
|
|
|
the ansible command. By default, this is empty.
|
2014-01-22 07:40:06 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `inventory_groups` (string) - A comma-separated list of groups to which packer
|
|
|
|
will assign the host `127.0.0.1`. A value of `my_group_1,my_group_2` will
|
|
|
|
generate an Ansible inventory like:
|
2015-07-14 11:43:55 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.text}
|
2015-07-15 16:09:56 -04:00
|
|
|
[my_group_1]
|
|
|
|
127.0.0.1
|
|
|
|
[my_group_2]
|
|
|
|
127.0.0.1
|
|
|
|
```
|
2015-04-30 12:33:15 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `inventory_file` (string) - The inventory file to be used by ansible. This
|
|
|
|
file must exist on your local system and will be uploaded to the
|
2014-04-04 14:19:55 -04:00
|
|
|
remote machine.
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
When using an inventory file, it's also required to `--limit` the hosts to the
|
|
|
|
specified host you're buiding. The `--limit` argument can be provided in the
|
|
|
|
`extra_arguments` option.
|
2014-04-04 14:19:55 -04:00
|
|
|
|
|
|
|
An example inventory file may look like:
|
2014-10-20 13:55:16 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
``` {.text}
|
2014-04-04 14:19:55 -04:00
|
|
|
[chi-dbservers]
|
|
|
|
db-01 ansible_connection=local
|
|
|
|
db-02 ansible_connection=local
|
|
|
|
|
|
|
|
[chi-appservers]
|
|
|
|
app-01 ansible_connection=local
|
|
|
|
app-02 ansible_connection=local
|
|
|
|
|
|
|
|
[chi:children]
|
|
|
|
chi-dbservers
|
|
|
|
chi-appservers
|
|
|
|
|
|
|
|
[dbservers:children]
|
|
|
|
chi-dbservers
|
|
|
|
|
|
|
|
[appservers:children]
|
|
|
|
chi-appservers
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2014-04-04 14:19:55 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `playbook_dir` (string) - a path to the complete ansible directory structure
|
|
|
|
on your local system to be copied to the remote machine as the
|
|
|
|
`staging_directory` before all other files and directories.
|
2014-05-11 09:12:47 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `playbook_paths` (array of strings) - An array of paths to playbook files on
|
2013-09-29 16:56:43 -04:00
|
|
|
your local system. These will be uploaded to the remote machine under
|
|
|
|
`staging_directory`/playbooks. By default, this is empty.
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `group_vars` (string) - a path to the directory containing ansible group
|
|
|
|
variables on your local system to be copied to the remote machine. By default,
|
|
|
|
this is empty.
|
2014-09-10 18:37:05 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `host_vars` (string) - a path to the directory containing ansible host
|
|
|
|
variables on your local system to be copied to the remote machine. By default,
|
|
|
|
this is empty.
|
2014-09-10 18:37:05 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `role_paths` (array of strings) - An array of paths to role directories on
|
2013-09-29 16:56:43 -04:00
|
|
|
your local system. These will be uploaded to the remote machine under
|
|
|
|
`staging_directory`/roles. By default, this is empty.
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
- `staging_directory` (string) - The directory where all the configuration of
|
|
|
|
Ansible by Packer will be placed. By default this
|
|
|
|
is "/tmp/packer-provisioner-ansible-local". This directory doesn't need to
|
|
|
|
exist but must have proper permissions so that the SSH user that Packer uses
|
|
|
|
is able to create directories and write into this folder. If the permissions
|
|
|
|
are not correct, use a shell provisioner prior to this to configure
|
|
|
|
it properly.
|