How to automate configuration changes tracking with Github for Mikrotik devices? Ideally the script for exporting the configuration should reside on the Mikrotik device itself and be invoked periodically by the Mikrotik device.
user
Sure, I'd be happy to provide a basic template for a script that could automate configuration changes tracking with GitHub for Mikrotik devices. However, I should note that this is not something that can be done natively with Mikrotik devices.

That being said, you could use a third-party tool, such as Ansible, to remotely configure and manage Mikrotik devices, and then integrate GitHub using Ansible's integrations.

Here's a simple template configuration management in Ansible:

1. Install Ansible:

   - If you're using Ubuntu or Debian-based operating systems, you can install Ansible using the following command:

     ```
     sudo apt install ansible
     ```

   - If you're using a RedHat-based operating system (like RHEL or Fedora), you can use this command:

     ```
     sudo yum install ansible
     ```

2. Create a playbook file (playbooks/mikrotik.yml) and define your tasks in it.

   ```
   ---
   - name: Manage Mikrotik Configuration
     hosts: mikrotik
     become: yes

     tasks:

     # Define your tasks here
   ```

3. In your `tasks` block, you'd need to define specific roles that align well with those of Ansible parts.

   ```
   - name: Retrieve Facts
     setup:

   - name: Export Configurations
     copy:
       src: /var/www/html/export_configs/="{{' configuration_name' }}"
       dest: /configurations/
       mode: '0644'

   - name: Create Repository
     git:
       repo: git://github.com/{'username'}/{workspace_name}.git
       force: yes
       update: yes

   - name: Add files
     git:
       repo: git://github.com/{'username'}/{workspace_name}.git
       state: present
       clone: yes

   - name: Commit Changes
     git:
       repo: git://github.com/{'username'}/{workspace_name}.git
       state: present
       commit: yes

   - name: Push Commits
     git:
       repo: git://github.com/{'username'}/{workspace_name}.git
       state: present
       update: yes
       compress: no
   ```

   In the above-mentioned code, the Git command "git://github.com/{'username'}/{workspace_name}.git" must be substituted with your actual URL.

4. The last bit would be configuring the scheduled task, in your cron / var/spool/cron/root.

   ```
   * * * * ansible-playbook --check -i inventory playbooks/mikrotik.yml
   ```

Note: Please, prior to executing a scheduled task, ensure that your Mikrotik router/device is configured for SSH. In addition, please make sure the cron software is operational and the Ansible software is installed on the remote end.

Keep in mind that this is a shortcut to automating configuration tracking, and you can customize and adjust the playbook based on your network requirements.
assistant
How to automate configuration changes tracking with Github for Mikrotik devices? Ideally the script for exporting the configuration should reside on the Mikrotik device itself and be invoked periodically by the Mikrotik device.
user
To automate configuration changes tracking with Github for Mikrotik devices, you can follow these steps:

1. **Create a GitHub Repository:**
   First, create a new repository on GitHub where you will store your Mikrotik configuration files.

2. **Generate SSH Key on Mikrotik:**
   You need to generate an SSH key on your Mikrotik device to authenticate with GitHub. Use the following command to generate an SSH key:

   ```
   /user ssh-keys generate name=github-keys user=git comment="GitHub Keys"
   ```

3. **Add SSH Key to GitHub:**
   Now, copy the public key generated in the previous step and add it to your GitHub account. You can find the public key in the Mikrotik by running this command:

   ```
   /user ssh-keys print detail
   ```

   Then, go to GitHub, click on your profile picture > Settings > SSH and GPG keys > New SSH key, and paste the public key.

4. **Create a Script on Mikrotik:**
   Create a script on your Mikrotik device that exports the configuration and pushes it to the GitHub repository. Here is a sample script:

   ```bash
   /system script
   add name=git-commit owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
   /export file=config
   /tool fetch address=github.com src-path=config.rsc user=git mode=scp password=github-keys upload=yes
   /tool fetch address=github.com src-path=config.rsc user=git mode=ssh command=\"cd YourRepoName && git add config.rsc && git commit -m 'Automated commit from Mikrotik' && git push origin master\" upload=yes
   "
   ```

   Replace "YourRepoName" with the name of your GitHub repository.

5. **Schedule the Script:**
   Now, you need to schedule the script to run periodically. Use the following command to schedule the script to run every day at 00:00:

   ```
   /system scheduler
   add name="Git Commit" start-date=jan/01/1970 start-time=00:00:00 interval=1d on-event=git-commit policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
   ```

That's it! The Mikrotik device will now export its configuration and push it to the GitHub repository every day at midnight.
assistant