-
Bug
-
Resolution: Done
-
Minor
-
None
-
None
-
False
-
-
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.