I generate a json from public cloud but ansible use this inventory.json so slow. pls tell me why my json like this:
{
"angelbeats": {
"hosts": ["10.193.0.24", "10.193.0.23"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"grammy": {
"hosts": ["10.193.2.5", "10.193.0.9", "10.193.10.4", "10.193.8.5"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"cdn": {
"hosts": ["10.193.0.12", "10.193.0.11", "10.193.2.7", "10.193.2.8"],
"vars": {
"ansible_ssh_user": "root"
}
},
"mdianying": {
"hosts": ["10.193.0.31"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"zkmq": {
"hosts": ["10.193.0.26", "10.193.0.27", "10.193.0.25"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"bmovie": {
"hosts": [],
"children": ["angelbeats", "growingpains", "forrestgump", "zkmq", "job", "tm", "inception"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"xxljob": {
"hosts": ["10.193.0.6"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"redis": {
"hosts": ["10.193.0.40", "10.193.2.13"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"tm": {
"hosts": ["10.193.0.13", "10.193.0.14", "10.193.0.16", "10.193.0.17", "10.193.0.15"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"dns": {
"hosts": ["10.193.0.100", "10.193.2.100", "10.193.10.10", "10.193.8.19"],
"vars": {
"ansible_ssh_user": "root"
}
},
"yctask": {
"hosts": ["10.193.8.15"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"cmovie": {
"hosts": [],
"children": ["angelbeats", "growingpains", "forrestgump", "zkmq", "job", "tm", "inception"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"forrestgump": {
"hosts": ["10.193.0.104", "10.193.2.101", "10.193.8.20", "10.193.10.11"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"pwapi": {
"hosts": ["10.193.0.28", "10.193.2.11", "10.193.8.10", "10.193.10.9"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"pwweb": {
"hosts": ["10.193.0.20", "10.193.0.19", "10.193.2.9", "10.193.2.10", "10.193.8.9", "10.193.8.8", "10.193.10.6", "10.193.10.7"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"pwtask": {
"hosts": ["10.193.0.29"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"apishow": {
"hosts": ["10.193.0.32", "10.193.8.11"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"inception": {
"hosts": ["10.193.0.10", "10.193.2.6", "10.193.8.7", "10.193.10.5"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"moviebi": {
"hosts": ["10.193.0.42", "10.193.8.18"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"yanchu": {
"hosts": ["10.193.0.35", "10.193.8.14"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"growingpains": {
"hosts": ["10.193.0.21", "10.193.0.22"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"goods": {
"hosts": ["10.193.0.33", "10.193.8.12"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"urm": {
"hosts": ["10.193.0.39", "10.193.2.12"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"job": {
"hosts": ["10.193.0.105"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
},
"order": {
"hosts": ["10.193.0.34", "10.193.8.13"],
"vars": {
"ansible_ssh_user": "wangluoli"
}
}
}
You need to create a _meta
section in your JSON:
The stock inventory script system detailed above works for all versions of Ansible, but calling --host for every host can be rather inefficient, especially if it involves API calls to a remote subsystem.
To avoid this inefficiency, if the inventory script returns a top level element called “_meta”, it is possible to return all of the host variables in one script execution. When this meta element contains a value for “hostvars”, the inventory script will not be invoked with --host for each host. This results in a significant performance increase for large numbers of hosts.