Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to import hosts with hostname/shortname only #1070

Closed
benjdudas opened this issue Nov 20, 2020 · 11 comments · Fixed by #1080
Closed

Option to import hosts with hostname/shortname only #1070

benjdudas opened this issue Nov 20, 2020 · 11 comments · Fixed by #1080

Comments

@benjdudas
Copy link

SUMMARY

A option which we could use in the plugin to remove the domain part from "host.domain" when importing a Foreman inventory would be very useful to have a inventory only with hostname/shortname of hosts imported from Foreman.

ISSUE TYPE
  • Feature Idea
@nesanton
Copy link
Contributor

Hi @benjdudas,
Could you elaborate a bit further on the value of this? How would Tower benefit from having short names?

@rcdlinux
Copy link

rcdlinux commented Nov 23, 2020

Hi nesanton,

Let me try to clarify this point because a big customer is requesting us that.

The customer has many network segments and they are connecting only with short name. When they need to identify another network segment the domain related to that segment is added "on the fly" during the automation process. Each segment has a corresponding domain name. Because of that, when Ansible Tower tries to contact a host, the same FQDN of this synced host from the Satellite inventory can point to many ip addresses according to network segment of this host.

Another point is that all hosts are registered into Satellite with only one domain, then a need to rack the foreman.py[1] script to remove the domain part (There is an option into Satellite Settings to remove the domain), but it is done when registering only. This option is not possible to use because there are more then 20k hosts already registered into Satellite.

Having a variable into foreman.yml to "enable/disable" the domain part would avoid the customer to controlling by hands the modification into foreman.py script in the Foreman collection.

[1] - Foreman collection plugin edited:
* /var/lib/awx/vendor/awx_ansible_collections/ansible_collections/theforeman/foreman/plugins/inventory/foreman.py

  - Line changed into script foreman.py: 
     grep -n self.inventory.add_host /var/lib/awx/vendor/awx_ansible_collections/ansible_collections/theforeman/foreman/plugins/inventory/foreman.py
     246:                host_name = self.inventory.add_host(host['name'].split('.')[0])

Thank you!

@evgeni
Copy link
Member

evgeni commented Nov 24, 2020

so we're trying (but failing a bit, sorry) to understand your issue:
Is it that issue that the hosts are wrongly named inside of Tower because of that, or that Tower tries to connect to the wrong IP/name? If the later, would it help you to be able to connect to the IP address reported by the API?

@rcdlinux
Copy link

Hi evgeni,

It's the first one!

Without modifying the line 246 as my previous post, the managed nodes are imported into Tower with FQDN, as the customer needs all managed nodes imported only with short name (without the domain), he is "maintaining" a custom version of the foreman.py script because there isn't a way to remove the domain officially with the script.

The customer didn't think it is an "issue" from foreman.py, but a "desired" feature to avoid customization of the original script (RFE) that he hopes we can have in these collection/plugin.

Let me know if it helps you!

@evgeni
Copy link
Member

evgeni commented Nov 24, 2020

Mhh.

For the later, you could've used compose, but that only allows to modify variables of a host, not the name itself.

I think this is an RFE against Ansible, to allow a common way to mangle the hostname in the same way compose does for variables. An inventory plugin should not be in the business of implementing this.

@rcdlinux
Copy link

rcdlinux commented Nov 25, 2020

Ok evgeni,

I understand you, but I guess a RFE against Ansible would demand another configs when importing the inventory, probably with performance impact when we have many managed nodes imported (I could see it from previous versions of foreman script and Satellite 6.6).
Since the foreman.py already have the collected hosts list, an option to save this list without the domain would be more direct and quickly to implement, any other changes into inventory could be made by Ansible later...

Could we have one variable in foreman.yml to redirect the code if this var is "true"?:
from:

  •             host_name = self.inventory.add_host(host['name'])
    

to:

  •             host_name = self.inventory.add_host(host['name'].split('.')[0])
    

What do you think?

Thank you!

@evgeni
Copy link
Member

evgeni commented Nov 25, 2020

No, I still think this should not be done inside our inventory, but if at all then in Ansible. But ideally you fix the data in Foreman/Satellite.

@rcdlinux
Copy link

Ok evgeni,

I know that Foreman/Satellite has a feature in Configuration/Settings which removes the domain when registering a host, but this can't be made for all already registered hosts, only new registered hosts. Unfortunately there are more than 20k hosts already registered in a customer environment and those hosts will not be passive to change.

The Tower docs has mentioned that the support is for inventory plugin templates, in this case the Foreman/Satellite plugin template don't have a feature to remove the domain part when importing the Foreman/Satellite hosts to Tower (please let me know if I'm wrong).

What I can understand based on your observation is that Ansible/Tower team should improve the inventory plugin template to best manipulate the hosts being imported (example: would be implement something like compose to remove domain part from FQDN)

Could you clarify if I'm summarizing correctly? A RFE with Ansible/Tower team would be the appropriate path?

I'm asking because I have already created one, but the recommendation was to have a RFE in Foreman.

@evgeni
Copy link
Member

evgeni commented Nov 27, 2020

Ansible and Tower are two completely different things ;-)

You opened an RFE against AWX/Tower, but it should be Ansible. But, I did some research, and maybe what I invision is actually implementable with current Ansible. I'll give it a shot and come back.

Just for the record, I think the requirement "I need shortnames in my inventory" is rather nonsense, as tomorrow another use will come and say "but I need to replace the domain of all my hosts". If we can make this templateable by the user (instead of a boolean switch), they can go and do whatever they want, and keep the pieces if they break it ;))

@evgeni
Copy link
Member

evgeni commented Nov 27, 2020

Have a look #1080 :)

@rcdlinux
Copy link

rcdlinux commented Nov 27, 2020

Hey evgeni++

I completely agree with you, if we could have this kind of changes templateable will be very useful! My insistence was because we didn't have any way to do it and the customer was maintaining a separated code for that and accounting us! I guess it can be useful for anyone who wants to use Foreman inventory short names like this customer ... ;-)

Now, they will have a way to do it and will be much more "easy" to plan and grow the environment without "racks in the code". For sure I will reinforce that templates with plugins will be the most suitable solution to go forward!

Thank you so much for helping us to achieve this feature here!!!

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

Successfully merging a pull request may close this issue.

4 participants