Wrapping Ansible around the Fabric Assessment Tool
This is part two to the previous post about customizing the Microsoft Fabric Assessment tool. See the previous post or my GitHub to fork the tool for your own use.
Next Steps
Once I understood and repackaged the tool I was able to get it to output the needed files for the PowerBI dashboards. However, we wanted to be able to drop these files weekly into a SharePoint site so the dashboards were automatically updated.
Wrapping in Ansible
For this play I would need to simply define the variables in the playbook and then run the tool. Once that’s done I’ll use a custom role to upload this to a SharePoint folder where the PowerBI team can ingest it.
Building a new EE
To accomplish this I opted to build a new execution environment. I trimmed down to the minimal amount of packages in my requirements.txt and requirements.yml. However, this tool uses some features introduced in Python 3.10. At the time of development the base container used Python 3.9. To maintain future flexibilty between old and new I opted to install Python 3.11 from the Red Hat repository alongside 3.9.
I added Python 3.11 to my dnf install file. Sample entry below.
python3.11 [platform:rpm]
I then added some commands to 3.11 to the execution-environment.yml file to install the tool into only the 3.11 environment. A virtual environment would also be a good idea here. Example below.
append_final:
- RUN python3.11 -m ensurepip --upgrade
- RUN python3.11 -m pip install /tmp/fabric_audit-1.14-py3-none-any.whl
- RUN echo "Built by Justin on `date +%Y-%m-%d_%H:%M`" > $MNT/etc/motd
Main playbook development
The main playbook development is simple. I have a custom role written to write files from an EE to a SharePoint target. I hope to share this some time soon but using the API is relatively simple and your favorite LLM can surely help get started. Other than that, we’ll simply collect the needed variables and run the tool. I’ll show some sections of the playbook below.
I recommend using an app registration. I covered that in the previous post. If you need help, ask your favorite Azure/Entra admin.
vars:
# PowerBI
output_dir: "/tmp/pbi_out"
pbi_environment: "USGov"
pbi_authentication: "ServicePrincipal"
pbi_premium_metrics_id: "{{ metrics_id }}"
pbi_tenant: "{{ ss_pass }}"
pbi_client_id: "{{ ss_domain }}"
pbi_client_secret: "{{ ss_uname_nodomain }}"
ss_id: "{{ ss_id }}"
Once the needed variables are setup, they can be passed to the command directly or in my case I opted to use a shell script file.
#!/bin/bash
python3.11 -m fabric_audit -c "file://{{ output_dir }}" \
-m "{{ pbi_premium_metrics_id }}" \
-e "{{ pbi_environment }}" \
-a "{{ pbi_authentication }}" \
-sp "{{ pbi_client_id }}" \
-spt "{{ pbi_tenant }}" \
-sps "{{ pbi_client_secret }}" \
-f
Then I copy the file with the variables in it and run it with some debug statements. I’ve added a block here to catch errors and alert me in a messaging channel.
- name: Script run block
block:
- name: Copy run bash script
ansible.builtin.template:
src: files/run.sh
dest: /tmp/run.sh
mode: '0755'
register: template_copy_script
- name: Debug - Cat run.sh
ansible.builtin.debug:
msg: "{{ template_copy_script }}"
- name: Run PowerBI script
ansible.builtin.command: >
sh /tmp/run.sh
register: run_script
changed_when: false
- name: Debug - Run PowerBI script
ansible.builtin.debug:
msg: "{{ run_script }}"
Building on a previous post about error variables, i’ll debug those and send a message to a Teams channel in this case.
rescue:
- name: Debug - Print PBI update error
ansible.builtin.debug:
msg:
- "{{ ansible_failed_task.name }}"
- "{{ ansible_failed_result.stderr_lines }}"
- name: Move appended comments to drive - Send failure message to Teams
ansible.builtin.include_role:
name: custom_roles.teams_send_message_to_channel
public: true
vars:
smtc_team: "{{ teams_notification_team }}"
smtc_channel: "{{ teams_notification_channel }}"
smtc_message: |
<center><h2>The PowerBI Assessment automation has failed. Full error is below. <br></h2></center>
Playbook {{ ansible_play_name }} failed at task: {{ ansible_failed_task.name }} <br>
Error: {{ ansible_failed_result.stderr_lines }}
That’s all there is to this! If you already run your EE with 3.11 or greater this would be a simple tool to get up and running and offer some great value to an organization that’s heavily invested in PowerBI and/or Fabric.
Thanks for reading!