Similar external inventory to puppet hiera

Hello all,

I just discovered ansible recently and I can’t seem to find any documentation on accessing data similar to puppet hiera. My project currently builds a vagrant development box using puppet based on a bunch of configuration in yaml.

Here is a sample yaml file: https://github.com/protobox/protobox/blob/master/data/vagrant/common.yaml-dist

The goal would be to use a similar yaml file to dynamically install apache, nginx, php, add virtualhosts, etc. With puppet I can use hiera to easily lookup if nginx exists in the config and loop through and run the necessary code.

I am kind of at a loss as to how this could possibly work in ansible.

Also, some generic pysodocode:

if $nginx_yaml[‘install’] == 1 {
$nginx_yaml[‘virtualhosts’].each |host| {

add virtualhost for each host

}
}

In ansible I checked out loops and conditionals so would it be something like:

  • name: “install virtualhosts”
    command: /bin/cp something {{ item.name }}
    with_items: external_data[‘virtualhosts’]
    when: external_data[‘install’] == 1

Thanks for any advice, I love the thought of using ansible and everything it stands for!

it’s seldom that anyone uses “Hiera” and easy in the same sentence, but I’ll try to answer this just the same :slight_smile: I find the way it approaches descriptions of things to be very very complicated, and the very need for it a sign a lot of things were missing in the core. But that’s me.

Basically Ansible is 100% data driven – already using pure YAML for everything – so it doesn’t need extra ways to look up YAML files.

Things like “vars_files” (covered in the documentation) can easily pull in variables, and you have things like inventory variables built into the very core of the system.

Things like “group_vars/” and “host_vars/” directories easily allow you to assign variables to specific groups or hosts.

Where you need to interact with external systems, you can use external inventory scripts

For some cases where you need to pull data from things that further supplement your inventory (for instance, your inventory comes from EC2 but you’ve got some values in Redis), things like lookup plugins exist.

I guess the question is where would you like “external_data” to come from and we can best provide suggestions, but it sounds like you should dig into the docs about group_vars, host_vars, and vars_files and see how those work, and it should just click.

Let us know if not!