How do I create and update Medulla packages in bulk from a CSV file?
Applies to: Medulla Server
Version: Latest version compatible with the pkgs module
Environment: On-Premise / Linux
Category: Administration / Package management
Script: medulla_import_csv.py
The medulla_import_csv.py script allows you to create or update Medulla software packages in bulk from a CSV file.
Each line in the CSV file corresponds to a package. The script uses the same API as the Medulla administration console (mmc-agent, pkgs module).
Medulla thus handles:
- Organizing packages into the appropriate shares.
- Storing them in the database.
- Managing file permissions.
- Calculating package hashes.
- Synchronization with relays.
In particular, the script supports:
- The creation of multiple packages in a single operation.
- Updating existing packages.
- Importing Windows, Linux, and macOS packages.
- Defining installation and uninstallation commands.
- Associating additional files.
- Selecting organizations and shares.
- Performing a full verification before import.
- Automatic backup before making changes.
- Resuming an import after a failure.
- Generation of a detailed report.
Note: The script modifies only the packages listed in the CSV file. Other packages on the server remain unchanged. The import does not trigger any deployments on workstations or activate any convergence.
1. What are the prerequisites?
The script must be run directly on the Medulla server with root privileges.
| Element | Prerequisite |
|---|---|
| System | Linux server hosting Medulla. |
| Python | Python 3, with no additional Python dependencies. |
| System user | root. |
| MMC account | An account with write permissions on the relevant shares. |
| Service | mmc-agent is operational and accessible. |
| Database | Access to the database configured for the pkgs module. |
| Backup | mysqldump or mariadb-dump. |
| Storage | Sufficient space for packages, temporary files, and backups. |
The script uses the following locations, among others:
| Path | Usage |
|---|---|
/etc/mmc/agent/config.ini |
mmc-agent configuration. |
/etc/mmc/agent/config.ini.local |
Possible local override. |
/etc/mmc/plugins/pkgs.ini |
pkgs module configuration. |
/etc/mmc/plugins/pkgs.ini.local |
Possible local override. |
/var/lib/pulse2/packages/ |
Medulla package directory. |
/var/lib/pulse2/package-server-tmpdir/ |
Temporary file preparation. |
/var/lib/pulse2/sauvegardes_import_csv/ |
Backups of imports. |
2. Where can I download the script and the sample CSV file?
Download the Python script
Download medulla_import_csv.py
From the Medulla server:
wget https://dl.medulla-tech.io/ma/medulla_import_csv.py
To update the script:
wget -N https://dl.medulla-tech.io/ma/medulla_import_csv.py
Download the sample CSV file
A sample CSV file is provided to help you prepare the packages.
It contains three sample packages:
- 7-Zip: installation and uninstallation of a Windows MSI package.
- Notepad++: using PowerShell scripts and an additional installer.
- Agent supervision: installing a Linux package.
The sample CSV file remains unchanged.
Note: The exact name of the CSV file on the download server must be verified. The script also allows you to generate the same template locally using its built-in examples.
Generate a CSV template
python3 medulla_import_csv.py --modele paquets.csv
This command creates a CSV file with the 21 columns recognized by the script and the three examples.
The script will not overwrite an existing file.
3. How do I use the script?
The standard procedure consists of four steps.
Step 1: Prepare the CSV
Download the sample file or generate a template:
python3 medulla_import_csv.py --modele paquets.csv
Edit the rows in a spreadsheet or text editor, specifying the packages to create or update.
Step 2: View organizations and shares
sudo python3 medulla_import_csv.py --lister
The command displays the shares accessible to the MMC account, their permissions, their quotas, and the associated organizations.
Step 3: Perform a full check
sudo python3 medulla_import_csv.py paquets.csv --verifier
This command performs all checks without modifying the packages or the CSV file:
- CSV format and structure.
- Values and referenced files.
- Medulla organizations and shares.
- Write permissions and quotas.
- UUIDs and existing packages.
- Ability to perform a backup of the database.
- Write permissions on directories.
- Available disk space.
Important: In this version, --verifier performs a full verification by connecting to Medulla. To verify only the CSV and files without connecting to the Medulla server, use --verifier --hors-ligne.
Step 4: Start the import
sudo python3 medulla_import_csv.py paquets.csv
The script reruns all checks, displays a summary, and asks for confirmation:
Lancer l'import (sauvegarde puis creation / mise a jour) ? [o/N]
Reply with o to continue.
If confirmation is denied, no changes are made.
To display more information:
sudo python3 medulla_import_csv.py paquets.csv -v
4. How do I verify a CSV file without a connection to Medulla?
Offline mode allows you to prepare and verify a CSV file on another computer.
python3 medulla_import_csv.py paquets.csv --verifier --hors-ligne
This mode checks:
- The encoding and CSV format.
- The columns and values.
- The existence and readability of the files.
- The extensions and generated commands.
- Duplicates within the CSV file.
It does not check:
- The organizations and shares that are actually available.
- Medulla permissions and quotas.
- Existing UUIDs on the server.
- The availability of the backup.
- The server's disk space.
Caution: A successful offline validation does not guarantee that the import will be accepted on the Medulla server. Perform a full validation on Medulla before publishing.
5. How do I prepare the CSV file?
The file must be saved in UTF-8.
UTF-8 files with a BOM, particularly those exported from Excel, are accepted.
The recognized delimiters are:
- The comma (
,). - The semicolon (
;).
The separator is automatically detected from the header.
Columns can be arranged in any order. Only the relevant columns are required.
Required columns
The CSV file must contain:
nom.partageororganisation.script_installationorscript_desinstallation.
Each row must also include a name, a destination, and at least one operation.
Complete list of columns
| Column | Description | Default value |
|---|---|---|
nom |
Package name (maximum 1,024 characters). | Required |
version |
Package version (maximum 50 characters). | 1.0 |
description |
Description (maximum 255 characters). | Package name |
os |
win, linux, or mac. | win |
partage |
Name of the Medulla share. | — |
organisation |
Organization whose share will be used. | — |
script_installation |
Installation file. | — |
arguments_installation |
Additional arguments. | — |
timeout_installation |
Maximum time in seconds. | 3600 |
script_desinstallation |
Uninstallation file. | — |
arguments_desinstallation |
Additional arguments. | — |
timeout_desinstallation |
Maximum time in seconds. | 3600 |
fichiers |
Additional files separated by |. | — |
redemarrage |
1 to restart after a successful operation, otherwise 0. | 0 |
inventaire_apres |
noforced, forced, or non. | noforced |
inventaire_logiciel |
Software associated with the inventory. | — |
inventaire_version |
Version of the associated software. | — |
inventaire_editeur |
Publisher of the associated software. | — |
licences |
Number of licenses, a positive integer or zero. | — |
editable |
oui: expert mode; non: manual mode. | oui |
uuid |
Package ID, added after creation. | Empty |
The version and inventory fields are limited to 50 characters. The licences field accepts up to 20 characters.
6. What packages does the sample file contain?
The sample CSV file contains three packages. These examples have not been modified.
Example 1: 7-Zip
| Parameter | Value |
|---|---|
| Name | 7-Zip |
| Version | 24.08 |
| Description | 7-Zip x64 silencieux |
| System | Windows |
| Share | global |
| Installation | installeurs/7z2408-x64.msi |
| Uninstallation | installeurs/7z2408-x64.msi |
| Inventory software | 7-Zip |
| Inventory version | 24.08 |
| Publisher | Igor Pavlov |
Example 2: Notepad++
| Parameter | Value |
|---|---|
| Name | Notepad++ |
| Version | 8.9.8.1 |
| System | Windows |
| Share | global |
| Installation | scripts/install_npp.ps1 |
| Arguments | -Silent |
| Uninstallation | scripts/uninstall_npp.ps1 |
| Additional file | installeurs/npp.8.9.8.1.Installer.x64.exe |
| Installation timeout | 1800 seconds |
Example 3: Agent supervision
| Parameter | Value |
|---|---|
| Name | Agent supervision |
| Version | 2.1 |
| System | Linux |
| Organization | Client A |
| Installation | scripts/install_agent.sh |
| Additional file | installeurs/agent_2.1_amd64.deb |
| Restart | 0 |
| Post-deployment inventory | forced |
Note: The paths to the example files must be adapted to your environment. The installers and scripts referenced must be present and readable before verification.
7. How do the installation and uninstallation scripts work?
Each package can contain two independent sections:
- Install Section: installs the software or performs the intended action.
- Uninstall Section: removes the software or performs the intended action.
The two sections do not run automatically one after the other. The operation is selected at the time of deployment in Medulla.
Commands generated based on the system
| System | Extension | Generated command |
|---|---|---|
| Windows | .ps1 | powershell.exe -NoProfile -ExecutionPolicy Bypass -File "script.ps1" |
| Windows | .bat / .cmd | cmd.exe /c "script.bat" |
| Windows | .vbs | cscript.exe //NoLogo "script.vbs" |
| Windows | .msi | msiexec.exe. |
| Windows | .exe | Direct execution. |
| Linux / macOS | .sh | /bin/bash "script.sh" |
| Linux / macOS | .py | python3 "script.py" |
| macOS | .pkg | installer -pkg "logiciel.pkg" -target / |
Special case for MSI files
Without custom arguments, the following commands are generated automatically.
Installation:
msiexec.exe /i "logiciel.msi" /qn /norestart
Uninstallation:
msiexec.exe /x "logiciel.msi" /qn /norestart
If custom arguments are provided, they are added to the command, and silent options are no longer added automatically.
Special case for EXE files
EXE programs are executed directly.
Silent installation options must be specified in arguments_installation.
If no arguments are provided, the script displays a warning: the installer may wait for user input until the timeout expires.
Special case for macOS PKG files
.pkg files are accepted only for installation.
To uninstall a macOS package, you must provide a .sh or .py script.
Return codes
A non-zero return code causes the operation to fail.
The maximum time limit is defined by the timeout_installation and timeout_desinstallation columns.
The default value is 3600 seconds.
8. How do I handle additional files?
Paths can be absolute or relative to the folder containing the CSV file.
Example of a relative path:
scripts/install.ps1
Example of an absolute path:
/opt/medulla/installeurs/setup.exe
The fichiers column allows you to add multiple additional files, separated by the | character.
installeurs/setup.exe|configuration/settings.ini|scripts/postinstall.ps1
All files are copied to the root of the package.
The script rejects:
- Files that do not exist or are unreadable.
- Empty scripts.
- File extensions that are incompatible with the target system.
- Empty entries in a file list.
- Two different files with the same name.
- The reserved files
conf.jsonandxmppdeploy.json.
An empty additional file triggers a warning but does not block the import.
Automatic script corrections
The script can apply certain corrections to copies of files uploaded to Medulla.
- Linux / macOS: Conversion of Windows CRLF line endings to LF for .sh and .py files.
- PowerShell: Adds a UTF-8 BOM to .ps1 scripts containing non-ASCII characters when the file is in UTF-8 without a BOM.
These corrections are applied only to the copies used for the package. The original files are not modified.
The fixes apply to scripts smaller than 10 MB.
9. How do organizations and shares work?
Each package is stored in a Medulla share.
The global share is intended for packages shared among authorized organizations.
An organization-specific share allows you to restrict access to the relevant packages.
In the CSV file, you can specify:
- The name of the share in
partage. - The organization’s name in the
organisationfield.
If both fields are filled in, they must correspond to the same share.
Use the full name of an organization
To avoid any ambiguity:
Entité racine > Revendeur > Client A
View available shares
sudo python3 medulla_import_csv.py --lister
Example result:
PARTAGE DROITS QUOTA ORGANISATION
Client A rw 0.2/1 Go Entite racine > Client A
Client B r illimite Entite racine > Client B
global rw illimite Partage global
In particular, the script rejects:
- An unknown organization or share.
- A share without write permissions.
- Insufficient quota.
- An ambiguous organization.
- Two shares with the same name.
- A change of share for an existing package.
The share change must be made in the Medulla console.
Note: The script does not create organizations or shares. They must exist before importation.
10. What checks are performed before the import?
The script performs six steps.
| Step | Check or operation | If an error occurs |
|---|---|---|
| 1. CSV format | Encoding, delimiter, columns, cells, and quotation marks. | Stop without making changes. |
| 2. Content | Files, values, organizations, permissions, quotas, UUIDs, and duplicates. | Stop without making changes. |
| 3. Server | Backup capability, write permissions, and disk space. | Stop without making changes. |
| 4. Confirmation | Summary presented and authorization requested. | Refusal: stop without making changes. |
| 5. Backup | Database and files of the updated packages. | Stop without making changes. |
| 6. Import | Creation or update of each package. | Failure reported; processing continues. |
The first five steps must succeed before any changes are made to the Medulla packages.
Format checks
The script checks for:
- UTF-8 encoding.
- Consistency of the separator.
- Unknown, missing, or duplicate columns.
- Rows containing an incorrect number of cells.
- Unclosed quotation marks.
- Line breaks and tabs in cells.
Completely empty rows are ignored.
Content checks
The script checks for the following, among other things:
- Required fields.
- The validity of the target system.
- Referenced scripts and files.
- Generated commands.
- Execution time limits.
- Inventory information.
- Restart and license values.
- Maximum field lengths.
- Duplicate name, version, and system combinations.
- Existing UUIDs.
Server checks
Before importing, the script also checks:
- The availability of mysqldump or mariadb-dump.
- Database login credentials.
- The ability to perform an actual backup.
- Write permissions on the CSV file.
- Write permissions for the temporary and backup directories.
- Available disk space.
For package files, the estimated space includes twice their total size, plus a 200 MB buffer.
The backup is also factored into the disk space requirements.
11. How do I create or update an existing package?
Create a new package
To create a package, leave the uuid column blank.
Medulla assigns a UUID upon creation.
The script immediately writes this identifier to the CSV file as soon as it is obtained.
Update a package
To update an existing package:
- Keep its UUID in the CSV file.
- Modify the desired information.
- Update the necessary files.
- Run the validation and import again.
sudo python3 medulla_import_csv.py paquets.csv
The package is updated without duplication.
Its old files are replaced by those specified in the CSV.
The creation date and original creator are retained.
Adopt a package already present in Medulla
If a package with the same name, version, system, and share already exists, but its UUID is not specified in the CSV, the script normally rejects the import to prevent a duplicate.
There are two possible solutions:
- Manually enter the UUID specified by the script.
- Use the
--adopter-existantsoption.
sudo python3 medulla_import_csv.py paquets.csv --adopter-existants
This option updates the existing package rather than creating a new one.
Its UUID is recorded in the CSV file after the backup.
Caution: The --adopter-existants option updates the corresponding packages. Check the batch summary before confirming the import.
12. How does automatic backup work?
Before the first modification, the script creates a timestamped backup folder:
/var/lib/pulse2/sauvegardes_import_csv/YYYYMMDD_HHMMSS/
This folder contains:
| File | Description |
|---|---|
pkgs.sql.gz |
Full backup of the pkgs database, when it has its default name. |
paquets_avant_mise_a_jour.tar.gz |
Files for existing packages affected by the updates. |
| Copy of the CSV | File status before import. |
RESTAURATION.txt |
Restoration procedure tailored to the server. |
The archive of old files is created only when the batch includes updates.
The name of the SQL archive depends on the name of the configured database.
Database configuration
The settings are read from:
/etc/mmc/plugins/pkgs.ini
/etc/mmc/plugins/pkgs.ini.local
The script accepts passwords in plain text or in {base64} format.
The password is passed to the backup utility via a protected temporary file, not via the command line.
The script checks the utility’s exit code and verifies that the dump is complete.
If the backup fails, the import will not start.
Change the backup folder
sudo python3 medulla_import_csv.py paquets.csv --dossier-sauvegarde /backup/medulla
Caution: Backups are not automatically deleted. It is recommended that you establish a retention policy and monitor disk space.
13. How do I restore packages after an import?
Each backup contains a file named RESTAURATION.txt with commands tailored to the environment.
The procedure is as follows:
- Stop mmc-agent.
- Restore the database.
- Restore the old files for the updated packages, if the archive exists.
- Restart mmc-agent.
Illustrative example for a database named pkgs:
systemctl stop mmc-agent
zcat /var/lib/pulse2/sauvegardes_import_csv/YYYYMMDD_HHMMSS/pkgs.sql.gz | mysql -u mmc -p
tar -xzf /var/lib/pulse2/sauvegardes_import_csv/YYYYMMDD_HHMMSS/paquets_avant_mise_a_jour.tar.gz -C /
systemctl start mmc-agent
The command to restore the files should only be run if the archive exists.
Important: The SQL restore reverts the entire pkgs database to its previous state. Changes made since the backup may be lost.
Directories for packages created during the import may remain on the disk.
Their UUIDs are listed in the CSV file and the report so they can be identified and deleted from the Medulla console.
14. What happens if a package fails during import?
When an error occurs during the publication of a package, the script reports the failure and continues processing the following packages.
The report shows the result of each operation.
If creation has already begun, the UUID may have been written to the CSV before the failure.
Running the same CSV file again will then resume processing as an update rather than creating a duplicate.
It is recommended that you:
- Review the import report.
- Identify and correct the cause of the error.
- Verify the CSV file and the UUIDs.
- Run the full validation again.
- Resume the import.
Caution: The script does not perform an automatic rollback if the publication fails. An interrupted operation may leave a package partially modified. The backup allows for a manual rollback.
15. How do I view the import report?
At the end of processing, the script generates a text report in the same folder as the CSV file.
For a file named paquets.csv, the report is:
paquets_rapport.txt
The report includes:
- The date of the import.
- The CSV file used.
- The MMC account.
- The backup folder.
- Packages created or updated.
- The corresponding UUIDs.
- Any errors.
- The overall summary.
| Status | Meaning |
|---|---|
CREE |
The package was created. |
MAJ |
The existing package has been updated. |
ECHEC |
The publication failed. |
To view the report:
cat paquets_rapport.txt
Reports from subsequent runs are appended to the same file.
16. How do I use verbose mode?
The -v or --verbeux option displays detailed information about checks and operations.
sudo python3 medulla_import_csv.py paquets.csv --verifier -v
In particular, it allows you to view:
- The connection to the mmc-agent service.
- Accessible shares, their permissions, and their quotas.
- The commands generated for each package.
- The results of the checks.
- Backup and disk space checks.
- Copied files.
- Medulla API calls, their durations, and their responses.
Passwords are not displayed in the diagnostic logs generated by the script.
17. What options are available?
| Option | Description |
|---|---|
--modele FILE |
Generates a sample CSV file. |
--lister |
Lists accessible organizations and shares. |
--verifier |
Performs all checks on the server without making any changes. |
--verifier --hors-ligne |
Verifies the format and files without connecting to the server. |
--adopter-existants |
Updates the corresponding existing packages and records their UUIDs in the CSV file. |
--oui |
Removes the confirmation prompt. |
--utilisateur NOM |
Uses an MMC account other than root. |
-v / --verbeux |
Displays operation details. |
--dossier-sauvegarde PATH |
Customizes the backup folder. |
--help |
Displays the script's help. |
MMC authentication
The default MMC account is root.
You will be prompted for the password upon launch.
To use a different account:
sudo python3 medulla_import_csv.py paquets.csv --utilisateur NOM
For automated execution, the script accepts the MMC_PASSWORD environment variable.
Security: Avoid storing passwords in plain text in scripts or commands that are saved in the shell history. Use an appropriate secret management mechanism.
18. What are the most common errors?
| Message | Probable cause | Solution |
|---|---|---|
fichier introuvable |
File missing or incorrect path. | Check the path specified in the CSV file. |
fichier vide |
Zero-size script. | Provide a valid script. |
extension non geree |
File extension is incompatible with the system. | Use a supported file extension. |
trop long |
Value exceeds the field limit. | Reduce the length of the text. |
deux fichiers differents nommes X |
File conflict. | Use distinct names. |
caractere non pris en charge par Windows |
Character incompatible with cp1252. | Adjust the arguments or the file name. |
meme nom/version/os |
Duplicate entry in the CSV. | Correct the affected rows. |
existe deja dans le partage |
Existing package without a specified UUID. | Specify the UUID or use --adopter-existants. |
uuid absent de Medulla |
Unknown identifier. | Correct the UUID or clear the cell to create a new package. |
partage inconnu |
Share does not exist or is inaccessible. | List the shares using --lister. |
organisation ambigue |
Multiple organizations have the same short name. | Use the full name. |
en lecture seule |
Account lacks write permissions. | Use an authorized account. |
quota |
Insufficient space on the share. | Free up space or increase the quota. |
mysqldump introuvable |
Backup utility missing. | Install the MariaDB or MySQL client. |
acces a la base refuse |
Incorrect SQL credentials or permissions. | Check the configuration of the pkgs module. |
espace disque insuffisant |
Insufficient storage. | Free up space or change the backup folder. |
mmc-agent injoignable |
Service unavailable or connection problem. | Check mmc-agent. |
To check the service:
systemctl status mmc-agent
19. Frequently asked questions
Can I import several hundred packages?
Yes. The script processes the lines one after another. The time required depends on the number of packages, the file sizes, and server performance.
Are the software packages automatically deployed?
No. The import creates or updates the packages. Deployment and convergence are separate operations.
Can I import packages for multiple organizations?
Yes. Each line can specify a different share or organization, depending on the MMC account’s permissions.
Can you create a package that contains only an uninstallation?
Yes. The script supports a package containing only an uninstall section.
Can I use Excel?
Yes. The file must be saved in UTF-8 CSV format.
Can the same CSV file be run multiple times?
Yes. UUIDs allow you to update existing packages without duplicating them.
Can I resume an interrupted import?
Yes, after correcting the error. The UUIDs included in the CSV file allow you to resume creations that have already been started.
Are the installation files downloaded automatically?
No. The files must be present on the server or on the computer performing an offline verification.
Can a package be moved to another share?
No. This operation must be performed in the Medulla console.
Can organizations be created from the CSV file?
No. Organizations and their shares must already exist.
Can imports be automated?
Yes. The --oui option suppresses the confirmation prompt.
sudo python3 medulla_import_csv.py paquets.csv --oui
Validation checks and backups still occur before publication.
20. Best practices
- Use the sample CSV file provided with the script.
- Keep the CSV files after importing to preserve the UUIDs.
- Perform a full verification using
--verifier. - Use
--listerto verify shares and permissions. - Test the first imports on a small batch.
- Use verbose mode for the first imports and diagnostics.
- Test installations and uninstallations on pilot workstations.
- Avoid the global share for packages reserved for a specific organization.
- Check the summary before using
--adopter-existants. - Keep the backups needed to roll back.
- Monitor the disk space used by backups.
- Review the report after each import.
21. Command summary
Download the script:
wget https://dl.medulla-tech.io/ma/medulla_import_csv.py
Update the script:
wget -N https://dl.medulla-tech.io/ma/medulla_import_csv.py
View help:
python3 medulla_import_csv.py --help
Generate a CSV template:
python3 medulla_import_csv.py --modele paquets.csv
List shares:
sudo python3 medulla_import_csv.py --lister
Check offline:
python3 medulla_import_csv.py paquets.csv --verifier --hors-ligne
Perform a full check on the server:
sudo python3 medulla_import_csv.py paquets.csv --verifier
Verify in detailed mode:
sudo python3 medulla_import_csv.py paquets.csv --verifier -v
Import packages:
sudo python3 medulla_import_csv.py paquets.csv
Import in detailed mode:
sudo python3 medulla_import_csv.py paquets.csv -v
Adopt existing packages:
sudo python3 medulla_import_csv.py paquets.csv --adopter-existants
Import without confirmation:
sudo python3 medulla_import_csv.py paquets.csv --oui
Customize the backup folder:
sudo python3 medulla_import_csv.py paquets.csv --dossier-sauvegarde /backup/medulla
View the report:
cat paquets_rapport.txt
Resources:
Python script: medulla_import_csv.py
Sample CSV file (name to be confirmed on the server): exemple_paquets.csv
Download directory: dl.medulla-tech.io/ma/
Medulla documentation: docs.medulla-tech.io