Improve case matching - strip domain part for -f/file read #164

Closed
opened 2021-11-20 15:20:33 +00:00 by ungleich-gitea · 9 comments

Created by: xorpierre

quote nico "Steven and I actually discussed having a second variable that only contains the hostname (i.e. with domain part stripped) so that matching is easier"

Issue I had:
host file with
a.bla.com
b.bla.com

case matching in manifest was only for a|b)
so matches failed when using cdist -f hostlist

*Created by: xorpierre* quote nico "Steven and I actually discussed having a second variable that only contains the hostname (i.e. with domain part stripped) so that matching is easier" Issue I had: host file with a.bla.com b.bla.com case matching in manifest was only for a|b) so matches failed when using cdist -f hostlist
Author
Owner

Created by: darko-poljak

@xorpierre @telmich Merged PR https://github.com/ungleich/cdist/pull/472.
Closing this issue.

*Created by: darko-poljak* @xorpierre @telmich Merged PR https://github.com/ungleich/cdist/pull/472. Closing this issue.
Author
Owner

Created by: darko-poljak

Sorry for close/reopen, wrong types/clicks.

@xorpierre Even better, you can use patterns in your case.
For host file with:
a.bla.com
b.bla.com

use case matching in manifest:
a*|b*)

*Created by: darko-poljak* Sorry for close/reopen, wrong types/clicks. @xorpierre Even better, you can use patterns in your case. For host file with: a.bla.com b.bla.com use case matching in manifest: `a*|b*)`
Author
Owner

Created by: darko-poljak

@telmich, @xorpierre I created pull request for this issue:
https://github.com/ungleich/cdist/pull/472

@xorpierre I don't know if this would solve your issue with stripped
domain part. Derived hostname lookup can contain fqdn or something like:
$ host chat.ungleich.ch
chat.ungleich.ch has address 78.47.116.245
$ host 78.47.116.245
245.116.47.78.in-addr.arpa domain name pointer static.245.116.47.78.clients.your-server.de.

If there is need in the script to use only first part of domain name (fqdn) until
the first dot then this can be done using:
target_name="${__target_host%%.*}"
and then you can construct your case statement using that variable.

*Created by: darko-poljak* @telmich, @xorpierre I created pull request for this issue: https://github.com/ungleich/cdist/pull/472 @xorpierre I don't know if this would solve your issue with stripped domain part. Derived hostname lookup can contain fqdn or something like: `$ host chat.ungleich.ch` `chat.ungleich.ch has address 78.47.116.245` `$ host 78.47.116.245` `245.116.47.78.in-addr.arpa domain name pointer static.245.116.47.78.clients.your-server.de.` If there is need in the script to use only first part of domain name (fqdn) until the first dot then this can be done using: `target_name="${__target_host%%.*}"` and then you can construct your **case** statement using that variable.
Author
Owner

Created by: darko-poljak

@telmich yes, on holidays with only mobile network, no wifi. It was raining :( so I took a look with my smartphone...

*Created by: darko-poljak* @telmich yes, on holidays with only mobile network, no wifi. It was raining :( so I took a look with my smartphone...
Author
Owner

Created by: telmich

@darko-poljak aren't you on holidays without Internet? :-)

That suggestion sounds good to me, so we have

__target_host - as is, command line, literally
__target_hostname - socket.gethostname, derived from __target_host
__target_fqdn - socket.getfqdn, derived from __target_host

in the end. We need to clearly document that __target_host is the primary variable and the content that the user passed in and that the others are just derived. I suggest to also include references to the python methods you mentioned.

*Created by: telmich* @darko-poljak aren't you on holidays without Internet? :-) That suggestion sounds good to me, so we have __target_host - as is, command line, literally __target_hostname - socket.gethostname, derived from __target_host __target_fqdn - socket.getfqdn, derived from __target_host in the end. We need to clearly document that __target_host is the primary variable and the content that the user passed in and that the others are just derived. I suggest to also include references to the python methods you mentioned.
Author
Owner

Created by: darko-poljak

Actually hostname (as returned from socket.gethostname), fqdn (returned from socket.getfqdn) and target host (exact value specified at cmd line or hostfile). @asteven , @telmich what do you think?

*Created by: darko-poljak* Actually hostname (as returned from socket.gethostname), fqdn (returned from socket.getfqdn) and target host (exact value specified at cmd line or hostfile). @asteven , @telmich what do you think?
Author
Owner

Created by: darko-poljak

Why not have hostname, domain name, fqdn and target host (value specified at cmd line/hostfile as is) and user can then use whichever best fits his/her needs?

*Created by: darko-poljak* Why not have hostname, domain name, fqdn and target host (value specified at cmd line/hostfile as is) and user can then use whichever best fits his/her needs?
Author
Owner

Created by: xorpierre

Alternative: make it work that I dont have to use the FQDN in the file. Even with search domain.tld in resolv.conf that doesnt work with cdist. Works fine with ssh&co

*Created by: xorpierre* Alternative: make it work that I dont have to use the FQDN in the file. Even with search domain.tld in resolv.conf that doesnt work with cdist. Works fine with ssh&co
Author
Owner

Created by: telmich

@asteven do you remember if we had good arguments to not provide this variable (besides finding an appropriate name)?

I think we discussed that it can easily be matched with ${__target_host%%.*} (which is true), however I think that "Parameter Expansion" (as bash calls it) is actually rather hard to read, even though easily applicable.

I vote for adding __new_good_name_that_does_not_confuse_the_user, which contains only the hostname, as it might also be a good best practise for people to match on the hostname by default and use __target_host only when they need to distinguish two systems with the same hostname.

Comments? Ideas?

Pinging @dheule, too - you might have encountered this before, too

*Created by: telmich* @asteven do you remember if we had good arguments to _not_ provide this variable (besides finding an appropriate name)? I think we discussed that it can easily be matched with ${__target_host%%.*} (which is true), however I think that "Parameter Expansion" (as bash calls it) is actually rather hard to read, even though easily applicable. I vote for adding __new_good_name_that_does_not_confuse_the_user, which contains only the hostname, as it might also be a good best practise for people to match on the hostname by default and use __target_host only when they need to distinguish two systems with the same hostname. Comments? Ideas? Pinging @dheule, too - you might have encountered this before, too
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ungleich-public/cdist#164
No description provided.