Ansible Level 1 - Test question 4

In the Ansible Level 1, question 4 in the test validation failed, I’ve shared the details below. However, I can see that the file got copied. May I know if there is any mistake in the playbook?
Question:

On jump host create a playbook /home/thor/ansible/playbook-t2q4.yml to 
copy /usr/src/finance-t2q4/devops-t2q4.txt file on same host 
at location /opt/finance-t2q4 with group and owner should be thor.

Note: Validation will try to run the playbook using command
ansible-playbook -i localhost playbook-t2q4.ymi so please make sure the 
playbook works this way without passing any extra arguments.

playbook:

- name: first play 
  hosts: localhost 
  connection: local 
  become: yes 
  tasks:
  - name: copy devops-t2q4 to finance-t2q4
    сору:
      src: /us/src/finance-t2q4/devops-t2q4.txt
      dest: /opt/finance-t2q4/devops-t2q4.txt
      owner: 'thor' 
      group: 'thor'
=========short test summary info============
FAILED ansible_copy_t2q4.py::test_t2q4 - NameError: name 'thor' is not defined
============================================

Hi @Srikanth_Reddy

Can you please confirm the task is from KodeKloud Engineer?
If so, Task 4 in Level 1 looks as follows:

What does your inventory file look like?

Hey @Santosh_KodeKloud ,
Thanks for the response.

Sorry for the confusion.
I wasn’t talking about task 4, rather I was taking about 4th question in level 1 test.
There is an option to take a test, right?
Screenshot 2025-02-15 at 18.46.23

Sorry!

The lab renders with random questions from a bunch. Unable to find identical question in test1.

Can you try removing the owner and group from the playbook?
If these values are unspecified, it uses the current user.

but doesn’t become: yes cause an issue? I suppose it runs as root.

can you tell me how you would write a playbook for this question? Or let me know if my understanding of this playbook is wrong.

- name: first play 
  hosts: localhost 
  connection: local 
  become: yes    #switches to root user(or any other user) based on ansible.cfg file 
  tasks:
  - name: copy devops-t2q4 to finance-t2q4   #this task copies file from src to 
    сору:                                    #dest with sudo. which would make 
      src: /us/src/finance-t2q4/devops-t2q4.txt #"root" the owner and group unless
      dest: /opt/finance-t2q4/devops-t2q4.txt. #specified otherwise using "owner"
      owner: 'thor'  #and "group" parameters.
      group: 'thor'

assuming creating files in that directory /opt/finance-t2q4 requires sudo privileges and the copied file owner and group should be thor.

True. This copy operation would require root, not specifying owner and group would not help.

Can you retry this lab, and see if you encounter the same lab?
If you get that, please share the complete screenshot of the lab, so that I can try to replicate or raise it internally.

I would write it in the same way.
Except, I would try it without 'thor' wrapped in quotes, I’ll try once without wrapping it and just passing thor. ( Though it would not make any difference with Ansible) But, our grader could be looking at value without quotes.
:slight_smile:

I don’t think there is an option to retake the test.
Initially I’d tried without quotes(owner: thor), after seeing that error I’ve added quotes(owner: 'thor').

One thing that I’d done, that might be the reason to fail the verification, is changing the directory permissions.
chmod 777 /opt/finance-t2q4