ansible/ansible — pull request #2082 by mmoya (2013-02-14 11:10:23+00:00)
Title: Local chroot support

Add support for acting on a local chroot. This could be use for building a preconfigure virtual OS image starting from a raw distro bootstrap.

This feature requires running ansible as `root` and using connection `local`.

Includes two fixes for fails when `/proc` is not mounted.

Using
-----
Example of use with a Debian boostrap:

* `sudo deboostrap squeeze /tmp/squeeze-chroot`
* `sudo -E ansible-playbook -vvv -c local --chroot=/tmp/squeeze-chroot test.yml`

an example `test.yml` could be:

---
- hosts: localhost

tasks:

- name: echo something to temp
shell: echo Yaaayy! >/tmp/foobar.txt

- name: install a package
apt: pkg=less state=latest

works also by setting `chroot` in the playbook, like:

---
- hosts: localhost
connection: local
chroot: /tmp/squeeze-chroot
...

In principle any playbook would work by just adding `-c local --chroot=/path/to/dir`.

Notes
-----
Assumptions about existence of local files created by actions should not be made. For example `test/lookup_plugings.yml` fails in `test with_sequence, fenceposts 1` because it expects a local `/tmp/seq-00` created by previous action, but the creation actually took place in the chroot (ie: the file created was `$CHROOTDIR/tmp/seq-00` instead of `/tmp/-seq00`).