-
Notifications
You must be signed in to change notification settings - Fork 32
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
Fix resolvectl task returning white spaces #411
Conversation
@@ -6,7 +6,7 @@ | |||
when: ansible_distribution == 'Fedora' and ansible_distribution_version is version('32', '<=') | |||
|
|||
- name: get DNS server from resolvectl (fedora >= f33) | |||
shell: "resolvectl status | grep 'Current DNS Server' | awk -F': ' '{print $2}'" | |||
shell: "resolvectl dns | grep -m1 'Link' | awk -F': ' '{print $2}' | tr -d '[:space:]'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this cmd on a 1minutetip machine but this would return a mangled output:
# resolvectl dns
Global:
Link 2 (eth0): 10.11.5.19 10.5.30.45
# resolvectl dns | grep -m1 'Link' | awk -F': ' '{print $2}' | tr -d '[:space:]'
10.11.5.1910.5.30.45
There are multiple issues:
- we can't assume that the DNS server is always configured at the link level, it could also be set for "Global: "
- multiple servers can be listed in each line
Something like resolvectl dns | grep -m1 ': [1-9]' | awk -F': ' '{print $2}' | cut -d' ' -f 1
should work (discard lines without any IP address and consider only the first one, extract the content after ': ', split with space and take only the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @flo-renaud! I wasn't expecting the link to return more than one address.
What I don't understand about the this issue is why the ipa-test-config.yaml you linked shows 2 addresses (one from Global another from Link supposedly) because the one from Global should have been set by a task called later create /etc/resolv.conf file from template
.
I failed to reproduce that.
The behaviour below shouldn't affect ipa-test-config.yaml
generation, but If that happens like the above, then the global IP might be 'master's address, not runner's IP.
These are the outputs from resolve dns
in various stages:
- Before executing any playbook:
$ resolvectl dns Global: Link 2 (eth0): 192.168.124.1
- After updating /etc/resolv.conf:
resolvectl dns Global: 192.168.124.252 Link 2 (eth0): 192.168.124.1
- Few minutes after executing that (because NM updated the
resolv.conf
)resolvectl dns Global: 127.0.0.1 Link 2 (eth0): 192.168.124.1
Replace task command to fetch DNS sever from `resolvectl dns` command, this will not return whitespaces. Execute grep -m1 to limit the number of lines to 1. Execute cut to return the first address. Issue #410 Signed-off-by: Armando Neto <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The command suggested by @flo-renaud works for me. I saw you updated the PR message as well, I'm approving it.
Thanks @flo-renaud and @f-trivino! |
Replace task command to fetch DNS sever from
resolvectl dns
command, this will not return whitespaces.Execute
grep -m1
to limit the number of lines to 1.Execute
tr
to remove possible spaces.Issue #410
Test runs:
fedora-32/test_webui_users
: http://freeipa-org-pr-ci.s3-website.eu-central-1.amazonaws.com/jobs/7f901ebe-3e24-11eb-9129-5254000d65adfedora-33/test_webui_users
: http://freeipa-org-pr-ci.s3-website.eu-central-1.amazonaws.com/jobs/ccc97ac6-3e2a-11eb-9129-5254000d65adfedora-rawhide/test_webui_users
" http://freeipa-org-pr-ci.s3-website.eu-central-1.amazonaws.com/jobs/d0da5f62-3e30-11eb-9129-5254000d65ad