From 4d4e2c39f8144695c9a38b0325ed6fd6164760c7 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 4 Nov 2019 14:19:41 -0800 Subject: [PATCH] add some docs explaining ansible + docker --- .../docs/provisioners/ansible.html.md.erb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/website/source/docs/provisioners/ansible.html.md.erb b/website/source/docs/provisioners/ansible.html.md.erb index b19693706..4f4a481c1 100644 --- a/website/source/docs/provisioners/ansible.html.md.erb +++ b/website/source/docs/provisioners/ansible.html.md.erb @@ -402,3 +402,53 @@ all command line arguments through into this call; this is necessary for making sure that --extra-vars and other important ansible arguments get set. Note the quoting around the bash array, too; if you don't use quotes, any arguments with spaces will not be read properly. + +### Docker + +When trying to use Ansible with Docker, you need to tweak a few options. + +- Change the ansible_connection from "ssh" to "docker" +- Set a Docker container name via the --name option. + +On a CI server you probably want to overwrite ansible_host with a random name. + +Example Packer template: + +``` +{ + "variables": { + "ansible_host": "default", + "ansible_connection": "docker" + }, + "builders":[ + { + "type": "docker", + "image": "centos:7", + "commit": true, + "run_command": [ "-d", "-i", "-t", "--name", "{{user `ansible_host`}}", "{{.Image}}", "/bin/bash" ] + } + ], + "provisioners": [ + { + "type": "ansible", + "groups": [ "webserver" ], + "playbook_file": "./webserver.yml", + "extra_arguments": [ + "--extra-vars", + "ansible_host={{user `ansible_host`}} ansible_connection={{user `ansible_connection`}}" + ] + } + ] +} +``` + +Example playbook: + +``` +- name: configure webserver + hosts: webserver + tasks: + - name: install Apache + yum: + name: httpd +``` \ No newline at end of file