# changing inventory\_hostname when working with chroot connector

**URL:** <https://forum.ansible.com/t/changing-inventory-hostname-when-working-with-chroot-connector/13706>\
**Category:** Ansible Project\
**Created:** [October 17, 2013, 12:11pm UTC](https://forum.ansible.com/t/changing-inventory-hostname-when-working-with-chroot-connector/13706 "2013-10-17T12:11:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Hollick](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Matthew\_Hollick](https://forum.ansible.com/u/Matthew_Hollick)\
**Post date:** [October 17, 2013, 12:11pm UTC](https://forum.ansible.com/t/changing-inventory-hostname-when-working-with-chroot-connector/13706/1 "2013-10-17T12:11:23Z")

</div>

I am probably doing this completely wrong…

The playbook is for a system running openvz.  
It tries to clone a openvz container from an existing template then setup ssh using the chroot connector.  
The container is then booted.  
Finally it attempts to ssh to the container to make sure that everything has worked.

my vars file:

vzhome: /vz  
veprivate: $vzhome/private/$veid

my hosts file:

[container\_deploy]  
[scratch248.example.com](http://scratch248.example.com) veid=248 suite=wheezy arch=amd64

some of my playbook:

- hosts: container\_deploy  
gather\_facts: no  
connection: local  
vars\_files:
- vars/setup.yml

…

- include: tasks/clone.yml

- name: Clean existing known\_hosts entry

command: ssh-keygen -R $inventory\_hostname

- include: tasks/initialconfig.yml ansible\_connection=chroot inventory\_hostname=$veprivate

- include: tasks/verify.yml ansible\_connection=ssh

The variable inventory\_hostname is not passed through to the included initialconfig.yml playbook like ansible\_connection is. I assume that it is a bit special. I get the following error:

TASK: [Create Openvz configuration] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[scratch248.example.com](http://scratch248.example.com)]

TASK: [Rebuild locales] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[scratch248.example.com](http://scratch248.example.com)] =\> [scratch248.example.com](http://scratch248.example.com) is not a directory

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/var/tmp/ansible/deploy.retry

[scratch248.example.com](http://scratch248.example.com) : ok=6 changed=4 unreachable=1 failed=0

Any suggestions for how to do this in a more elegant manner, or at least one that will work? 😃

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 17, 2013, 5:58pm UTC](https://forum.ansible.com/t/changing-inventory-hostname-when-working-with-chroot-connector/13706/2 "2013-10-17T17:58:10Z")

</div>

inventory\_hostname is indeed a magic variable and cannot be set.

I’m trying to understand a little bit but it sounds like you want to configure it chroot and then talk to it normally?

I would do better if I understood the use case a little bit.

If you want to do that the “add\_host” module can mangle inventory but you might be better served by putting it into inventory twice and having the “build\_image” be one record and the host be another?
