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?
How can I reuse the Ansible inventory for local tasks?
configuration;lxc;ansible
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:https://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hostshttps://serverfault.com/questions/638507/how-to-access-host-variable-of-a-different-host-with-ansible