Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Systems nested hostgroups are only grouped by top-level hostgroup #27

Open
wzzrd opened this issue Aug 19, 2016 · 14 comments
Open

Systems nested hostgroups are only grouped by top-level hostgroup #27

wzzrd opened this issue Aug 19, 2016 · 14 comments

Comments

@wzzrd
Copy link

wzzrd commented Aug 19, 2016

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).

@agx
Copy link
Member

agx commented Aug 19, 2016

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.

@wzzrd
Copy link
Author

wzzrd commented Aug 19, 2016

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

@agx
Copy link
Member

agx commented Aug 23, 2016

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.

@smnmtzgr
Copy link

smnmtzgr commented Oct 11, 2016

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

@agx
Copy link
Member

agx commented Oct 11, 2016

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.

@smnmtzgr
Copy link

smnmtzgr commented Oct 11, 2016

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

@agx
Copy link
Member

agx commented Oct 11, 2016

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.

@timogoebel
Copy link
Member

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"

@smnmtzgr
Copy link

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

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

@smnmtzgr
Copy link

I have created this pull request: Pull Request #38

@agx
Copy link
Member

agx commented Oct 11, 2016

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

@timogoebel
Copy link
Member

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

agx added a commit that referenced this issue Oct 12, 2016
Foreman changed behviour in 1.12: the hostgroup_name does no longer
contain the parent hostgroups like " a / b / c " but the title does so
use this for the building the ansible groups. Fall back to
hostgroup_name for older versions.

Closes: #27
agx added a commit that referenced this issue Oct 12, 2016
Foreman changed behviour in 1.12: the hostgroup_name does no longer
contain the parent hostgroups like " a / b / c " but the title does so
use this for the building the ansible groups. Fall back to
hostgroup_name for older versions.

Closes #27
agx added a commit that referenced this issue Oct 12, 2016
Foreman changed behviour in 1.12: the hostgroup_name does no longer
contain the parent hostgroups like " a / b / c " but the title does so
use this for the building the ansible groups. Fall back to
hostgroup_name for older versions.

Closes #27
@agx
Copy link
Member

agx commented Oct 12, 2016

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

agx added a commit that referenced this issue Oct 13, 2016
Foreman changed behviour in 1.12: the hostgroup_name does no longer
contain the parent hostgroups like " a / b / c " but the title does so
use this for the building the ansible groups. Fall back to
hostgroup_name for older versions.

Closes #27
@gbus
Copy link

gbus commented Jan 10, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants