Jdup is a command-line tool designed to simplify and automate the process of finding and replacing configuration lines across a fleet of Juniper devices running Junos OS. It leverages multi-threading to perform changes in parallel, ensuring efficiency, and incorporates critical safety features like commit check and automatic rollback to prevent faulty configurations from being activated.
- ⚡ Parallel Execution: Uses a thread pool to apply configurations to multiple devices simultaneously, drastically reducing the time required for large-scale changes.
- 🛡️ Safe & Reliable: Performs a
commit checkbefore every commit. If the check fails, the script automatically rolls back the changes, leaving the device in its original state. - 💾 Automated Backups: Before making any changes, the script finds and saves the specific configuration lines that will be modified.
- 📝 Detailed Logging: Creates comprehensive logs for each run, including a main script log, individual device session logs, and detailed error logs for failed commits.
- 🔄 Smart Duplicate: Intelligently handles
deactivatestatements by creating a correspondingsetstatement for the new configuration while preserving the deactivation. - 🎨 User-Friendly Interface: Provides a clean, colored output for easy tracking of successes and failures, with a final summary of the entire operation.
- Load Devices: Reads device connection details (IP, credentials) from a CSV file.
- Connect: Establishes SSH connections to the devices.
- Find & Backup: Searches for configuration lines matching the specified string and saves them to a backup file in the
logsdirectory. - Generate New Config: Creates the new configuration by replacing the match string with the duplicate string.
- Apply & Verify: Loads the new configuration, runs
commit checkto validate it. - Commit or Rollback:
- If validation is successful, it commits the changes.
- If validation fails, it runs
rollback 0and logs the error.
- Report: Displays a summary of which devices were updated successfully and which failed.
If using jdup.exe then skip this part
-
Clone the repository:
git clone https://github.com/shahedfardous/jdup.git cd jdup -
Create a virtual environment (recommended):
python -m venv .dup source .dup/bin/activate # On Windows, use: .dup\Scripts\activate
-
Install dependencies: A
requirements.txtfile is included for easy installation.pip install -r requirements.txt
-
Create a
devices.csvfile in the same directory with the following columns:hostname,ip,port,username,password.devices.csvexample:hostname,ip,port,username,password juniper-srx1,10.0.0.1,22,admin,your_password_123 juniper-mx1,10.0.0.2,22,admin,your_password_123
-
Run the script with the string to find, the string to replace it with, and the input file.
Syntax:
python jdup.py <"match_string"> <"duplicate_string"> -i <input_file.csv>
For the executable (jdup.exe): Syntax:
jdup.exe <"match_string"> <"duplicate_string"> -i <input_file.csv>
Examples:
- Duplicate an IP configuration:
python jdup.py "10.1.1.0/24" "10.2.2.0/24" -i devices.csv or python jdup.py "10.1.1.0/24" "10.2.2.0/24" -i devices.csv -l custom_logs
- Duplicate an IP configuration using the executable:
jdup.exe "10.1.1.0/24" "10.2.2.0/24" -i devices.csv or jdup.exe "10.1.1.0/24" "10.2.2.0/24" -i devices.csv -l custom_logs
- Duplicate an IP configuration:
All operational logs are stored in the logs/ directory (or a custom directory specified with -l).
script_log_...log: Main log for the script's execution.<hostname>_session.log: Full session log for each device.<hostname>_error_...log: Detailed error output if acommit checkorcommitfails.<hostname>_<match_string>_...conf: A backup of the configuration lines before changes were made.<hostname>_<duplicate_string>_...conf: The new configuration lines that were applied.
This project is licensed under the MIT License. See the LICENSE file for details.

