github.com/rothwerx/packer@v0.9.0/website/source/docs/provisioners/ansible.html.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "Ansible Provisioner" 4 description: |- 5 The `ansible` Packer provisioner allows Ansible playbooks to be run to provision the machine. 6 --- 7 8 # Ansible Provisioner 9 10 Type: `ansible` 11 12 The `ansible` Packer provisioner runs Ansible playbooks. It dynamically creates 13 an Ansible inventory file configured to use SSH, runs an SSH server, executes 14 `ansible-playbook`, and marshals Ansible plays through the SSH server to the 15 machine being provisioned by Packer. 16 17 ## Basic Example 18 19 This is a fully functional template that will provision an image on 20 DigitalOcean. Replace the mock `api_token` value with your own. 21 22 ```json 23 { 24 "provisioners": [ 25 { 26 "type": "ansible", 27 "playbook_file": "./playbook.yml" 28 } 29 ], 30 31 "builders": [ 32 { 33 "type": "digitalocean", 34 "api_token": "6a561151587389c7cf8faa2d83e94150a4202da0e2bad34dd2bf236018ffaeeb", 35 "image": "ubuntu-14-04-x64", 36 "region": "sfo1" 37 } 38 ] 39 } 40 ``` 41 42 ## Configuration Reference 43 44 Required Parameters: 45 46 - `playbook_file` - The playbook to be run by Ansible. 47 48 Optional Parameters: 49 50 - `groups` (array of strings) - The groups into which the Ansible host 51 should be placed. When unspecified, the host is not associated with any 52 groups. 53 54 - `host_alias` (string) - The alias by which the Ansible host should be known. 55 Defaults to `default`. 56 57 - `ssh_host_key_file` (string) - The SSH key that will be used to run the SSH 58 server on the host machine to forward commands to the target machine. Ansible 59 connects to this server and will validate the identity of the server using 60 the system known_hosts. The default behaviour is to generate and use a 61 onetime key. Host key checking is disabled via the 62 `ANSIBLE_HOST_KEY_CHECKING` environment variable if the key is generated. 63 64 - `ssh_authorized_key_file` (string) - The SSH public key of the Ansible 65 `ssh_user`. The default behaviour is to generate and use a onetime key. If 66 this key is generated, the corresponding private key is passed to 67 `ansible-playbook` with the `--private-key` option. 68 69 - `local_port` (string) - The port on which to attempt to listen for SSH 70 connections. This value is a starting point. The provisioner will attempt 71 listen for SSH connections on the first available of ten ports, starting at 72 `local_port`. A system-chosen port is used when `local_port` is missing or 73 empty. 74 75 - `sftp_command` (string) - The command to run on the machine being provisioned 76 by Packer to handle the SFTP protocol that Ansible will use to transfer 77 files. The command should read and write on stdin and stdout, respectively. 78 Defaults to `/usr/lib/sftp-server -e`. 79 80 - `extra_arguments` (array of strings) - Extra arguments to pass to Ansible. 81 82 - `ansible_env_vars` (array of strings) - Environment variables to set before running Ansible. 83 If unset, defaults to `ANSIBLE_HOST_KEY_CHECKING=False`. 84 Usage example: 85 86 ``` 87 "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ] 88 ``` 89 90 ## Limitations 91 92 The `ansible` provisioner does not support SCP to transfer files.