ansible coding help

66 views
Skip to first unread message

Nancy Desai

unread,
Feb 27, 2022, 3:12:16 PM2/27/22
to Ansible Development
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: 
6.PNG

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

Jan Bergner

unread,
Mar 5, 2022, 4:00:25 PM3/5/22
to Nancy Desai, Ansible Development

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

Am 27.02.22 um 21:12 schrieb Nancy Desai:
--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/2e9c5b1c-2a88-4870-9ee5-8d90f0982c81n%40googlegroups.com.
OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages