github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/website/source/docs/provisioners/ansible.html.md (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 - `empty_groups` (array of strings) - The groups which should be present in 55 inventory file but remain empty. 56 57 - `host_alias` (string) - The alias by which the Ansible host should be known. 58 Defaults to `default`. 59 60 - `ssh_host_key_file` (string) - The SSH key that will be used to run the SSH 61 server on the host machine to forward commands to the target machine. Ansible 62 connects to this server and will validate the identity of the server using 63 the system known_hosts. The default behaviour is to generate and use a 64 onetime key. Host key checking is disabled via the 65 `ANSIBLE_HOST_KEY_CHECKING` environment variable if the key is generated. 66 67 - `ssh_authorized_key_file` (string) - The SSH public key of the Ansible 68 `ssh_user`. The default behaviour is to generate and use a onetime key. If 69 this key is generated, the corresponding private key is passed to 70 `ansible-playbook` with the `--private-key` option. 71 72 - `local_port` (string) - The port on which to attempt to listen for SSH 73 connections. This value is a starting point. The provisioner will attempt 74 listen for SSH connections on the first available of ten ports, starting at 75 `local_port`. A system-chosen port is used when `local_port` is missing or 76 empty. 77 78 - `sftp_command` (string) - The command to run on the machine being provisioned 79 by Packer to handle the SFTP protocol that Ansible will use to transfer 80 files. The command should read and write on stdin and stdout, respectively. 81 Defaults to `/usr/lib/sftp-server -e`. 82 83 - `extra_arguments` (array of strings) - Extra arguments to pass to Ansible. 84 Usage example: 85 86 ``` 87 "extra_arguments": [ "--extra-vars", "\"Region={{user `Region`}} Stage={{user `Stage`}}\"" ] 88 ``` 89 90 - `ansible_env_vars` (array of strings) - Environment variables to set before running Ansible. 91 If unset, defaults to `ANSIBLE_HOST_KEY_CHECKING=False`. 92 Usage example: 93 94 ``` 95 "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ] 96 ``` 97 98 - `user` (string) - The `ansible_user` to use. Defaults to the user running 99 packer. 100 101 ## Limitations 102 103 The `ansible` provisioner does not support SCP to transfer files.