0

I'm trying to make use of Ansible for configuration management and centralized administration.

All the machines I'm interested about are actually containers on the host which is going to run Ansible.

Currently I am writing a dynamic inventory script that groups the different hosts and makes certain hostvars available per group and also per host.

How can I use the inventory information to run local tasks?

Example: I have a container named foo and the dynamic inventory defines certain items like IP address, cgroup limits and so on for it. How can I reuse that information before the guest container is even up, in order to generate (using the usual Jinja2 templates) the container configuration on the host?

1
  • You can also target the remote host and use "delegate_to: localhost" if that fits your usage better.
    – MillerGeek
    Commented Aug 23, 2015 at 21:58

1 Answer 1

3

If I understand correctly you need to access some ansible variables defined for a generic host. You can access all hosts variables by the dictionary hostvars, that has hostname as primary key, for your example:

{{ hostvars['foo']['ipv4']['address'] }}

Credits goes to:

1
  • That looks like what I'm looking for. Thanks. Commented May 25, 2015 at 10:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .