PPA Tools PPA Tools: Excel

Summary

This module contains actions used to create Microsoft Excel workbooks.

Actions

ppa_tools.excel.

create_from_dictionaries

Generate an Excel workbook & save it as a file in the task workspace.

Supports creating workbooks with a single sheet or multiple sheets.

The file will be saved using the xlsx extension.

Minimum Plugin Version: 5.0.0

Input (Single Sheet)
  • header: a list of column names

  • keys: a list of dictionary keys used to retrieve the value for each column

  • data: a list of dictionaries used to populate each row in the spreadsheet

  • file_name: the name of the file to create (an xlsx extension will be added if not provided)

Input (Multiple Sheets)
  • header: a list of column names

  • keys: a list of dictionary keys used to retrieve the value for each column

  • data: a dictionary containing sheet names & dictionaries used to populate each sheet

  • file_name: the name of the file to create (an xlsx extension will be added if not provided)

Output

Nothing is outputted by this action.

Example 1 - Single Sheet
  • Getting Remote Desktop Users from Active Directory & saving them as rdp_users
1
2
3
4
5
- active_directory.groups.get_users:
    distinguishedName: CN=Remote Desktop Users,CN=Builtin,DC=Example,DC=Domain
  load:
    domain_controller: domain_controller
  save: users
  • Creating an Excel spreadsheet from users with 4 attributes from each user
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
- ppa_tools.excel.create_from_dictionaries:
    header:
      - SAM Account Name
      - Email Address
      - Enabled
      - Locked
    keys:
      - sAMAccountName
      - mail
      - is_enabled
      - is_locked
    file_name: rdp_users.xlsx
  load:
    data: users
  • Sending the created file as an email attachment
1
2
3
4
5
6
7
8
9
- ppa.events.send_email:
    subject: Test Excel Spreadsheet
    html: >
      <html>
        <head>PPA Email Header</head>
        <body>PPA Email Body</body>
      </html>
    attachments:
      - rdp_users.xlsx
Example 2 - Multiple Sheets
  • Getting users from 3 groups in Active Directory

  • Creating an Excel spreadsheet with a sheet per group & 4 attributes per user

  • Sending the spreadsheet 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
set:
  group_names:
    - Remote Desktop Users
    - Domain Admins
    - Account Operators
  group_members: {}

steps:

  - name: Get Group Members
    sequence: group_names  # Loop over each group name defined above
    actions:

      # Look up the group using its sAMAccountName
      - active_directory.groups.by_samaccountname:
        load:
          sAMAccountName: loop.step.item.value
          domain_controller: domain_controller
        save: group

      # Get the users in the group
      - active_directory.groups.get_users:
        load:
          distinguishedName: group.distinguishedName
          domain_controller: domain_controller
        save: users

      # Update the group_members dictionary with the current group & its users
      - ppa_tools.dictionaries.insert:
        load:
          name: loop.step.item.value
          value: users
          dictionary: group_members
        save: group_members

  - name: Create & Send Spreadsheet
    actions:

    - ppa_tools.excel.create_from_dictionaries:
        header:
          - SAM Account Name
          - Email Address
          - Enabled
          - Locked
        keys:
          - sAMAccountName
          - mail
          - is_enabled
          - is_locked
        file_name: all_users
      load:
        data: group_members
      save: file

  - ppa.events.send_email:
      subject: Test Excel Spreadsheet
      html: >
        <html>
          <head>PPA Email Header</head>
          <body>PPA Email Body</body>
        </html>
      attachments:
        - "{{ spreadsheet_file_name }}"

Header & Keys Length

The length of the header & keys inputs must be the same.