Wednesday, February 12, 2020

Redhat Ansible - Playbook to read data from csv file


Redhat Ansible - Playbook to read data from csv file










For this week, let us see, how to read data from .csv file from Ansible Playbook. Since Ansible 2.8.x and above we have a module read_csv that will do the job for us

---
- hosts: localhost
  tasks:
  - name: read csv file
    read_csv:
      path: emp_details.csv
      delimiter: ','
    register: emp_details

  - name: print the data
    debug:
      msg: "{{item.empid}}  {{ item.empname }}  {{ item.empdept }} {{ item.empgrade}} {{ item.emplocation }} "
    with_items:
        "{{ emp_details.list }}"


Task 'read csv file' uses read_csv module and accepts path, delimiter as parameters; the read output is stored under emp_details variable

Task 'print the data' is printing each of the field value to the console as below



Happy Ansible folks !!!


1 comment:

  1. Do you realize there is a 12 word sentence you can say to your man... that will trigger intense feelings of love and impulsive attractiveness to you deep inside his heart?

    Because deep inside these 12 words is a "secret signal" that triggers a man's impulse to love, admire and care for you with all his heart...

    12 Words Who Fuel A Man's Desire Impulse

    This impulse is so built-in to a man's mind that it will drive him to try better than before to do his best at looking after your relationship.

    As a matter of fact, triggering this all-powerful impulse is absolutely binding to having the best ever relationship with your man that the moment you send your man one of these "Secret Signals"...

    ...You will instantly notice him expose his heart and soul to you in such a way he haven't expressed before and he will recognize you as the only woman in the universe who has ever truly attracted him.

    ReplyDelete