<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chirag Mahida on Medium]]></title>
        <description><![CDATA[Stories by Chirag Mahida on Medium]]></description>
        <link>https://medium.com/@ChiragMahida026?source=rss-7ecf8ef5d9ff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LmP6HuOCMLfJs9sbG5KScg.jpeg</url>
            <title>Stories by Chirag Mahida on Medium</title>
            <link>https://medium.com/@ChiragMahida026?source=rss-7ecf8ef5d9ff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:26:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ChiragMahida026/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Securing Your Linux Server with Fail2Ban: A Practical DevOps Guide]]></title>
            <link>https://medium.com/@ChiragMahida026/securing-your-linux-server-with-fail2ban-a-practical-devops-guide-046ad2ec0b8f?source=rss-7ecf8ef5d9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/046ad2ec0b8f</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[server-security]]></category>
            <category><![CDATA[fail2ban]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Chirag Mahida]]></dc:creator>
            <pubDate>Wed, 22 Jul 2026 10:31:01 GMT</pubDate>
            <atom:updated>2026-07-22T10:31:01.571Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How to protect your servers from brute-force attacks — install, configure, whitelist, and verify, step by step.</em></p><p>If you run any server exposed to the internet — a web app, a mail server, a Docker host, or just an SSH box — you have already been attacked. Not “might be.” <strong>Already.</strong> Open your auth logs and you will see hundreds of failed login attempts from IPs all over the world, hammering your SSH port and login endpoints around the clock.</p><p>This is where <strong>Fail2Ban</strong> comes in. In this guide I’ll walk through what it is, why every server should run it, and exactly how to set it up, whitelist your own IPs, and verify it’s working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhziOfXw4dDaHdcxCfIJVQ.png" /><figcaption><em>[Figure 1: Screenshot of </em>`/var/log/auth.log`<em> showing repeated failed SSH login attempts — the problem we’re solving]</em></figcaption></figure><h3>What Is Fail2Ban?</h3><p>Fail2Ban is a lightweight intrusion-prevention tool that scans your log files (SSH, Nginx, Apache, mail, etc.) for suspicious activity — like repeated failed login attempts — and automatically <strong>bans the offending IP address</strong> by updating your firewall rules.</p><p>In simple terms:</p><blockquote><em>Fail2Ban watches your logs → detects attack patterns → blocks the attacker’s IP for a set period of time.</em></blockquote><p>It does this silently and automatically, 24/7, without you having to lift a finger.</p><h3>Why You Should Use It</h3><p>Here’s why Fail2Ban belongs on every server you manage:</p><ul><li><strong>Stops brute-force attacks.</strong> Attackers rely on trying thousands of password combinations. Fail2Ban bans them after just a few failed attempts, making brute-forcing impractical.</li><li><strong>Reduces server load.</strong> Constant malicious traffic wastes CPU, memory, and bandwidth. Banning bad actors frees up resources for real users.</li><li><strong>Cleaner logs.</strong> Less noise from attackers means it’s far easier to spot genuine issues.</li><li><strong>Protects more than SSH.</strong> It works with Nginx, Apache, Postfix, Dovecot, WordPress, and many other services through “jails.”</li><li><strong>Lightweight and free.</strong> Minimal resource footprint, open-source, and battle-tested in production.</li></ul><p>For a DevOps engineer, it’s one of the cheapest, highest-impact security wins you can deploy in under ten minutes.</p><h3>How Fail2Ban Works (Quick Concept)</h3><p>Before the commands, understand three terms:</p><ul><li><strong>Jail</strong> — a configuration unit that ties a service (e.g., SSH) to a filter and an action.</li><li><strong>Filter</strong> — a set of regex patterns that define what a “failure” looks like in the logs.</li><li><strong>Action</strong> — what to do when the limit is hit (usually: ban the IP via the firewall).</li></ul><p>The logic is: <em>If an IP triggers </em><em>maxretry failures within </em><em>findtime, ban it for </em><em>bantime.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fxd5cdx7AGFkIBRd8OcszQ.png" /><figcaption><em>[Figure 2: Simple flow diagram — Logs → Filter (regex match) → Counter → Ban action via firewall]</em></figcaption></figure><h3>Prerequisites</h3><ul><li>A Linux server (Ubuntu/Debian or CentOS/RHEL)</li><li>A user with sudo privileges</li><li>SSH access to the server</li></ul><h3>Step 1: Install Fail2Ban</h3><p><strong>On Ubuntu / Debian:</strong></p><pre>sudo apt update<br>sudo apt install fail2ban -y</pre><p><strong>On CentOS / RHEL / Rocky / Alma (requires EPEL):</strong></p><pre>sudo dnf install epel-release -y<br>sudo dnf install fail2ban -y</pre><p>Verify the installation:</p><pre>fail2ban-client --version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U6-I5WpGXc3kkr1R6vV9zg.png" /><figcaption><em>[Figure 3: Terminal output showing the installed Fail2Ban version]</em></figcaption></figure><h3>Step 2: Create Your Local Configuration</h3><p><strong>Important:</strong> Never edit /etc/fail2ban/jail.conf directly. It gets overwritten on updates. Instead, create a jail.local file — Fail2Ban reads it and it takes priority.</p><p>Copy the default config as a starting point:</p><pre>sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local</pre><p>Now open it for editing:</p><pre>sudo nano /etc/fail2ban/jail.local</pre><p>Under the [DEFAULT] section, set your global rules. Here&#39;s a solid baseline:</p><pre>[DEFAULT]<br># Time an IP is banned (in seconds). 1h = 3600<br>bantime  = 3600</pre><pre># Window in which failures are counted (10 minutes)<br>findtime = 600</pre><pre># Number of failures before a ban<br>maxretry = 5</pre><pre># Ban action using the system firewall<br>banaction = iptables-multiport</pre><blockquote><strong><em>Tip:</em></strong><em> Set </em><em>bantime = -1 to ban an IP permanently, or use something like </em><em>bantime = 1d for one day.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MSnUh75oUM3mZ_RsNTXzqA.png" /><figcaption><em>[Figure 4: Screenshot of the </em><em>[DEFAULT] section in jail.local with these values]</em></figcaption></figure><h3>Step 3: Enable the SSH Jail</h3><p>SSH is the most commonly attacked service, so let’s enable protection for it. Still inside jail.local, find the [sshd] section and configure it:</p><pre>[sshd]<br>enabled  = true<br>port     = ssh<br>filter   = sshd<br>logpath  = /var/log/auth.log<br>maxretry = 3</pre><blockquote><strong><em>Note:</em></strong><em> On CentOS/RHEL, the log path is usually </em><em>/var/log/secure instead of </em><em>/var/log/auth.log.</em></blockquote><p>Save and exit the file (Ctrl + O, Enter, then Ctrl + X in nano).</p><h3>Step 4: Whitelist Your Own IP Addresses (Very Important!)</h3><p>This is a step people forget — and then lock <strong>themselves</strong> out. You must whitelist your own IP so Fail2Ban never bans you, even if you fumble a password.</p><p>Open jail.local again and find the ignoreip line in the [DEFAULT] section (add it if it isn&#39;t there):</p><pre>[DEFAULT]<br># Whitelist localhost, your office IP, and any trusted ranges<br>ignoreip = 127.0.0.1/8 ::1 203.0.113.25 192.168.1.0/24</pre><p>Breaking that down:</p><ul><li>127.0.0.1/8 and ::1 — localhost (always keep these)</li><li>203.0.113.25 — a single trusted public IP (e.g., your office or home)</li><li>192.168.1.0/24 — a whole trusted subnet (e.g., your internal network)</li></ul><p>You can add multiple IPs and CIDR ranges separated by spaces.</p><blockquote><strong><em>Best practice:</em></strong><em> Always add your current public IP before enabling Fail2Ban. Find it quickly with:</em></blockquote><pre>curl ifconfig.me</pre><p>After any config change, restart Fail2Ban to apply it (covered in the next step).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGC5Uxa9vQ6DMShaDCk1LQ.png" /><figcaption><em>[Figure 5: Screenshot of the </em><em>ignoreip line with whitelisted IPs]</em></figcaption></figure><h3>Step 5: Enable and Start the Service</h3><p>Enable Fail2Ban to start on boot, and start it now:</p><pre>sudo systemctl enable fail2ban<br>sudo systemctl start fail2ban</pre><p>If you changed the config after it was already running, restart instead:</p><pre>sudo systemctl restart fail2ban</pre><p>Check that the service is active:</p><pre>sudo systemctl status fail2ban</pre><p>You should see active (running) in green.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XXMWm1e5VuI_Jrv_Fp0gXQ.png" /><figcaption><em>[Figure 6: Terminal output of </em><em>systemctl status fail2ban showing the active/running state]</em></figcaption></figure><h3>Step 6: Verify Everything Is Working</h3><p>Now let’s confirm Fail2Ban is actually protecting your server.</p><p><strong>Check the overall status and list of active jails:</strong></p><pre>sudo fail2ban-client status</pre><p><strong>Check the status of a specific jail (e.g., SSH):</strong></p><pre>sudo fail2ban-client status sshd</pre><p>This shows you the currently banned IPs, total failures, and total bans — for example:</p><pre>Status for the jail: sshd<br>|- Filter<br>|  |- Currently failed: 2<br>|  |- Total failed:     148<br>|  `- File list:        /var/log/auth.log<br>`- Actions<br>   |- Currently banned: 3<br>   |- Total banned:     27<br>   `- Banned IP list:   45.148.10.12 61.177.173.9 194.169.175.36</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCimkmbRFijFC-12n2_fBw.png" /><figcaption><em>[Figure 7: Terminal output of </em><em>fail2ban-client status sshd showing banned IPs]</em></figcaption></figure><h3>Managing Bans (Ban &amp; Unban Manually)</h3><p>Sometimes you need to unban a legitimate user who got caught, or manually ban a known bad IP.</p><p><strong>Unban an IP:</strong></p><pre>sudo fail2ban-client set sshd unbanip 203.0.113.99</pre><p><strong>Manually ban an IP:</strong></p><pre>sudo fail2ban-client set sshd banip 45.148.10.12</pre><p><strong>Whitelist an IP on the fly (without editing config):</strong></p><pre>sudo fail2ban-client set sshd addignoreip 203.0.113.25</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qDT_IpX81WEY1zK9mtX3wQ.png" /><figcaption><em>[Figure 8: Example of unbanning an IP from the command line]</em></figcaption></figure><h3>Bonus: Protecting Nginx</h3><p>Fail2Ban isn’t just for SSH. If you run Nginx, add this jail to jail.local to block clients that repeatedly hit bad auth or flood your server:</p><pre>[nginx-http-auth]<br>enabled  = true<br>filter   = nginx-http-auth<br>port     = http,https<br>logpath  = /var/log/nginx/error.log<br>maxretry = 5</pre><p>Restart Fail2Ban and it will now guard your web server too. The same pattern applies to Apache, Postfix, Dovecot, and more — one jail per service.</p><h3>Best Practices for Production</h3><ul><li><strong>Always whitelist your own IP</strong> before enabling — this is the #1 lockout cause.</li><li><strong>Start with a moderate </strong><strong>bantime</strong> (like 1 hour) and increase for repeat offenders.</li><li><strong>Enable </strong><strong>bantime.increment</strong> so repeat attackers get progressively longer bans:</li></ul><pre>[DEFAULT]<br>bantime.increment = true<br>bantime.factor    = 2</pre><ul><li><strong>Monitor the logs</strong> at /var/log/fail2ban.log to understand attack patterns.</li><li><strong>Combine with other hardening</strong> — key-based SSH auth, disabling root login, and a proper firewall. Fail2Ban is a layer, not the whole wall.</li></ul><h3>Conclusion</h3><p>Fail2Ban is one of those tools that takes ten minutes to set up and pays off every single day. It quietly shuts down brute-force attacks, keeps your logs clean, and frees up server resources — all with a tiny footprint.</p><p>If you manage servers and haven’t deployed it yet, do it today. Just remember: <strong>whitelist your own IP first.</strong></p><p><em>If this guide helped you secure your servers, give it a clap 👏 and follow for more practical DevOps content. Got questions? Drop them in the comments.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=046ad2ec0b8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Static Web Apps: A Practical Guide to Deployment and Domain Configuration]]></title>
            <link>https://medium.com/@ChiragMahida026/azure-static-web-apps-a-practical-guide-to-deployment-and-domain-configuration-9949df2f32bd?source=rss-7ecf8ef5d9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/9949df2f32bd</guid>
            <dc:creator><![CDATA[Chirag Mahida]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 17:22:16 GMT</pubDate>
            <atom:updated>2023-11-12T17:23:33.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*GPEhA5XIS3iQ3ESt_tcXsQ.jpeg" /></figure><h3>Azure Static Web Apps: A Practical Guide to Deployment and Custom Domain Configuration</h3><blockquote><strong>Introduction</strong></blockquote><p>In this guide, we’ll explore the seamless deployment of web applications using Azure Static Web Apps. Azure Static Web Apps simplify the deployment process, enabling you to host static content effortlessly. We’ll walk you through creating Azure resources, configuring GitHub Actions for continuous integration and deployment (CI/CD), and adding a custom domain for a polished online presence. This practical guide will provide step-by-step instructions using the Azure portal, making the process easy to understand and implement. Let’s embark on a journey to efficiently deploy and configure your web apps with Azure Static Web Apps.</p><blockquote><strong>Step 1: Create Azure Static Web App</strong></blockquote><ul><li>In the Azure portal, click “Create a resource” .</li><li>Search for “Static Web App” and select “Static Web App” from the results.</li><li>Click “Create.”</li></ul><figure><img alt="Search about the static web application in azure portal" src="https://cdn-images-1.medium.com/max/636/1*t2FxIMnab6-1kgLSzz1Qbw.png" /><figcaption>Fig 1. Search about the static web application in azure portal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WkvJXSBa-6agOTppx4FRA.png" /><figcaption>Fig 2. Make a resource name of the “ChiragMahida”</figcaption></figure><ol><li>Fill in the required information:<br> — <strong>Subscription</strong>: Choose your subscription.<br> — <strong>Resource group: </strong>Select the resource group created in Step 1.<br> — <strong>Name:</strong> Enter a unique name for your Static Web App.<br> — <strong>Region:</strong> Choose a region.<br> — <strong>SKU:</strong> Select the appropriate SKU based on your needs.<br> — <strong>Repository:</strong> Connect your GitHub repository.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSm9HKxArZLZq8WhCy8AeQ.png" /><figcaption>Fig 3.Create static web app with the required information</figcaption></figure><ol><li>Click “Next” to configure the build details:<br> — <strong>Build Presets: </strong>Choose the appropriate preset based on your project.<br> — <strong>App Location: </strong>Set the path to your web app files.<br> — <strong>API Location:</strong> Set the path to your API files.<br> — <strong>Output Location:</strong> Set the build output location.</li><li>Click “Review + create” and then “Create” to deploy the Static Web App.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CrT5xbcyF100Sr_0JAuXrw.png" /><figcaption>Fig 4.Add build details with the proper configuration</figcaption></figure><p>— Code of the Azure Static Web Apps CI/CD</p><pre>name: Azure Static Web Apps CI/CD<br><br>on:<br>  push:<br>    branches:<br>      - Azure-webapp<br>  pull_request:<br>    types: [opened, synchronize, reopened, closed]<br>    branches:<br>      - Azure-webapp<br><br>jobs:<br>  build_and_deploy_job:<br>    if: github.event_name == &#39;push&#39; || (github.event_name == &#39;pull_request&#39; &amp;&amp; github.event.action != &#39;closed&#39;)<br>    runs-on: ubuntu-latest<br>    name: Build and Deploy Job<br>    steps:<br>      - uses: actions/checkout@v3<br>        with:<br>          submodules: true<br>          lfs: false<br>      - name: Build And Deploy<br>        id: builddeploy<br>        uses: Azure/static-web-apps-deploy@v1<br>        with:<br>          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_YELLOW_BEACH_0BCF82A10 }}<br>          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)<br>          action: &quot;upload&quot;<br>          ###### Repository/Build Configurations - These values can be configured to match your app requirements. ######<br>          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig<br>          app_location: &quot;/&quot; # App source code path<br>          api_location: &quot;&quot; # Api source code path - optional<br>          output_location: &quot;/&quot; # Built app content directory - optional<br>          ###### End of Repository/Build Configurations ######<br><br>  close_pull_request_job:<br>    if: github.event_name == &#39;pull_request&#39; &amp;&amp; github.event.action == &#39;closed&#39;<br>    runs-on: ubuntu-latest<br>    name: Close Pull Request Job<br>    steps:<br>      - name: Close Pull Request<br>        id: closepullrequest<br>        uses: Azure/static-web-apps-deploy@v1<br>        with:<br>          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_YELLOW_BEACH_0BCF82A10 }}<br>          action: &quot;close&quot;</pre><blockquote><strong>Step 2: Configure GitHub Action CI/CD Logs</strong></blockquote><ul><li>Open your GitHub repository.</li><li>Navigate to the “Actions” tab.</li><li>You should see a workflow named “Build and deploy”. Click on it to view the logs for CI/CD.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6sF2t0w_1ooRoZ7XDCgrg.png" /><figcaption>Fig 5.Show the log of the azure CI/CD pipeline deployment</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQRzVtQZYLcwb9urtDTXdQ.png" /><figcaption>Fig 6.Dashboard of the ChiragMahida Resource and static web application</figcaption></figure><blockquote><strong>Step 4: Add Custom Domain in Azure Static Web App</strong></blockquote><ul><li>In the Azure portal, go to your Static Web App.</li><li>Under “Settings,” click on “Custom domains.”</li><li>Click “Add custom domain.”</li><li>Enter your custom domain and follow the steps to verify ownership.</li></ul><blockquote><strong>Step 5: Add Custom Domain in DNS Provider</strong></blockquote><ul><li>Go to your DNS provider’s website.</li><li>Add a new CNAME record pointing to your Azure Static Web App’s default domain.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*iJwpxygIFNoAIV7RZQ195Q.png" /><figcaption>Fig 7.Add Custom domain on azure static web app</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*IsHb7dHJuIC2wrNW4yb8oQ.png" /><figcaption>Fig 8.Add Domain name with the custom domain on other DNS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*XdlPgEO2YbQLKhnzZr2MtA.png" /><figcaption>Fig 9.Add Validate domain ownership with record type</figcaption></figure><blockquote><strong>Conclusion</strong></blockquote><p>In conclusion, this guide has provided a straightforward walk through for deploying a web app using Azure Static Web Apps, emphasizing key steps like resource group creation, GitHub Actions integration, and custom domain configuration. By following these steps through the Azure portal, users can efficiently manage and enhance their web application deployment process. Empowered with this knowledge, you can confidently deploy your projects, ensuring a seamless experience for both developers and end-users on the Azure Static Web Apps platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9949df2f32bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ansible Automation for Bash Script and Crontab Backup: A Guide with Ansible-Vault]]></title>
            <link>https://medium.com/@ChiragMahida026/ansible-automation-for-bash-script-and-crontab-backup-a-guide-with-ansible-vault-d9e1d3fd6b80?source=rss-7ecf8ef5d9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9e1d3fd6b80</guid>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[ansible-playbook]]></category>
            <category><![CDATA[cloud-backup-server]]></category>
            <category><![CDATA[ansible-vault]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Chirag Mahida]]></dc:creator>
            <pubDate>Sun, 02 Jul 2023 11:47:00 GMT</pubDate>
            <atom:updated>2023-07-02T11:47:59.892Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*PNvyf5kQKniBn8sqSJkeCg.png" /></figure><blockquote><strong>What is Ansible ?</strong></blockquote><p>Ansible is an open-source automation tool that enables you to automate various IT tasks such as configuration management, application deployment, and infrastructure provisioning. It provides a simple, declarative language to describe the desired state of your systems, and it can manage and orchestrate multiple machines simultaneously.</p><p>With Ansible, you can automate tasks across different operating systems and cloud environments, making it a versatile tool for managing diverse infrastructure. Ansible uses SSH (Secure Shell) to establish connections with remote machines and executes tasks on them using modules.</p><blockquote><strong>Introduction:</strong></blockquote><p>In today’s fast-paced world of IT operations, automation plays a crucial role in streamlining tasks and increasing productivity. Ansible, an open-source automation tool, is widely used for managing and orchestrating infrastructure, applications, and configurations. In this article, we will explore how Ansible can be leveraged to automate the backup of Bash scripts and crontab entries. Additionally, we will learn how to enhance the security of our automation workflow using Ansible-Vault.</p><blockquote><strong>Understanding Ansible:</strong></blockquote><p>Ansible is a powerful automation tool that follows a declarative approach, allowing users to define the desired state of systems or configurations. It operates by connecting to remote nodes over SSH and executing tasks using SSH connections and Python. With its agentless architecture, Ansible simplifies the process of managing and automating a wide range of tasks across multiple servers.</p><blockquote><strong>Automating Bash Script and Crontab Backup:</strong></blockquote><p>To automate the backup of Bash scripts and crontab entries, we can create an Ansible playbook that performs the following steps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*7DiR8RURWVKNHHy1f02wAQ.png" /><figcaption>Apply the changes in ansible.cfg File</figcaption></figure><ol><li><strong><em>Inventory Configuration:</em></strong> Create an inventory file that lists the target servers where the backups need to be performed. This file should contain the IP addresses or hostnames of the servers.</li></ol><pre>inventory.ini<br><br>[web_servers]<br>server1 ansible_host=192.168.1.101 ansible_become_pass={{ server1_password }}<br>server2 ansible_host=192.168.1.102 ansible_become_pass={{ server2_password }}<br>server3 ansible_host=192.168.1.103 ansible_become_pass={{ server3_password }}</pre><p>2. <strong><em>Ansible Vault Configuration:</em></strong> Ansible-Vault provides a secure way to encrypt sensitive information such as passwords, API keys, or in our case, any authentication details required for the backup process. Create an Ansible-Vault encrypted file to store the necessary credentials securely.</p><p>i) Create a vault file that will store the encrypted passwords. Run the following command:</p><p>→<em> set the vault password.</em></p><pre>ansible-vault create vault.yml</pre><p>This will open an editor where you can enter the password for each server. The file will be encrypted and saved when you exit the editor.</p><p>ii) Add the server-specific variables and their values (passwords) in the vault file.</p><pre>server1_password: &quot;password1&quot;<br>server2_password: &quot;password2&quot;<br>server3_password: &quot;password3&quot;</pre><p>Save and exit the vault file.</p><p>iii) In playbook(<em>runtestplaybook.yml</em>) to use the vault password.</p><pre>---<br>- name: Accessing Vaults in playbooks<br>  hosts: localhost<br>  vars_files: vault.yml<br>  tasks:<br>   - name: show server1_password value<br>     debug:<br>       msg: &quot;{{ server1_password }}&quot; </pre><p>iv) Run the test File to check your configuration right For that use this command :</p><pre>//Attach the inventory file to the command <br>ansible-playbook -i inventory.ini runtestplaybook.yml --ask-vault-pass<br><br>//run the file without attching inventory file <br>ansible-playbook runtestplaybook.yml --ask-vault-pass</pre><p><strong><em>3. Playbook Creation:</em></strong> Develop an Ansible playbook that defines the tasks required for backing up the Bash scripts and crontab entries. The playbook should include the following steps:</p><ul><li><strong><em>a. Gather Facts:</em></strong><em> </em>Use the Ansible “setup” module to gather system information about the target servers. This step ensures that the playbook has access to the necessary details about the server’s configuration.</li><li><strong>b. Backup Bash Scripts:</strong> Utilize the Ansible “fetch” module to copy the Bash scripts from the target servers to the local machine or a designated backup location.</li><li><strong><em>c. Backup Crontab Entries:</em></strong> Employ the Ansible “cronvar” module to fetch the crontab entries from the target servers and store them securely in the backup location.</li></ul><blockquote><strong><em>Ansible Playbook Code</em></strong></blockquote><pre>---<br>- name: Take backup of all web servers<br>  vars_files: server-secrets.yml<br>  hosts: web_servers<br>  gather_facts: yes<br>  become: true<br>  # become_user: root<br><br>  vars:<br>    backup_dir: &quot;/home/backup/{{ ansible_date_time.date }}&quot;<br>    crontab_file: &quot;crontab.txt&quot;<br><br>  # Backup the nginx file from every server<br>  tasks:<br>    - name: create backup directory if it doesn&#39;t exist<br>      file:<br>        path: &quot;{{ backup_dir }}&quot;<br>        state: directory<br>      delegate_to: &quot;{{ inventory_hostname }}&quot;<br><br>    - name: Take a backup of nginx conf file<br>      synchronize:<br>        src: &quot;/etc/nginx/site-enabled/&quot;<br>        dest: &quot;{{ backup_dir }}/nginx_conf_backup/&quot;<br>      delegate_to: &quot;{{ inventory_hostname }}&quot;<br><br>    # Backup the sh script file in every server<br>    - name: check if demo.sh file exists<br>      stat:<br>        path: &quot;/home/scripts/demo.sh&quot;<br>      register: script_file<br>      ignore_errors: yes<br><br>    - name: Take backup of demo.sh script<br>      synchronize:<br>        src: &quot;/home/scripts/demo.sh&quot;<br>        dest: &quot;{{ backup_dir }}/demo_script_backup/&quot;<br>      delegate_to: &quot;{{ inventory_hostname }}&quot;<br>      when: script_file.stat.exists == true<br><br>    # Backup the crontab in every server<br>    - name: Backup crontab<br>      become: true<br>      become_user: chirag<br>      shell: &quot;crontab -l &gt; {{ crontab_file }}&quot;<br>      register: crontab_output<br>      changed_when: false<br>      delegate_to: &quot;{{ inventory_hostname }}&quot;<br>      when: inventory_hostname in groups[&#39;web_servers&#39;]<br><br>    - name: Copy crontab backup file to backup directory<br>      become: true<br>      synchronize:<br>        src: &quot;{{ crontab_file }}&quot;<br>        dest: &quot;{{ backup_dir }}/crontab.txt.{{ inventory_hostname }}&quot;<br>      when: crontab_output.stdout != &quot;&quot; and inventory_hostname in groups[&#39;web_servers&#39;]<br><br>    - name: Remove crontab backup file from tmp directory<br>      become: true<br>      file:<br>        path: &quot;{{ crontab_file }}&quot;<br>        state: absent<br>      when: crontab_output.stdout != &quot;&quot; and inventory_hostname in groups[&#39;web_servers&#39;]<br><br>    - name: Move file to backup directory<br>      command: mv &quot;/home/{{ crontab_file }}&quot; &quot;{{ backup_dir }}/&quot;<br><br>    # Create a tar file of the backup directory<br>    - name: create tar file of backup directory<br>      achive:<br>        path: &quot;{{ backup_dir }}&quot;<br>        dest: &quot;/home/backup/{{ inventory_hostname }}.tar.gz&quot;<br>        format: gz<br>        delegate_to: &quot;{{ inventory_hostname }}&quot;<br><br>    # Transfer tar file to server1<br>    - name: get tar file from multiple servers and store in server1<br>      fetch:<br>        src: &quot;/home/backup/{{ inventory_hostname }}.tar.gz&quot;<br>        dest: &quot;/home/ALL_Backup/&quot;<br>        flat: yes<br>        remote_src: yes<br>        ignore_errors: true<br><br>    - name: Transfer tar file to server1<br>      copy:<br>        src: &quot;/home/backup/{{ inventory_hostname }}.tar.gz&quot;<br>        dest: &quot;/home/ALL_Backup/&quot;<br>        remote_src: yes<br><br>    - name: Set tar file permissions<br>      file:<br>        path: &quot;/home/ALL_Backup/{{ inventory_hostname }}.tar.gz&quot;<br>        mode: &quot;0644&quot;<br>      when: tarfile.stat.exists<br><br>    # Print completion messages<br>    - name: Print completion<br>      debug:<br>        msg: &quot;ok its done&quot;<br><br>    - name: Print the completion message on a particular server<br>      debug:<br>        msg: &quot;ok its done in server2&quot;<br>      delegate_to: &quot;{{ inventory_hostname }}&quot;<br>      when:<br>        - script_file.stat.exists == true<br>        - inventory_hostname == &#39;server2&#39;</pre><p><strong><em>4. Encrypting Sensitive Data with Ansible-Vault:</em></strong> To safeguard any sensitive data used in the playbook, we can leverage Ansible-Vault. By encrypting the playbook variables or entire files, we ensure that the credentials and other confidential information are protected from unauthorized access.</p><blockquote><strong>Conclusion</strong></blockquote><p>Ansible provides a flexible and efficient approach to automate various IT operations. In this article, we explored how to automate the backup of Bash scripts and crontab entries using Ansible. We learned about Ansible’s declarative nature and its ability to securely manage inventory and execute tasks on remote servers. By incorporating Ansible-Vault into our workflow, we enhanced the security of our automation process. With the power of Ansible, we can streamline routine tasks and focus on more critical aspects of our IT infrastructure management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9e1d3fd6b80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up Automated CI/CD for an Electron Project using GitLab]]></title>
            <link>https://medium.com/@ChiragMahida026/set-up-automated-ci-cd-for-an-electron-project-using-gitlab-cdcf00b8893b?source=rss-7ecf8ef5d9ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdcf00b8893b</guid>
            <category><![CDATA[gitlab-runner]]></category>
            <category><![CDATA[gitlab-cicd]]></category>
            <category><![CDATA[auto-update]]></category>
            <category><![CDATA[features]]></category>
            <category><![CDATA[electronjs]]></category>
            <dc:creator><![CDATA[Chirag Mahida]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 17:09:58 GMT</pubDate>
            <atom:updated>2023-07-02T11:54:09.042Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*QocBzXPZESRRK2ZtVYk0CQ.png" /></figure><p>In today’s software development landscape, continuous integration and continuous deployment (CI/CD) have become essential practices. They enable teams to automate build, test, and deployment processes, resulting in faster and more reliable software delivery. In this blog post, we will walk through the process of setting up automated CI/CD for an Electron project using GitLab.</p><p><strong>Step 1: </strong>Create a New GitLab Repository The first step is to create a new GitLab repository for your Electron project. Log in to GitLab and follow the steps to create a new repository. Once created, clone the repository to your local machine using Git.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*6WN9d4CCqrjdm9Ubp9bhRQ.png" /><figcaption>Figure 1:Create Gitlab Token</figcaption></figure><p><strong>Step 2: </strong>Install GitLab Runner To execute the CI/CD pipeline, you need to install GitLab Runner on your machine or server. GitLab Runner is responsible for running the pipeline jobs. Refer to the GitLab Runner documentation for detailed installation instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*H4YrOs6ROrlJlj1D2tY6WA.png" /></figure><p><strong>Step 3: </strong>Configure the CI/CD Pipeline In the root directory of your Electron project, create a .gitlab-ci.yml file. This file defines the stages and jobs of your CI/CD pipeline. You can customize the pipeline stages to fit your specific needs. Here&#39;s an example configuration for an Electron project:</p><pre>stages:<br>  - Build<br>  - Upload<br>  - Release<br><br>build:<br>  stage: Build<br>  image: electronuserland/builder:wine<br>  before_script:<br>    - npm install<br>  script:<br>    - export VERSION=$(node -e &quot;console.log(require(&#39;./package.json&#39;).version)&quot;)<br>    - echo &quot;VERSION=$VERSION&quot; &gt;&gt; variables.env<br>    - export APPNAME=$(node -e &quot;console.log(require(&#39;./package.json&#39;).productName)&quot;)<br>    - echo &quot;APPNAME=$APPNAME&quot; &gt;&gt; variables.env<br>    - npm run build<br>  artifacts:<br>    reports:<br>      dotenv: variables.env<br>    name: $CI_COMMIT_REF_SLUG<br>    paths:<br>      - $CI_PROJECT_DIR/dist/*.*<br>    when: on_success<br>  only:<br>    - main //specific branch build change branch according your repo<br><br>variables:<br>  WIN_BINARY: &#39;${APPNAME}-${VERSION}.exe&#39;<br>  PACKAGE_REGISTRY_URL: &#39;${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${APPNAME}/${VERSION}&#39;<br>  PACKAGE_REGISTRY_URL_YML: &#39;${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${APPNAME}&#39;<br><br>upload:<br>  stage: Upload<br>  needs:<br>    - job: build<br>      artifacts: true<br>  rules:<br>    - if: $CI_COMMIT_TAG<br>      when: never # Do not run this job when a tag is created manually<br>    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when when commits are pushed to the default branch<br>  script:<br>    - &#39;curl --header &quot;JOB-TOKEN: $CI_JOB_TOKEN&quot; --upload-file &quot;./dist/${WIN_BINARY}&quot; &quot;${PACKAGE_REGISTRY_URL}/${WIN_BINARY}&quot;&#39;<br>    - &#39;curl --header &quot;JOB-TOKEN: $CI_JOB_TOKEN&quot; --upload-file &quot;./dist/latest.yml&quot; &quot;${PACKAGE_REGISTRY_URL_YML}/latest.yml&quot;&#39;<br>    - echo &quot;${PACKAGE_REGISTRY_URL_YML}/latest.yml&quot;<br><br>auto-release-main:<br>  image: registry.gitlab.com/gitlab-org/release-cli<br>  needs:<br>    - job: build<br>      artifacts: true<br>    - job: upload<br>      artifacts: true<br>  stage: Release<br>  rules:<br>    - if: $CI_COMMIT_TAG<br>      when: never # Do not run this job when a tag is created manually<br>    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when when commits are pushed to the default branch<br>  script:<br>    - echo &quot;Release $VERSION&quot;<br>    - |<br>      release-cli create --name &quot;Release $VERSION&quot; --tag-name v$VERSION \<br>      --description &#39;Created using the release-cli. $CI_COMMIT_TITLE&#39; --ref $CI_COMMIT_SHA \<br>      --assets-link &quot;{\&quot;name\&quot;:\&quot;${APPNAME}\&quot;,\&quot;url\&quot;:\&quot;${PACKAGE_REGISTRY_URL}/${WIN_BINARY}\&quot;}&quot; \<br>      --assets-link &quot;{\&quot;name\&quot;:\&quot;${APPNAME} Latest\&quot;,\&quot;url\&quot;:\&quot;${PACKAGE_REGISTRY_URL_YML}/latest.yml\&quot;}&quot;</pre><p><strong>Step 4:</strong> Define Pipeline Stages and Jobs Within the .gitlab-ci.yml file, define the stages and jobs for your CI/CD pipeline. Typical stages for an Electron project include build, test, package, and deploy. Each stage consists of one or more jobs that perform specific tasks. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*8x0VPVpInf2HgVVnhvdOnA.png" /></figure><p>5. Add Electron Js code in Main.js File</p><pre>// Inital app<br>const electron = require(&quot;electron&quot;);<br>const { autoUpdater } = require(&quot;electron-updater&quot;);<br>const { app, BrowserWindow, ipcMain, Menu, dialog } = require(&quot;electron&quot;);<br>const log = require(&quot;electron-log&quot;);<br><br>log.info(&quot;Hello, log&quot;);<br><br>let mainWindow;<br>// mainWindow.webContents.openDevTools();<br><br><br>function createWindow() {<br>  mainWindow = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      nodeIntegration: true,<br>    },<br>  });<br>  mainWindow.loadFile(&quot;index.html&quot;);<br>  mainWindow.on(&quot;closed&quot;, function () {<br>    mainWindow = null;<br>  });<br><br>  // Create the menu template<br>  // const template = [<br>  //   {<br>  //     label: &quot;Update Custom Menu&quot;,<br>  //     click() {<br>  //       sendStatusToWindow(&quot;Checking for updates...&quot;);<br>  //       autoUpdater.checkForUpdatesAndNotify();<br>  //     },<br>  //   },<br>  // ];<br><br>  // // Add the menu to the main application menu<br>  // const menu = Menu.buildFromTemplate(template);<br>  // Menu.setApplicationMenu(menu);<br>}<br><br>app.on(&quot;ready&quot;, () =&gt; {<br>  createWindow();<br>});<br><br>app.on(&quot;window-all-closed&quot;, function () {<br>  if (process.platform !== &quot;darwin&quot;) {<br>    app.quit();<br>  }<br>});<br><br>app.on(&quot;activate&quot;, function () {<br>  if (mainWindow === null) {<br>    createWindow();<br>  }<br>});<br><br>ipcMain.on(&quot;app_version&quot;, (event) =&gt; {<br>  sendStatusToWindow(&quot;Getting App Version....&quot;);<br>  event.sender.send(&quot;app_version&quot;, { version: app.getVersion() });<br>});<br><br>///////////////////<br>// Auto upadater //<br>///////////////////<br>autoUpdater.requestHeaders = { &quot;PRIVATE-TOKEN&quot;: &quot;&lt;GITLAB-TOKEN&gt;&quot; };<br>autoUpdater.autoDownload = true;<br><br>console.log(autoUpdater.requestHeaders);<br><br><br>autoUpdater.setFeedURL(<br>  &quot;https://gitlab.com/api/v4/projects/&lt;PROJECT-ID&gt;/jobs/artifacts/&lt;BRANCH-NAME&gt;/raw/dist?job=build&quot;<br>);<br><br>autoUpdater.on(&quot;checking-for-update&quot;, function () {<br>  sendStatusToWindow(&quot;Checking for update...&quot;);<br>});<br><br>autoUpdater.on(&quot;update-available&quot;, function (info) {<br>  sendStatusToWindow(&quot;Update available.&quot;);<br>  dialog.showMessageBox(mainWindow, {<br>    type: &quot;info&quot;,<br>    buttons: [&quot;OK&quot;],<br>    message: &quot;An update is available. It will be downloaded in the background.&quot;<br>  });<br>});<br><br><br>autoUpdater.on(&quot;update-not-available&quot;, function (info) {<br>  sendStatusToWindow(&quot;Update not available.&quot;);<br>  dialog.showMessageBox(mainWindow, {<br>    type: &quot;info&quot;,<br>    buttons: [&quot;OK&quot;],<br>    message: &quot;No updates are currently available.&quot;<br>  });<br>});<br><br><br>autoUpdater.on(&quot;error&quot;, function (err) {<br>  sendStatusToWindow(&quot;Error in auto-updater.&quot;);<br>});<br><br>autoUpdater.on(&quot;download-progress&quot;, function (progressObj) {<br>  let log_message = &quot;Download speed: &quot; + progressObj.bytesPerSecond;<br>  log_message =<br>    log_message + &quot; - Downloaded &quot; + parseInt(progressObj.percent) + &quot;%&quot;;<br>  log_message =<br>    log_message +<br>    &quot; (&quot; +<br>    progressObj.transferred +<br>    &quot;/&quot; +<br>    progressObj.total +<br>    &quot;)&quot;;<br>  sendStatusToWindow(log_message);<br>});<br><br>autoUpdater.on(&quot;update-downloaded&quot;, function (info) {<br>  dialog<br>    .showMessageBox(mainWindow, {<br>      type: &quot;question&quot;,<br>      buttons: [&quot;Install&quot;, &quot;Later&quot;],<br>      defaultId: 0,<br>      message: &quot;A new version of the app has been downloaded. Install now?&quot;,<br>    })<br>    .then((result) =&gt; {<br>      if (result.response === 0) {<br>        sendStatusToWindow(&quot;Installing update...&quot;);<br>        autoUpdater.quitAndInstall();<br>      } else {<br>        sendStatusToWindow(&quot;Update postponed.&quot;);<br>      }<br>    })<br>    .catch((err) =&gt; {<br>      sendStatusToWindow(&quot;Update error: &quot; + err.message);<br>    });<br>});<br><br>autoUpdater.checkForUpdates();<br><br>function sendStatusToWindow(message) {<br>  console.log(message);<br>}</pre><p>6. Set up the pipeline to automatically build and test the project whenever changes are pushed to the repository.</p><p>7. Configure the pipeline to deploy the project to the appropriate environment based on the branch or tag being pushed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*-Cv7HnkA_nx746gc9JP6fA.png" /></figure><blockquote><strong>Conclusion:</strong></blockquote><p>Automating the CI/CD process for your Electron project using GitLab can greatly improve your development workflow. By following the steps outlined in this blog post, you can set up a robust and efficient CI/CD pipeline that builds, tests, packages, and deploys your Electron application automatically. If you have any questions or need further assistance, please don’t hesitate to contact me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdcf00b8893b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>