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

Fix resolvectl task returning white spaces #411

Merged
merged 1 commit into from
Jan 14, 2021
Merged

Fix resolvectl task returning white spaces #411

merged 1 commit into from
Jan 14, 2021

Conversation

netoarmando
Copy link
Member

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:

@@ -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:]'"
Copy link
Contributor

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.

Copy link
Member Author

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]>
Copy link
Contributor

@f-trivino f-trivino left a 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.

@netoarmando
Copy link
Member Author

Thanks @flo-renaud and @f-trivino!

@netoarmando netoarmando merged commit f9fb4ca into freeipa:master Jan 14, 2021
@netoarmando netoarmando deleted the issue-410 branch January 14, 2021 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants