ansible coding help

Hello. I’m in an ansible coding class and I need some assistance if you can provide it. I’ve been given an assignment to create an ansible playbook on CentOS which will do the following: check users in a csv file to see if they have user accounts on the computer. If they do, when I run the playbook, I would get a success message. If they do not exist, I would get a failure message.

So my CSV file is named ckusers.csv and is made up for 5 usernames and only usernames. Each username is on a different line of the csv file.

There is a python script that was included in the assignment called ckeck_user.py that looks like this:

So far, I have this in my playbook knowing that I’m at least 70% wrong. The playbook is called ckusers.yml.

Hello Nancy,

you might start by simply printing your users-variable to see, what is really in there.

You could do that for example with the debug-module [1] like this:

  • name: “Print, what is in users”
    debug:
    msg: “{{ users }}”

You might also want to look up, how the read_csv-plugin actually works. [2]

In general, I highly recommend using the documentation frequently. Most of the time, you have quite decent odds of finding what you need in the examples-sections. Additionally, it will help you learning and is normally faster than hoping for a response via email.

Best,
Jan

[1] https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html
[2] https://docs.ansible.com/ansible/latest/collections/community/general/read_csv_module.html