Bookmark this page

Guided Exercise: Configuring System Settings

In this exercise, you will configure system settings for network devices.

Outcomes

You should be able to:

  • Execute an ad hoc command that configures the name-server setting on an IOS device.

  • Perform a play that sets name servers on IOS devices.

  • Perform a play that sets name servers using a multivendor playbook.

  • Perform a play that sets host names, domain names, and name servers using a multivendor playbook.

Open a terminal window on the workstation VM and change to the ~/proj/ directory.

  1. Execute an ad hoc command to configure the name server on cs01.

    1. Execute an ad hoc command to display the current name-server settings for cs01.

      [student@workstation proj]$ ansible -m ios_command \
      > -a "commands='sh run | include ip name-server'" cs01
      cs01 | SUCCESS => {
          "changed": false,
          "stdout": [
              ""
          ],
          "stdout_lines": [
              [
                  ""
              ]
          ]
      }
    2. Execute an ad hoc command that sets 8.8.8.8 as a name server on cs01.

      [student@workstation proj]$ ansible -m ios_system -a "name_servers=8.8.8.8" cs01
      cs01 | SUCCESS => {
          "changed": true,
          "commands": [
              "ip name-server 8.8.8.8"
          ]
      }
    3. Execute an ad hoc command to display the new name-server settings on cs01.

      [student@workstation proj]$ ansible -m ios_command \
      > -a "commands='sh run | include ip name-server'" cs01
      cs01 | SUCCESS => {
          "changed": false,
          "stdout": [
              "ip name-server 8.8.8.8"
          ],
          "stdout_lines": [
              [
                  "ip name-server 8.8.8.8"
              ]
          ]
      }
  2. Perform a play that sets name servers on IOS devices.

    1. Compose a playbook named ios-nameservers1.yml that sets the name servers on members of the ios host group to 8.8.8.8 and 8.8.4.4.

      [student@workstation proj]$ cat ios-nameservers1.yml
      ---
      - name: sets nameservers on ios device
        hosts: ios
        vars:
          nameservers:
          - 8.8.8.8
          - 8.8.4.4
      
        tasks:
      
        - name: set nameservers
          ios_system:
            name_servers: "{{ nameservers }}"
    2. Perform the play found in your new playbook.

      [student@workstation proj]$ ansible-playbook ios-nameservers1.yml
    3. Execute an ad hoc command to display the updated name-server settings on cs01.

      [student@workstation proj]$ ansible -m ios_command \
      > -a "commands='sh run | include ip name-server'" cs01
      cs01 | SUCCESS => {
          "changed": false,
          "stdout": [
              "ip name-server 8.8.8.8 8.8.4.4"
          ],
          "stdout_lines": [
              [
                  "ip name-server 8.8.8.8 8.8.4.4"
              ]
          ]
      }
  3. Perform a play that configures name servers on VyOS and IOS devices according to a group variable.

    1. Add a list variable named nameservers to the group_vars/network/vars.yml file with 8.8.8.8 and 8.8.4.4 as list elements:

      [student@workstation proj]$ cat group_vars/network/vars.yml
      ansible_connection: network_cli
      nameservers:
      - 8.8.8.8
      - 8.8.4.4
    2. Compose a multivendor playbook named multi-vendor-nameservers1.yml that sets the name servers on members of the network host group according to items in the name servers list variable contained in the group_vars/network/vars.yml file. Make it use the network host group by default, but make it possible to apply the play to a particular target if the -e option is used with the target variable in the ansible-playbook command.

      [student@workstation proj]$ cat multi-vendor-nameservers1.yml
      ---
      - name: sets nameservers on devices
        hosts: network
      
        tasks:
      
        - name: set nameservers on ios devices
          ios_system:
            name_servers: "{{ nameservers }}"
          when: ansible_network_os == 'ios'
      
        - name: set nameservers on vyos devices
          vyos_system:
            name_servers: "{{ nameservers }}"
          when: ansible_network_os == 'vyos'
    3. Perform the play found in your new playbook, applying it to the spine02 device.

      1. Execute an ad hoc command to display the spine02's name servers before performing the play.

        [student@workstation proj]$ ansible -m vyos_command \
        > -a "commands='sh config | grep name-server'" spine02
        spine02 | SUCCESS => {
            "changed": false,
            "stdout": [
                ""
            ],
            "stdout_lines": [
                [
                    ""
                ]
            ]
        }
      2. Perform the play. Limit it to spine02.

        [student@workstation proj]$ ansible-playbook -l spine02 \
        > multi-vendor-nameservers1.yml
      3. Display the spine02 name servers after performing the play.

        [student@workstation proj]$ ansible -m vyos_command \
        > -a "commands='sh config | grep name-server'" spine02
        spine02 | SUCCESS => {
            "changed": false,
            "stdout": [
                "name-server 8.8.8.8\n    name-server 8.8.4.4"
            ],
            "stdout_lines": [
                [
                    "name-server 8.8.8.8",
                    "    name-server 8.8.4.4"
                ]
            ]
        }
  4. Perform a play that sets host name, domain name, and name servers using a multivendor playbook.

    1. Add a domain_name variable to the group_vars/network/vars.yml file.

      [student@workstation proj]$ cat group_vars/network/vars.yml
      ansible_connection: network_cli
      domain_name: lab.example.com
      nameservers:
      - 8.8.8.8
      - 8.8.4.4
    2. Compose a playbook named multi-vendor-host-domain-ns1.yml that sets the host name, domain name, and name servers.

      [student@workstation proj]$ cat multi-vendor-host-domain-ns1.yml
      ---
      - name: sets host name, domain name, nameservers
        hosts: network
      
        tasks:
      
        # --- host name ---
        - name: set host name on vyos device
          vyos_system:
            host_name: "{{ inventory_hostname }}"
          when: ansible_network_os == 'vyos'
      
        - name: set host name on ios device
          ios_system:
            hostname: "{{ inventory_hostname }}"
          when: ansible_network_os == 'ios'
      
        # --- domain name ---
        - name: set domain name on vyos device
          vyos_system:
            domain_name: "{{ domain_name }}"
          when: ansible_network_os == 'vyos'
      
        - name: set domain name on ios device
          ios_system:
            domain_name: "{{ domain_name }}"
          when: ansible_network_os == 'ios'
      
        # --- nameserver ---
        - name: set nameservers on ios devices
          ios_system:
            name_servers: "{{ nameservers }}"
          when: ansible_network_os == 'ios'
      
        - name: set nameservers on vyos devices
          vyos_system:
            name_servers: "{{ nameservers }}"
          when: ansible_network_os == 'vyos'
    3. Verify that the playbook syntax is valid.

      [student@workstation proj]$ ansible-playbook --syntax-check \
      > multi-vendor-host-domain-ns1.yml
      
      Playbook: multi-vendor-host-domain-ns1.yml
    4. Inspect the host name, domain name, and name servers on leaf02 by performing the play found in the multi-vendor-host-dnsinfo1.yml playbook you created in the section called “Guided Exercise: Backing Up Network Device Configurations”. Limit the hosts to leaf02.

      [student@workstation proj]$ ansible-playbook -l leaf02 \
      > multi-vendor-host-dnsinfo1.yml
      
      PLAY [multi-vendor play to display host name, domain name, nameservers] ********
      
      TASK [ios host, domain, nameserver] ********************************************
      skipping: [leaf02]
      
      TASK [display ios host settings] ***********************************************
      skipping: [leaf02]
      
      TASK [vyos host, domain, nameserver] *******************************************
      ok: [leaf02]
      
      TASK [display vyos host settings] **********************************************
      ok: [leaf02] => {
          "result.stdout": [
              "vyos",
              "",
              ""
          ]
      }
      
      PLAY RECAP *********************************************************************
      leaf02                     : ok=2    changed=0    unreachable=0    failed=0
    5. Perform the play found in your newly created playbook, multi-vendor-host-domain-ns1.yml, applying it only to leaf02.

      [student@workstation proj]$ ansible-playbook -l leaf02 \
      > multi-vendor-host-domain-ns1.yml
    6. Inspect the state of leaf02 after applying the multivendor change, again using multi-vendor-host-dnsinfo1.yml for that purpose.

      [student@workstation proj]$ ansible-playbook -l leaf02 \
      > multi-vendor-host-dnsinfo1.yml
      
      PLAY [multi-vendor play to display host name, domain name, nameservers] ********
      
      TASK [ios host, domain, nameserver] ********************************************
      skipping: [leaf02]
      
      TASK [display ios host settings] ***********************************************
      skipping: [leaf02]
      
      TASK [vyos host, domain, nameserver] *******************************************
      ok: [leaf02]
      
      TASK [display vyos host settings] **********************************************
      ok: [leaf02] => {
          "result.stdout": [
              "leaf02",
              "lab.example.com",
              "name-server 8.8.8.8\n    name-server 8.8.4.4"
          ]
      }
      
      PLAY RECAP *********************************************************************
      leaf02                     : ok=2    changed=0    unreachable=0    failed=0

This concludes the guided exercise.

Revision: do457-2.5-4693601