N is not known prior to proceeding. Every config.json has the same set of variables (variables with same name, but different values) defining different virtual hosts like:
config.json:
{
listen: 8081
name: dev1
cache: no
}
How should I write Ansible playbook to process such kind of data and generate virtual host configs from them?
I tried with_fileglob loops but they dont work. Maybe because with_fileglob is for one-dir listings. Module "find" isn included in my version of Ansible (1.9.4). And there`s a bigger problem: how to parse this kind of data and set Ansible variables to use it?
But how do I do this provided that (as I mentioned in the first post):
Files to include with vars_files ot include vars are located by the path configs*\config.json, and this path should be processed dynamically (the names of directories * and the number of directories are not known prior to proceeding). How do I load them dynamically travelling through the structure configs//.json? How to go through this structure of files dynamically?
Just loading each config.json does not solve the problem since in every config.json variables have the same name (as Ive mentioned it in my first post). E.g. variable 'name' from the configs/dir1/config.json will be overwritten by the variable 'name' loaded from configs/dir2/config.json . The solution could be add values from each config to some array. But I dont understand how is it possible to fill this array. Another solution could be generate vhost configs at each step after loading every config, but since Ansible does not support multiple tasks within one loop (as far as I know) I don`t understand how to do that.
But this kind of construction is not allowed (several actions at once: incude_vars + set_fact). And with_fileglob does`n work for files that are not in the same directory.
So the question is:
How I should build Ansible instructions to: (1) walk through the file structure configs/*.config.json, (2) load each json config, and (3) fill in array sites_array with data from each config.
Seems to be several actions for the same loop, which is not allowed. Is it possible to do it using Ansible?
I would be grateful if someone shows me the correct way to do this