Skip to content

PPA Tools PPA Tools: CSV

Summary

This module contains actions used to create CSV spreadsheets.

Actions

ppa_tools.csv.

create_from_dictionaries

Generate CSV data from a list of dictionaries & keys.

Minimum Plugin Version: 5.0.0

Input
  • header: a list of table column headers

  • keys: a list of corresponding dictionary keys, one for each header

  • dictionaries: a list of dictionaries to get the values of each key from

Output

The generated CSV as a string.

Example
  • Creating a CSV spreadsheet of Active Directory users in the Domain Admins group

  • Writing the CSV spreadsheet to a file

  • Sending the file as an email attachment

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
- active_directory.groups.get_users:
    distinguishedName: CN=Domain Admins,CN=Users,DC=Example,DC=Domain
  load:
    domain_controller: domain_controller
  save: domain_admins

- ppa_tools.csv.create_from_dictionaries:
    header:
      - Common Name
      - SAM Account Name
      - Email Address
    keys:
      - cn
      - sAMAccountName
      - mail
  load:
    dictionaries: domain_admins
  save: domain_admins_csv

- ppa_tools.files.write_text_file:
    name: domain_admins.csv
  load:
    contents: domain_admins_csv

- ppa.events.send_email:
    subject: Domain Admins Report
    html: >
      <html>
        <head>PPA Domain Admins Report</head>
        <body>The CSV spreadsheet is attached to this email.</body>
      </html>
    attachments:
      - domain_admins.csv

Headers & Keys

The header & keys lists must be the same length, & the attributes must be in the same order.

If a supplied key is missing from a dictionary, its value will be blank.

ppa_tools.csv.

create_from_table

Generate CSV data from a table header & rows.

Minimum Plugin Version: 5.0.0

Input
  • header: a list of table column headers

  • rows: a list of lists where each inner list contains each cell value

Output

The generated CSV as a string.

Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
- ppa_tools.csv.create_from_table:
    header:
      - Given Name
      - Surname
      - Locked
    rows:
      - - John
        - Smith
        - True
      - - Bruce
        - Wayne
        - False
  save: users_csv

- ppa_tools.files.write_text_file:
    name: users.csv
  load:
    contents: users_csv

- ppa.events.send_email:
    subject: Users Report
    html: >
      <html>
        <head>Users Report</head>
        <body>The CSV spreadsheet is attached to this email.</body>
      </html>
    attachments:
      - users.csv

Header & Row Length

Each list inside the rows input must be the same length as the supplied header.

ppa_tools.csv.

read_file

Read a CSV file into a list of dictionaries.

Minimum Plugin Version: 10.2.0

Input
  • name: the name of the CSV file to read

Columns & Row Lengths

The columns will be extracted from the first line of the CSV file.

Please ensure every row has one cell per column.

Output

A list of dictionaries where each dictionary is a row, & each key is a column name.

The columns are taken from the first line of the CSV file.

See the example below for more information.

Example

Example users.csv file:

1
2
3
sAMAccountName,givenName,sn,mail
first.user,first,user,first.user@domain.net
second.user,second,user,second.user@domain.net

Playbook snippet:

1
2
3
- ppa_tools.csv.read_file:
    name: users.csv
  save: users

The value of the users variable will be:

- sAMAccountName: first.user
  givenName: first
  sn: user
  mail: first.user@domain.net
- sAMAccountName: second.user
  givenName: second
  sn: user
  mail: second.user@domain.net