Uploaded image for project: 'Product Technical Learning'
  1. Product Technical Learning
  2. PTL-14302

grading script should fail on wrong ansible-navigator configuration file

XMLWordPrintable

    • False
    • Hide

      None

      Show
      None
    • False
    • en-US (English)

      Please fill in the following information:


      URL: https://rol.redhat.com/rol/app/courses/do457-2.3/pages/ch08s02
      Reporter RHNID: atcorduneanu@extraordy.com
      Section Title: Lab: Installation and Configuration
                                                                             

      Issue description

      If the student provides a bad configuration file for ansible-navigator, the grading script does not fail on this step, but it rather fails on subsequent steps making the source of the error less clear to the student.

      A student could choose to use (e.g.) 'ansible-inventory' instead of 'ansible-navigator inventory' to verify their work and oversee the error in the ansible-navigator configuration.

      Steps to reproduce:

      Provide a bad configuration for ansible-navigator like the following (the ansible key is missing between ansible-navigator and inventory)

       

      ---
      ansible-navigator:
          inventory:
            entries:
              - inventory.yaml
       ...

       

      Now say that the student must configure the inventory files with variables for all hosts. To meet the lab specifications, the student must eliminate all the variables except for ansible_user and ansible_ssh_private_key_file, that need be defined in inventory.yaml for all the hosts.

      Given the bad ansible-navigator configuration file, the grading will fail with the following content for inventory.yaml

      ---
      all:
        vars:
          ansible_user: student
          ansible_ssh_private_key_file: ~/.ssh/lab_rsa
        children:
          ...

      The error message is as follows

       - The 'inventory.yaml' file in the 'cr1' branch of the 'git@git.lab.example.com:student/compreview' Git repository does not define the 'ansible_user' variable with the 'student' value for all hosts.

      This is because the grading script relies on 'ansible-navigator inventory' to gather the inventory output:

       

      # FROM ~/.venv/labs/lib/python3.9/site-packages/do457/ansible/compreview-cr1/grade_removed_variables.yml
      
      - name: Run 'ansible-navigator inventory -i inventory.yaml'
        ansible.builtin.command:
          cmd: ansible-navigator inventory -i inventory.yaml --list
          chdir: "{{ temp_git['path'] }}"
        register: inventory_vars
       

      The task fails with the following error, but the play continues from the rescue section of the block.

      The variable inventory_vars then gets transformed into inventory_vars_json, but when accessed in the following grading tasks, the content is empty

      # FROM ~/.venv/labs/lib/python3.9/site-packages/do457/ansible/compreview-cr1/grade_removed_variables.yml
      
          - name: Include tasks/grade_removed_variables.yml
            vars:
              var_data: "{{ inventory_vars_json['_meta']['hostvars'] }}"
              var_key: ansible_user
              var_value: student
              var_inventory_file: inventory.yaml
              var_inventory_hosts:
                - arista1.lab.example.com
                - arista2.lab.example.com
                - iosxe1.lab.example.com
                - iosxe2.lab.example.com
                - junos1.lab.example.com
                - junos2.lab.example.com
            ansible.builtin.include_tasks: tasks/grade_removed_variables.yml
            loop: "{{ var_inventory_hosts }}"
            loop_control:
              label: >-
                Checking if the '{{ var_key }}' variable
                has been defined for the '{{ host_item }}' host.
              loop_var: host_item 

       

       

      So the error as received by the student is the following

      Workaround:

      Insert a block for ansible-navigator configuration check.

      Expected result:

      I would expect the grading script to fail on a wrong configuration of ansible-navigator.

        1. image-2024-11-17-10-30-15-532.png
          1.11 MB
          Andrei Tudor Corduneanu
        2. image-2024-11-17-10-31-36-245.png
          235 kB
          Andrei Tudor Corduneanu
        3. image-2024-11-20-05-20-40-614.png
          487 kB
          Michael Phillips

              glsbugs-automation@redhat.com PTL - Ansible Team
              atcorduneanu@extraordy.com Andrei Tudor Corduneanu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: