Skip to main content

Update

Set the DNS resolvers of an interface.

Writes a netplan file of the interface's own, such as /etc/netplan/osapi-dns-eth0.yaml for eth0, under the netplan definition that matches the interface, and applies it. A definition that matches several interfaces, such as cloud-init's all for en*, gives each of them the resolvers. An empty list keeps the interface's servers or domains, and an interface with no resolvers yet starts from none. override_dhcp drops the servers DHCP gives. It runs on the Debian family, and elsewhere, and in a container, reports skipped.

osapi client node dns update [flags]

Examples​

# Set the servers of an interface
osapi client node dns update --target web-01 --interface-name osapi0 --servers 9.9.9.9

# Set the search domains, and keep the servers
osapi client node dns update --target web-01 --interface-name osapi0 --search-domains corp.example --override-dhcp

# An interface with no resolvers yet
osapi client node dns update --target web-01 --interface-name osapi0 --servers 9.9.9.9

Result​

Set the servers of an interface, on one host:

$ osapi client node dns update --target web-01 --interface-name osapi0 --servers 9.9.9.9
Results:
  HOSTNAME  STATUS   INTERFACE NAME
  web-01    changed  osapi0

  1 host: 1 changed   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node dns update --target _all --interface-name osapi0 --servers 9.9.9.9
Results:
  HOSTNAME  STATUS   INTERFACE NAME
  web-01    changed  osapi0
  web-02    changed  osapi0

  3 hosts: 2 changed, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"hostname": "web-01",
"interface_name": "osapi0",
"status": "ok"
}
]
}

Set the search domains, and keep the servers, on one host:

$ osapi client node dns update --target web-01 --interface-name osapi0 --search-domains corp.example --override-dhcp
Results:
  HOSTNAME  STATUS   INTERFACE NAME
  web-01    changed  osapi0

  1 host: 1 changed   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node dns update --target _all --interface-name osapi0 --search-domains corp.example --override-dhcp
Results:
  HOSTNAME  STATUS   INTERFACE NAME
  web-01    changed  osapi0
  web-02    changed  osapi0

  3 hosts: 2 changed, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"hostname": "web-01",
"interface_name": "osapi0",
"status": "ok"
}
]
}

An interface with no resolvers yet, on one host:

$ osapi client node dns update --target web-01 --interface-name osapi0 --servers 9.9.9.9
Results:
  HOSTNAME  STATUS   INTERFACE NAME
  web-01    changed  osapi0

  1 host: 1 changed   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

On each host, where one cannot run it:

$ osapi client node dns update --target _all --interface-name osapi0 --servers 9.9.9.9
Results:
  HOSTNAME  STATUS   INTERFACE NAME
  web-01    changed  osapi0
  web-02    changed  osapi0

  3 hosts: 2 changed, 1 skipped   job 550e8400-e29b-41d4-a716-446655440000   trace 26e448c9dbe1c4a8d216a98c675079c9

Details:
  mac-01  skipped  operation not supported on this OS family

With --json, the API's response:

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"changed": true,
"hostname": "web-01",
"interface_name": "osapi0",
"status": "ok"
}
]
}

With the default settings, each example does this on the host:

ExampleOn the host
Set the servers of an interfacewrites /etc/netplan/osapi-dns-osapi0.yaml: network:\n version: 2\n ethernets:\n osapi0:\n nameservers:\n addresses:\n - 9.9.9.9\n search:\n - example.com; runs netplan generate; runs netplan apply
Set the search domains, and keep the serverswrites /etc/netplan/osapi-dns-osapi0.yaml: network:\n version: 2\n ethernets:\n osapi0:\n nameservers:\n addresses:\n - 1.1.1.1\n - 8.8.8.8\n search:\n - corp.example\n dhcp4-overrides:\n use-dns: false\n dhcp6-overrides:\n use-dns: false; runs netplan generate; runs netplan apply
An interface with no resolvers yetwrites /etc/netplan/osapi-dns-osapi0.yaml: network:\n version: 2\n ethernets:\n osapi0:\n nameservers:\n addresses:\n - 9.9.9.9; runs netplan generate; runs netplan apply

The command fails in these cases:

CallFlagsFails with
No servers and no search domains--interface-name osapi0give servers or search domains
An interface the host does not have, to keep the servers of--interface-name eth9 --search-domains corp.examplenot found
A server that is not an IP address--interface-name osapi0 --servers one.oneip
A search domain that is not a host name--interface-name osapi0 --search-domains "bad domain"hostname
More than 16 servers--interface-name osapi0 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1 --servers 1.1.1.1Servers
More than 16 search domains--interface-name osapi0 --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.b --search-domains a.bSearchDomains
An interface name that is not alphanumeric--interface-name "osapi0;reboot" --servers 9.9.9.9InterfaceName

Permission​

It needs the dns:write permission. osapi controller role get --name <role> shows what a role grants.

Flags​

FlagDescriptionDefault
--interface-nameThe interface, such as eth0, or a fact such as @fact.interface.primary (required)
--override-dhcpUse only these servers: drop the ones DHCP gives
--search-domainsThe search domains; the interface's own when empty
--serversThe DNS servers, IPv4 or IPv6; the interface's own when empty
-T, --targetTarget: _all, _any, hostname, or label (group:web.dev)_all

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml
--urlBase URL the CLI client connects to (controller.client.url)https://localhost:8080

Output tells how the result is printed, and what --json gives.