
How it works...
In the network.yml file, we define the name_servers variable as a list of DNS servers, and we also define the ntp_servers variable, which defines the NTP servers that we want to configure on the IOS devices. Defining these parameters in the network.yml file applies these variables to all the devices within the network group.
We create a playbook and the first play targets all the hosts in the lan group (this includes both access and core devices) and, within this play, we reference two tasks:
- ios_system: This sets the hostname and the DNS servers on the devices.
- ios_ntp: This configures the NTP on the IOS devices and enables logging for NTP events.
Both these modules are declarative Ansible modules in which we just identify the state pertaining to our infrastructure. Ansible converts this declaration into the necessary IOS commands. The modules retrieve the configuration of the devices and compare the current state with our intended state (to have DNS and NTP configured on them) and then, if the current state does not correspond to the intended state defined by these modules, Ansible will apply the needed configuration to the devices.
When we run these tasks on all the LAN devices, the following configuration is pushed to the devices:
!
ip name-server 172.20.1.250 172.20.1.251
no ip domain lookup
ip domain name lab.net
!
ntp logging
ntp server 172.20.1.17
!