foreman_ansible_inventory icon indicating copy to clipboard operation
foreman_ansible_inventory copied to clipboard

Systems nested hostgroups are only grouped by top-level hostgroup

Open wzzrd opened this issue 9 years ago • 14 comments

I have a hostgroup hierarchy like this: RHEL7/Webserver/Production. With the current script, I only get automatic grouping on "Production", which is ambiguous, since I might as well have RHEL7/Database/Production.

What would be great if the script could either group automatically on all nested hostgroups (group for RHEL7, Webserver / Database and Production), or on the whole hierarchy (automatic group in Ansible would be RHEL7/Webserver/Production).

wzzrd avatar Aug 19 '16 10:08 wzzrd

On Fri, Aug 19, 2016 at 03:40:15AM -0700, Maxim Burgerhout wrote:

I have a hostgroup hierarchy like this: RHEL7/Webserver/Production. With the current script, I only get automatic grouping on "Production", which is ambiguous, since I might as well have RHEL7/Database/Production.

It will also create groups named RHEL7_Database_Production

What would be great if the script could either group automatically on all nested hostgroups (group for RHEL7, Webserver / Database and Production), or on the whole hierarchy (automatic group in Ansible would be RHEL7/Webserver/Production).

You can achieve that using parameters on the hostgroups and group_patterns.

agx avatar Aug 19 '16 10:08 agx

Mmh. I must be doing something wrong then, because I only get the 'Production' one.

wzzrd avatar Aug 19 '16 11:08 wzzrd

If I create a nested hostgroup a / b / c I get a ansible group foreman_hostgroup_a_b_c . You can check all ansible groups in the generated .index file.

agx avatar Aug 23 '16 05:08 agx

Hello, I can confirm that the issue of wzzrd exists. I have nested groups: datacenter / lan / distris-lan and with the dynamic inventory script I only get back "foreman_hostgroup_distris-lan" and "all". I've also checked the .index file.

I am using foreman 1.13 and Ansible 2.1.0

Regards, Simon

smnmtzgr avatar Oct 11 '16 06:10 smnmtzgr

On Mon, Oct 10, 2016 at 11:18:21PM -0700, Simon wrote:

Hello, I can confirm that the issue of wzzrd exists. I have nested groups: datacenter / lan / distris-lan and with the dynamic inventory script I only get back "distris-lan".

Please tell us how you came to this conclusion so we can debug this. Please allo paste your *.index file. It has all the generated host groups.

agx avatar Oct 11 '16 06:10 agx

I came to this conclusion by executing the inventory script manually or called by ansible-playbook. In both situations I get the following groups:

{ "all": [ "rz1-distri-05", ], "foreman_hostgroup_distris_lan": [ "rz1-distri-05", ] }%

But in foreman I have configured: datacenter/lan/distris-lan

smnmtzgr avatar Oct 11 '16 06:10 smnmtzgr

On Mon, Oct 10, 2016 at 11:24:13PM -0700, Simon wrote:

{ "all": [ "rz1-distri-05", ], "foreman_hostgroup_distris_lan": [ "rz1-distri-05", ] }%

Hmmm...see my comment:

https://github.com/theforeman/foreman_ansible_inventory/issues/27#issuecomment-241629145

We're "simply" grabbing the hostgroup_name from the host object so maybe this changed in 1.13 and foreman puts the short hostgroup name there now instead of the title as before? You can check by performing this api call:

 curl https://theforeman.org/api/1.13/apidoc/v2/hosts/<hostid>

If that's the case then there's a bug in Foreman itself.

agx avatar Oct 11 '16 06:10 agx

We're "simply" grabbing the hostgroup_name from the host object so maybe this changed in 1.13 and foreman puts the short hostgroup name there now instead of the title as before?

I don't recall such a change and just confirmed with 1.12. If you want to get the nested hierarchy, you need to use the hostgroup_title parameter. Let me give you an example: If you have two hostgroups: CoreOS and k8s-master-lxsbx (the latter being a child of the former) you get the following:

"hostgroup_name":"k8s-master-lxsbx","hostgroup_title":"CoreOS/k8s-master-lxsbx"

timogoebel avatar Oct 11 '16 07:10 timogoebel

I've checked this and the following is returned by the API:

"hostgroup_name":"distris-lan","hostgroup_title":"datacenter/lan/distris-lan"

smnmtzgr avatar Oct 11 '16 07:10 smnmtzgr

I have created this pull request: Pull Request #38

smnmtzgr avatar Oct 11 '16 11:10 smnmtzgr

On Tue, Oct 11, 2016 at 12:03:10AM -0700, Timo Goebel wrote:

We're "simply" grabbing the hostgroup_name from the host object so maybe this changed in 1.13 and foreman puts the short hostgroup name there now instead of the title as before?

I don't recall such a change and just confirmed with 1.12. If you want to get the nested hierarchy, you need to use the hostgroup_title parameter. Let me give you an example: If you have two hostgroups: CoreOS and k8s-master-lxsbx (the latter being a child of the former) you get the following:

"hostgroup_name":"k8s-master-lxsbx","hostgroup_title":"CoreOS/k8s-master-lxsbx"

The 1.10 instance I had when writing the inventory hat _name == _title. I double check tomorrow but I think we should just switch to

hostname_title

agx avatar Oct 11 '16 18:10 agx

That makes sense, the new parameter was added in 1.12.0, see http://projects.theforeman.org/issues/14190

timogoebel avatar Oct 12 '16 06:10 timogoebel

@timogoebel Thanks for digging this out. I've added a PR that prefers title of name.

agx avatar Oct 12 '16 18:10 agx

Please note that the release package download doesn't contain this fix. I had to clone from the repo to fix the issue, but a new release is probably needed.

gbus avatar Jan 10 '17 14:01 gbus