<?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 ANTONY A N on Medium]]></title>
        <description><![CDATA[Stories by ANTONY A N on Medium]]></description>
        <link>https://medium.com/@antonyan009?source=rss-73c89003020------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FzbsSb40mOIbHvtzbvIEDQ.jpeg</url>
            <title>Stories by ANTONY A N on Medium</title>
            <link>https://medium.com/@antonyan009?source=rss-73c89003020------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:01:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@antonyan009/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[Secure Multi StageAmazon EKS Deployments Using GitLab CI/CD, Terragrunt, and OIDC (No AWS Access…]]></title>
            <link>https://medium.com/@antonyan009/secure-multi-stageamazon-eks-deployments-using-gitlab-ci-cd-terragrunt-and-oidc-no-aws-access-706d5971fe03?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/706d5971fe03</guid>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[aws-eks]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 18:27:30 GMT</pubDate>
            <atom:updated>2026-02-08T19:07:02.231Z</atom:updated>
            <content:encoded><![CDATA[<h3>Secure Multi StageAmazon EKS Deployments Using GitLab CI/CD, Terragrunt, and OIDC (No AWS Access Keys)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aF3g1D6fG7HjgKFHJq_qGA.png" /></figure><p>Managing Amazon EKS infrastructure securely in CI/CD pipelines is a common challenge. Many teams still rely on long-lived AWS access keys, which increases security risk and operational overhead.</p><p>In this article, we’ll build a <strong>secure, production-ready GitLab CI/CD pipeline</strong> that deploys Amazon EKS infrastructure using <strong>Terragrunt</strong>, authenticated via <strong>GitLab OpenID Connect (OIDC)</strong> — with <strong>no static AWS credentials</strong>.</p><p>How to access,</p><p>Clone the repo,</p><pre>git clonehttps://gitlab.com/antonyan_009/eks/terragrunt.git</pre><p>You can find the <a href="https://gitlab.com/antonyan_009/eks/terragrunt/-/blob/main/.gitlab-ci.yml?ref_type=heads">.gitlab-ci.yml</a> there.</p><p>This pipeline supports:</p><ul><li>Multiple AWS regions</li><li>Multiple environments (dev &amp; staging)</li><li>Manual approval gates</li><li>Secure AWS authentication via OIDC</li></ul><p><strong>Why Use GitLab OIDC for AWS?</strong></p><p>Using <strong>OIDC with GitLab CI</strong> eliminates the need for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.</p><p>Instead:</p><ul><li>GitLab issues a short-lived OIDC token</li><li>AWS validates the token</li><li>The pipeline assumes an IAM role dynamically</li><li>Credentials expire automatically</li></ul><p>This approach is:</p><ul><li>More secure</li><li>Easier to audit</li><li>Fully cloud-native</li></ul><p><strong>How can I set this? Don’t worry, I have already documented this for you, buddy :)</strong></p><blockquote><a href="https://medium.com/@antonyan009/set-up-an-oidc-provider-for-aws-gitlab-integration-using-terraform-d9f64d7dc684">https://medium.com/@antonyan009/set-up-an-oidc-provider-for-aws-gitlab-integration-using-terraform-d9f64d7dc684</a></blockquote><p><strong>Architecture Overview</strong></p><p>At a high level, the pipeline works as follows:</p><ol><li>GitLab generates an OIDC token</li><li>AWS STS exchanges the token for temporary credentials</li><li>The pipeline authenticates to EKS using IAM</li><li>Terragrunt plans and applies infrastructure changes</li><li>Applies require manual approval</li></ol><p><strong>Prerequisites</strong></p><p>Before using this pipeline, the following <strong>must already exist</strong>:</p><h4>1. Two EKS Clusters (Pre-Provisioned)</h4><p>This CI/CD pipeline <strong>does not create the EKS clusters themselves</strong>.<br> It assumes the following clusters already exist:</p><p>Don’t worry about the region and clusters name, they can be set via variables.</p><ul><li><strong>Dev cluster</strong></li><li>Region: us-west-2</li><li>Name: eks-terraform-dev</li><li><strong>Staging cluster</strong></li><li>Region: us-east-2</li><li>Name: eks-terraform-stage</li></ul><p>These clusters are used by Terragrunt to manage workloads or cluster-level resources.</p><p><strong>Do you need any help? Here you go</strong></p><blockquote><a href="https://medium.com/@antonyan009/how-to-deploy-an-amazon-eks-cluster-using-terragrunt-f91013279450"><strong>https://medium.com/@antonyan009/how-to-deploy-an-amazon-eks-cluster-using-terragrunt-f91013279450</strong></a></blockquote><p><strong>2. AWS IAM OIDC Provider for GitLab</strong></p><p>The setup is already explained in the above link.</p><p>3. IAM Role for GitLab CI</p><p>An IAM role with:</p><ul><li>sts:AssumeRoleWithWebIdentity</li><li>Trust policy scoped to GitLab OIDC</li><li>Permissions to AWS resources, here GitLab is provided with administrator access, you can create your own permission set</li><li>In our example, the ROLE_ARN is added as a variable in GitLab. It is better to keep sensitive values such as secrets/arn in the GitLab itself, make sure that you have enabled variable expansion</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*XG7mEpZHlQrc6fzTrozPrg.png" /></figure><p>Now let’s have a look at the pipeline</p><p><strong>Pipeline</strong></p><p>The pipeline runs only under controlled conditions:</p><pre>workflow:<br>  rules:<br>    - if: $CI_PIPELINE_SOURCE == &quot;merge_request_event&quot;<br>    - if: $CI_PIPELINE_SOURCE == &quot;push&quot; &amp;&amp; $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH<br>    - if: $CI_PIPELINE_SOURCE == &quot;web&quot;</pre><p>This ensures:</p><ul><li>Merge Requests trigger plan</li><li>Applies don’t run automatically</li><li>Manual execution is supported</li></ul><p>So once you commit your changes to your development branch, make a MR, the pipeline will start to execute with the following steps.</p><p><strong>stages</strong></p><pre>stages:<br>  - aws_configure<br>  - eks_auth<br>  - terraform_plan<br>  - terraform_apply_dev<br>  - terraform_apply_staging</pre><p><strong>AWS Authentication with OIDC</strong></p><p>In this step, GitLab provides an OIDC token directly to the pipeline:</p><pre>default:<br> id_tokens:<br> GITLAB_OIDC_TOKEN:<br> aud: https://gitlab.com</pre><p>This token is written to disk and used to assume an AWS role:</p><pre>aws sts get-caller-identity - profile oidc-role</pre><p>No secrets are stored. Credentials expire automatically.Also, the aws-config is saved as an artifact for use in the EKS auth step</p><p><strong>Dynamic EKS Authentication</strong></p><p>This section contains the installation part of kubectl and kubeconfig authentication.</p><p>Kubernetes access is configured at runtime:</p><pre>aws eks update-kubeconfig \<br>  --region ${REGION} \<br>  --name ${EKS_CLUSTER_NAME}</pre><p>The region and clustername will be applied during the runtime.</p><p>This provides:</p><ul><li>No static kubeconfig files</li><li>IAM-based access control</li><li>Environment-specific cluster authentication</li></ul><p>Since the terragrunt plan &amp; apply is applicable for both stages, we have created a template-like structure and will apply it in the stages with corresponding variable values. This will reduce the length of the pipeline and make it simple.</p><p>Also, the folder is structured in a way that with the variable substitution it can enter the correct directory.</p><pre>cd &quot;${CI_PROJECT_DIR}/aws-infra/${ENV}/${REGION}/eks&quot;</pre><h4>Terragrunt Plan:</h4><p>Terragrunt plan runs automatically for merge requests:</p><pre>terragrunt plan</pre><p>This allows teams to review infrastructure changes before applying them.</p><p>Once you are happy with the terragrunt plan result, you can decide whether to go further. Or fix errors?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7IFBN3BnB1ghcLudZRdL-A.png" /></figure><p>Here we will check both the dev and staging. The above example shows the sample output of terragrunt plan.</p><p><strong>Manual Applies for Dev and Staging</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQHNi7SnuFFltEHdE30j8Q.png" /></figure><p>As you can see in the picture, all applies are <strong>manual only</strong>:</p><ul><li>Dev applies requires explicit approval</li><li>Staging applies requires explicit approval</li><li>No automatic infrastructure changes</li></ul><p>This significantly reduces risk.</p><p>Once you approve, this will run the terragrunt apply from the respective folders</p><pre>cd &quot;${CI_PROJECT_DIR}/aws-infra/${ENV}/${REGION}/eks&quot;<br>AWS_PROFILE=&quot;${EKS_PROFILE}&quot; terragrunt apply --auto-approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*7RnoHtkHHUGMJwqW0JgK-g.png" /></figure><p>I don’t have any new resources to be deployed, so it matches with the current state.</p><h3>Multi-Region, Multi-Environment Support</h3><p>Each job injects environment-specific variables:</p><ul><li>ENV</li><li>REGION</li><li>EKS_CLUSTER_NAME</li></ul><p>This pattern scales easily to:</p><ul><li>Production clusters</li><li>Additional AWS regions</li><li>Multiple accounts</li></ul><h3>Security and Best Practices Achieved</h3><p>✔ No AWS access keys<br> ✔ Short-lived credentials<br> ✔ IAM-based EKS access<br> ✔ Manual approval gates<br> ✔ Clear audit trail<br> ✔ Terragrunt-friendly workflow</p><h3>Final Thoughts</h3><p>This GitLab CI/CD pipeline demonstrates a <strong>secure, scalable, and production-ready</strong> approach to managing Amazon EKS infrastructure with Terragrunt.</p><p>By combining <strong>GitLab OIDC</strong>, <strong>AWS IAM</strong>, and <strong>Terragrunt</strong>, you get:</p><ul><li>Strong security guarantees</li><li>Cleaner pipelines</li><li>Easier operations</li></ul><p>If you’re building modern cloud infrastructure on AWS, this pattern is worth adopting.</p><p>Thanks for reading</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=706d5971fe03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set up an OIDC provider for AWS-Gitlab Integration using Terraform]]></title>
            <link>https://medium.com/@antonyan009/set-up-an-oidc-provider-for-aws-gitlab-integration-using-terraform-d9f64d7dc684?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9f64d7dc684</guid>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[oidc]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Thu, 22 Jan 2026 18:01:57 GMT</pubDate>
            <atom:updated>2026-02-08T18:31:23.744Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vATJfDoXHKpda54IDDJJrw.png" /></figure><p>Modern CI/CD pipelines should <strong>never rely on long-lived cloud credentials</strong>.<br> With <strong>OpenID Connect (OIDC)</strong>, GitLab can securely authenticate to AWS using <strong>short-lived credentials</strong>, eliminating the need to store AWS access keys in GitLab.</p><p>In this article, we’ll walk through <strong>setting up an AWS OIDC provider for GitLab</strong> and configuring an <strong>IAM role</strong> that GitLab CI/CD pipelines can assume securely.</p><h3>The Problem with Static Credentials</h3><p>Traditional GitLab → AWS integrations often use:</p><ul><li>AWS_ACCESS_KEY_ID</li><li>AWS_SECRET_ACCESS_KEY</li></ul><h3>And this is risky because,</h3><ul><li>Long-lived credentials</li><li>Manual rotation</li><li>High blast radius if leaked</li><li>Stored in CI variables</li></ul><p>OIDC solves all of this.</p><h3>What Is OIDC?</h3><p><strong>OpenID Connect (OIDC)</strong> allows GitLab to:</p><ul><li>Authenticate using a <strong>token</strong></li><li>Request <strong>temporary AWS credentials</strong></li><li>Assume an IAM role using sts:AssumeRoleWithWebIdentity</li></ul><p>So there is no headache in keeping the long-lived credentials.</p><p>How to set this up?</p><p>You can clone this repo,</p><pre>https://gitlab.com/antonyan_009/eks/oidc-gitlab-setup.git</pre><p>It contains the oidc.tf, provider.tf&amp; variables.tf</p><p>Let’s concentrate on oidc.tf</p><pre>resource &quot;aws_iam_openid_connect_provider&quot; &quot;gitlab&quot; {<br>  url = &quot;https://gitlab.com&quot;<br>  client_id_list = [&quot;https://gitlab.com&quot;]<br>  # AWS manages the thumbprint for gitlab.com automatically<br>  thumbprint_list = [&quot;ffffffffffffffffffffffffffffffffffffffff&quot;] <br>}<br><br># Define the IAM role that GitLab CI/CD will assume<br>resource &quot;aws_iam_role&quot; &quot;gitlab_oidc_role&quot; {<br>  name = &quot;${local.env}gitlab_oidc_role&quot;<br><br>  # The trust policy allows assuming the role via Web Identity Federation<br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect = &quot;Allow&quot;<br>        Principal = {<br>          Federated = aws_iam_openid_connect_provider.gitlab.arn<br>        }<br>        Action = &quot;sts:AssumeRoleWithWebIdentity&quot;<br>        Condition = {<br>          StringEquals = {<br>            # This condition restricts the role assumption to a specific audience claim<br>            &quot;gitlab.com:aud&quot;: [&quot;https://gitlab.com&quot;]<br>          }<br>          StringLike = {<br>            # This condition further restricts by project path and branch<br>            &quot;gitlab.com:sub&quot;: &quot;project_path:antonyan_009/eks/*:ref_type:*:ref:*&quot;<br>          }<br>        }<br>      }<br>    ]<br>  })<br><br>  # Max session duration for the assumed role (optional)<br>  max_session_duration = 3600<br>}<br><br># (Optional) Attach a policy with specific permissions (e.g., S3 access)<br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;gitlab_policy_attachment&quot; {<br>  role       = aws_iam_role.gitlab_oidc_role.name<br>  # Replace with the ARN of your desired policy (e.g., a custom S3 policy or AWS managed policy)<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AdministratorAccess&quot; <br>}<br><br># Output the Role ARN to be used in GitLab CI/CD<br>output &quot;gitlab_oidc_role_arn&quot; {<br>  value = aws_iam_role.gitlab_oidc_role.arn<br>}</pre><p>This setup is only for GitLab. If you are planning to use GitHub, there are changes.</p><pre>resource &quot;aws_iam_openid_connect_provider&quot; &quot;gitlab&quot; {<br>  url = &quot;https://gitlab.com&quot;<br>  client_id_list = [&quot;https://gitlab.com&quot;]<br>  # AWS manages the thumbprint for gitlab.com automatically<br>  thumbprint_list = [&quot;ffffffffffffffffffffffffffffffffffffffff&quot;] <br>}</pre><p>This block defines the OIDC setup. In our case, the URL is <strong>gitlab.com</strong> itself, since we are using the default setup, also Client ID in OIDC is a unique, public string assigned to an application (the Relying Party) when it registers with an authorization server. It acts as an identifier for the application, allowing the server to recognize which client is requesting user authentication. In our case, it is gitlab itself.</p><p>Next, we need to create a role with a trust policy. This role will be assumed by GitLab pipelines. For demo purposes, we are assigning the role with administrator access; in real scenarios, we need to follow the least privilege model.</p><pre>resource &quot;aws_iam_role&quot; &quot;gitlab_oidc_role&quot; {<br>  name = &quot;${local.env}gitlab_oidc_role&quot;<br><br>  # The trust policy allows assuming the role via Web Identity Federation<br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect = &quot;Allow&quot;<br>        Principal = {<br>          Federated = aws_iam_openid_connect_provider.gitlab.arn<br>        }<br>        Action = &quot;sts:AssumeRoleWithWebIdentity&quot;<br>        Condition = {<br>          StringEquals = {<br>            # This condition restricts the role assumption to a specific audience claim<br>            &quot;gitlab.com:aud&quot;: [&quot;https://gitlab.com&quot;]<br>          }<br>          StringLike = {<br>            # This condition further restricts by project path and branch<br>            &quot;gitlab.com:sub&quot;: &quot;project_path:antonyan_009/eks/*:ref_type:*:ref:*&quot;<br>          }<br>        }<br>      }<br>    ]<br>  })<br><br>  # Max session duration for the assumed role (optional)<br>  max_session_duration = 3600<br>}</pre><p>That’s the role definition, and in the next step you need to attach this policy to the IAM role.</p><pre>resource &quot;aws_iam_role_policy_attachment&quot; &quot;gitlab_policy_attachment&quot; {<br>  role       = aws_iam_role.gitlab_oidc_role.name<br>  # Replace with the ARN of your desired policy (e.g., a custom S3 policy or AWS managed policy)<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AdministratorAccess&quot; <br>}</pre><p>That’s it, now we can deploy this.</p><pre>Terraform plan<br>terraform apply </pre><p>Bingo, the resources created successfully.</p><pre>Apply complete! Resources: 3 added, 0 changed, 0 destroyed.</pre><p>Now we can use this oidc setup in the pipelines, and we can safely remove the aws_access_key_id and aws_secret_key</p><p>Thanks for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9f64d7dc684" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to DeployAmazon EKS Cluster for Dev and Staging Using Terragrunt]]></title>
            <link>https://medium.com/@antonyan009/how-to-deploy-an-amazon-eks-cluster-using-terragrunt-f91013279450?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/f91013279450</guid>
            <category><![CDATA[terragrunt]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Fri, 16 Jan 2026 18:25:50 GMT</pubDate>
            <atom:updated>2026-02-08T19:04:33.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyTnU_n1b9Xryzo4-g3oQw.png" /></figure><p>Managing infrastructure at scale with plain Terraform can quickly become repetitive and hard to maintain. This is where <strong>Terragrunt</strong> shines. In this article, we’ll walk through how to deploy an <strong>Amazon EKS (Elastic Kubernetes Service) cluster</strong> using <strong>Terraform modules orchestrated by Terragrunt</strong>.</p><p>The goal is not just to deploy EKS, but to do it in a <strong>clean, reusable, and DRY</strong> way.</p><h3>Why Terragrunt?</h3><p>Terraform is great, but as your infrastructure grows, you’ll start seeing problems like:</p><ul><li>Repeated backend configuration</li><li>Duplicated variables across environments etc</li></ul><p>Terragrunt solves these by:</p><ul><li>Keeping Terraform code <strong>DRY</strong></li><li>Managing <strong>remote state</strong> centrally</li><li>Making <strong>multi-environment</strong> setups easier</li></ul><p>Architecture Overview</p><p>I already created a detailed post on <a href="https://medium.com/@antonyan009/deploying-an-eks-cluster-using-terraform-2ad5c8e7e06d">how to deploy an EKS cluster using Terraform</a>, so I’m not going deep on the eks/vpc features.</p><p>Here, we will deploy EKS clusters across 2 regions to replicate 2 distinct stages. We will use the same EKS module shared in the above link.<br>There are a few additional files that are used to define configuration and environment-specific values.</p><p>root.hcl</p><pre>generate &quot;provider&quot; {<br>  path      = &quot;provider.tf&quot;<br>  if_exists = &quot;overwrite&quot;<br>  contents  = &lt;&lt;EOF<br>provider &quot;aws&quot; {<br>  region = var.region<br>}<br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 6.0&quot;<br>    }<br>    helm = {<br>      source  = &quot;hashicorp/helm&quot;<br>      version = &quot;~&gt; 2.0&quot;<br><br>    }<br>  }<br>}<br>EOF<br>}<br><br>remote_state {<br>  backend = &quot;s3&quot;<br><br>  config = {<br>    bucket         = &quot;aws-terraform-state-infra-file&quot;<br>    key            = &quot;${path_relative_to_include()}/terraform.tfstate&quot;<br>    region         = &quot;us-west-2&quot;<br>    encrypt        = false<br>  }<br><br>  generate = {<br>    path      = &quot;backend.tf&quot;<br>    if_exists = &quot;overwrite&quot;<br>  }<br>}</pre><p>This file is used to generate the default provider.tf and remote backend configuration. In this example, we are deploying 2 different clusters on 2 distinct regions, and both the state files are stored in the same bucket.</p><p>For the environments, we need to create different terragrunt.hcl files with the inputs according to the env. The region will be selected from the input variable.</p><p>Now, let’s compare the terragrunt file for the environments.</p><p>terragrunt.hcl -staging</p><pre>include &quot;root&quot; {<br>  path = find_in_parent_folders(&quot;root.hcl&quot;)<br>}<br><br>terraform {<br>    source = &quot;git::https://gitlab.com/antonyan_009/eks/eks-terraform.git//eks-module?ref=main&quot;<br><br>}<br>inputs = {<br>  eks         = &quot;eks-terraform&quot;<br>  vpc         = &quot;eks-vpc&quot;<br>  env         = &quot;stage&quot;<br>  region      = &quot;us-east-2&quot;<br>  eks_version = &quot;1.30&quot;<br>  tags = {<br>    Name = &quot;eks-terraform&quot;<br>  }<br><br>cidr_block =&quot;10.0.0.0/16&quot;<br><br>instance_type  = [&quot;t3.small&quot;]<br>}<br><br></pre><p>terragrunt.hcl -dev</p><pre>include &quot;root&quot; {<br>  path = find_in_parent_folders(&quot;root.hcl&quot;)<br>}<br><br>terraform {<br>    source = &quot;git::https://gitlab.com/antonyan_009/eks/eks-terraform.git//eks-module?ref=main&quot;<br><br>}<br>inputs = {<br>  eks         = &quot;eks-terraform&quot;<br>  vpc         = &quot;eks-vpc&quot;<br>  env         = &quot;dev&quot;<br>  region      = &quot;us-west-2&quot;<br>  eks_version = &quot;1.30&quot;<br>  tags = {<br>    Name = &quot;eks-terraform&quot;<br>  }<br><br>cidr_block =&quot;10.0.0.0/16&quot;<br><br>instance_type  = [&quot;t3.small&quot;]<br>}<br><br></pre><p>to make things simple, I just changed the region and kept other values similar.</p><p>How to deploy</p><p>Let’s deploy the dev first,</p><ul><li>clone the repo, and go to the dev folder inside the AWS infra, and inside the eks folder, you can see the terragrunt.hcl file.</li><li>Update the inputs as per your requirements, and running</li></ul><pre>terragrunt init</pre><p>this will download the module and other dependencies.</p><p>In the next step, deploy the resources using</p><pre>terragrunt apply</pre><p>You will see a similar output to Terraform, verify the resource informations and type yes.</p><p>It will take 10–15 mins to complete the setup once it is completed, you can see this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Ms8QXB7DrjB9SYLO6nAcQ.png" /></figure><p>Repeat the same process for staging as well. You need to wait couple of minutes to complete this process as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kx9M9BVCPNCwjlkgkYqH-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*QQ2AUt8tVFByG_K2-Shmlw.png" /></figure><p>That’s it, you deployed 2 EKS clusters with terragrunt.</p><p>If you don’t want to go to each repo and terragrunt apply, you can stay in the folder that contains the root.hcl and run,</p><pre>terragrunt apply --all</pre><p>It will ask for the confirmation, click on y and continue.</p><p>Simple, cleaner :)</p><p><strong>Destroy</strong></p><p>If you want to destroy the clusters, simply run</p><pre>terragrunt destroy - all</pre><p>It will ask for a confirmation</p><pre>INFO Unit queue will be processed for destroy in this order:<br>- Unit staging/us-east-2/eks<br>- Unit dev/us-west-2/eks<br>WARNING: Are you sure you want to run `terragrunt destroy` in each unit of the run queue displayed above? There is no undo! (y/n)</pre><p>Click on y, it will delete both the clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EWPEFP_Z5Skw_V72928AOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ok3fkIQcVcXB6OPiGYwkVw.png" /></figure><p>That’s it, buddy</p><p>Interested in CICD with OIDC, don’t waste time, it’s already here.</p><p><a href="https://medium.com/@antonyan009/secure-multi-stageamazon-eks-deployments-using-gitlab-ci-cd-terragrunt-and-oidc-no-aws-access-706d5971fe03">https://medium.com/@antonyan009/secure-multi-stageamazon-eks-deployments-using-gitlab-ci-cd-terragrunt-and-oidc-no-aws-access-706d5971fe03</a></p><p>Thanks for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f91013279450" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set up an EKS cluster using Terraform]]></title>
            <link>https://medium.com/@antonyan009/deploying-an-eks-cluster-using-terraform-2ad5c8e7e06d?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ad5c8e7e06d</guid>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Wed, 07 Jan 2026 18:47:21 GMT</pubDate>
            <atom:updated>2026-02-08T18:36:39.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*ADVK8qfyozJqSppVEZ_Bag.png" /></figure><p>Kubernetes has become the standard for container orchestration, and <strong>Amazon Elastic Kubernetes Service (EKS)</strong> makes it easier to run Kubernetes on AWS.<br>However, manually creating EKS clusters through the AWS Console is error-prone and hard to reproduce.</p><p>In this article, we’ll walk through <strong>deploying an EKS cluster using Terraform</strong>, focusing on <strong>infrastructure as code</strong>, best practices, and a clean project structure.</p><h3>Why Terraform for EKS?</h3><p>Terraform allows you to:</p><ul><li>Define infrastructure in a <strong>declarative</strong> way</li><li>Version-control your AWS resources</li><li>Recreate environments consistently (dev, staging, prod)</li><li>Avoid manual configuration drift</li></ul><p>When combined with EKS, Terraform gives you a <strong>repeatable and auditable Kubernetes setup</strong>.</p><h3>Architecture Overview</h3><p>The EKS setup in this guide includes:</p><ul><li>A custom <strong>VPC</strong> with public and private subnets</li><li>Internet Gateway and NAT Gateway</li><li>An <strong>EKS control plane</strong></li><li>Managed <strong>EKS node groups</strong></li><li>Proper IAM roles and security groups</li></ul><p>This architecture follows AWS best practices for production-ready clusters.</p><h3><strong>Prerequisites</strong></h3><p>Please make sure that you have configured the following on your machine.</p><ul><li><a href="https://developer.hashicorp.com/terraform/install">Terraform</a></li><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">AWS CLI v2</a></li><li><a href="https://kubernetes.io/docs/tasks/tools/">kubectl</a></li><li><a href="https://github.com/ahmetb/kubectx">kubectx </a>(not mandatory, good to have)</li></ul><h3>Project Structure</h3><p>A clean Terraform structure makes your code easier to maintain and update. Our code is defined in the following structure.</p><pre>.<br>├── main.tf<br>├── variables.tf<br>├── provider.tf<br>├── datasource.tf<br>└── modules<br>    └── eks<br>        ├── eks.tf<br>        ├── iamroles.tf<br>        ├── igw.tf<br>        ├── nat.tf<br>        ├── noderoles.tf<br>        ├── nodes.tf<br>        ├── public-subnet.tf<br>        ├── private-subnet.tf<br>        ├── output.tf<br>        ├── variables.tf<br>        ├── vpc.tf<br>        └── route.tf</pre><p>With this code, we will deploy an EKS cluster with subnets based on the number of AZs.</p><p>Let’s walk through the code, clone the repo</p><pre>git clone https://gitlab.com/antonyan_009/eks/eks-terraform.git<br>cd  eks-terraform</pre><h3>Defining the Provider</h3><pre>provider &quot;aws&quot; {<br>  region = var.region<br>}</pre><p>This ensures all AWS resources are created in the desired region. We are using the Helm provider as well for later Helm installations.</p><h3>Using Locals for Environment Configuration</h3><pre>locals {<br>  env         = &quot;dev&quot;<br>  region      = &quot;us-west-2&quot;<br>  eks_name    = &quot;eks-terraform&quot;<br>  eks_version = &quot;1.30&quot;</pre><pre>  tags = {<br>    Project     = &quot;eks-terraform&quot;<br>    Environment = local.env<br>  }<br>}</pre><p>Using locals keeps configuration centralized and avoids duplication.</p><p>In the root level, we defined the variables and referenced them in the <strong>main.tf</strong> so that these values will be passed to the Terraform module.</p><pre>main.tf</pre><pre><br><br>module &quot;eks&quot; {<br>    <br>  source = &quot;./eks-module/&quot;<br><br>   cidr_block_public_1 = var.cidr_block_public_1<br>   cidr_block_public_2 = var.cidr_block_public_2<br>   cidr_block_private_1 = var.cidr_block_private_1<br>   cidr_block_private_2 = var.cidr_block_private_2<br>   <br>   eks         = local.eks<br>   vpc         = local.vpc<br>   env         = local.env<br>   region      = local.region<br>   eks_version = local.eks_version<br>   az = data.aws_availability_zones.available.names   <br>   tags        = local.tags<br>  <br>}</pre><p>Our module expects these inputs, so we need to define them at the root level like this.</p><p>You can change the variable values by using the variables.tf file from the root folder.</p><pre>variables.tf</pre><pre><br><br>locals {<br>  eks         = &quot;eks-terraform&quot;<br>  vpc         = &quot;eks-vpc&quot;<br>  env         = &quot;dev&quot;<br>  region      = &quot;us-west-2&quot;<br>  eks_version = &quot;1.30&quot;<br>   az = data.aws_availability_zones.available.names<br>  tags = {<br>    Name = &quot;eks-terraform&quot;<br>  }<br>}<br><br>variable &quot;cidr_block_public_1&quot; {<br>  default = &quot;10.0.0.0/18&quot;<br>}<br>variable &quot;cidr_block_public_2&quot; {<br>  default = &quot;10.0.64.0/18&quot;<br>}<br>variable &quot;cidr_block_private_1&quot; {<br>  default = &quot;10.0.128.0/18&quot;<br>}<br>variable &quot;cidr_block_private_2&quot; {<br>  default = &quot;10.0.192.0/18&quot;<br>}</pre><h3>Creating EKS Cluster</h3><p>The EKS module creates a VPC with the following resources.</p><ul><li>Public subnets</li><li>Private subnets</li><li>NAT Gateway</li><li>Internet gateway</li><li>Node group for worker nodes</li></ul><pre>module &quot;eks&quot; {<br>  source = &quot;./eks-module&quot;</pre><pre>   cidr_block_public_1 = var.cidr_block_public_1<br>   cidr_block_public_2 = var.cidr_block_public_2<br>   cidr_block_private_1 = var.cidr_block_private_1<br>   cidr_block_private_2 = var.cidr_block_private_2<br>   <br>   eks         = local.eks<br>   vpc         = local.vpc<br>   env         = local.env<br>   region      = local.region<br>   eks_version = local.eks_version<br>   az = data.aws_availability_zones.available.names<br>   tags        = local.tags</pre><p>We are using a name tag to identify the resource.</p><p>Terraform handles dependencies automatically, ensuring the VPC is created before EKS.</p><h3>Applying the Configuration</h3><p>Before applying, make sure that you have configured AWS-CLI with access key and secret key.</p><p>Initialize Terraform:</p><p>This step will initialize the modules and dependencies</p><pre>terraform init</pre><p>Validate your configuration:</p><p>This step will make sure that the configuration is valid.</p><pre>terraform validate</pre><p>Correct format issues</p><pre>terraform fmt</pre><p>Preview the resources:</p><pre>terraform plan</pre><p>Create the infrastructure:</p><pre>terraform apply</pre><p>Typically, it will take 10–15 mins to provision the entire EKS cluster.</p><pre>Apply complete! Resources: 24 added, 0 changed, 0 destroyed.</pre><p><strong>PRO TIP</strong></p><blockquote>If you are on AWS Free Tier, if you try to use t2.small/medium, the resource won’t be created; by default, they don’t allow it to be created. In that case, change the instance type in the nodes.tf to t2.micro then complete the terraform apply.</blockquote><blockquote>Once the cluster is created, modify the instance type to t2.small/medium, bingo :)</blockquote><h3>Accessing the Cluster</h3><p>After creation, update your kubeconfig:</p><pre>aws eks update-kubeconfig \<br>  --region us-west-2 \<br>  --name eks-terraform</pre><p>Replace with your cluster name, and you will receive a response like the following.</p><pre>Updated context arn:aws:eks:us-west-2:&lt;aws_account_id&gt;:cluster/eks-terraform in /home/&lt;user&gt;/.kube/config</pre><p>Verify access:</p><pre>kubectl get nodes</pre><pre>kubectl get nodes<br>NAME                                         STATUS   ROLES    AGE    VERSION<br>ip-10-0-139-28.us-west-2.compute.internal    Ready    &lt;none&gt;   117s   v1.30.14-eks-ecaa3a6<br>ip-10-0-220-102.us-west-2.compute.internal   Ready    &lt;none&gt;   119s   v1.30.14-eks-ecaa3a6</pre><p>Let’s try to create an nginx pod and port-forward it to make sure that we can run a workload on the newly created cluster.</p><pre>kubectl run nginx-pod --image=nginx<br>kubectl port-forward nginx-pod 8080:80</pre><p>Let’s try to access it on port 8080 on localhost</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-6WXakE33ATWnWixlmp3mQ.png" /></figure><p>Bingo, that’s it, you created your first EKS cluster using Terraform, congrats :)</p><p>If you are just playing with the EKS cluster, make sure that you delete the resources to avoid getting billed.</p><pre>terraform destroy</pre><h3>Conclusion</h3><p>Deploying EKS with Terraform provides a <strong>repeatable, production-ready Kubernetes platform</strong> while keeping your infrastructure maintainable and scalable.</p><p>If you’re managing multiple environments or teams, this approach quickly pays off in reliability and operational simplicity.</p><p>In the upcoming articles, we will introduce terragrunt to manage multiple environments with the same Terraform code.</p><p>If you found this helpful, feel free to connect or leave feedback — happy automating!</p><p>Any plans for deploying EKS to dev and stage? Check it out</p><p><a href="https://medium.com/@antonyan009/how-to-deploy-an-amazon-eks-cluster-using-terragrunt-f91013279450">https://medium.com/@antonyan009/how-to-deploy-an-amazon-eks-cluster-using-terragrunt-f91013279450</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ad5c8e7e06d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Jenkins Pipeline Status to Microsoft Teams without connector]]></title>
            <link>https://medium.com/@antonyan009/integrate-jenkins-pipeline-status-to-microsoft-teams-without-connector-067208e3cd0f?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/067208e3cd0f</guid>
            <category><![CDATA[notifications]]></category>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[microsoft-teams]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 15:46:45 GMT</pubDate>
            <atom:updated>2025-02-07T15:46:45.355Z</atom:updated>
            <content:encoded><![CDATA[<p>Microsoft Teams used to have a built-in <strong>Connector</strong> feature that made sending Jenkins pipeline build status updates directly into a Teams channel easy. However, many teams have been looking for alternative solutions with that feature no longer available.</p><p>In this post, I’ll walk you through a new workaround that allows you to achieve the same functionality — sending Jenkins pipeline notifications to Microsoft Teams — without relying on the deprecated Connector feature. Whether you’re managing CI/CD pipelines or just want real-time visibility into your builds, this method will ensure that your team stays informed.</p><p>Let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*hPn-4IkNB7cgQeja3vwMjA.png" /></figure><p>for this you need,</p><ul><li>Jenkins Instance</li><li>Teams Account</li></ul><p>In your teams application, you can find an option called Apps(not available in the free version).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*UPhi5CNQ32vw3W4RTW0U-A.png" /></figure><p>You can search for Jenkins in the search bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*zKWS5LdXWNp37_iKD-5Viw.png" /></figure><p>It should be available in teams app, if it is not available you can check with the teams admin to install the same.</p><p>Once you select the Jenkins app, you can start configuring it.</p><p>It will give you a webhook URL, copy that we need to use the URL in the Jenkins app.</p><p>Select the Team and channel you need to get the notification.</p><p>and complete the process.</p><p>Now you need to log in to your Jenkins instance.</p><p>Once you log in click on manage jenkins &gt;&gt; install plugin &gt;&gt; search for Office 365 connector and install it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eqt3bhKtZzvN4I6zpwszsw.png" /></figure><p>Once the plugin is installed navigate to the pipeline that you need to get the notifications in teams.</p><p>Now you will be able to find the option to configure the connector.</p><p>paste the URL copied from teams and provide a name for the connector.</p><p>You can ignore the <strong>Use AdaptiveCard Format, </strong>let’s keep it disabled.</p><p>Click on advanced, choose the actions that need to be forwarded to teams, and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*ndNWu1XSr-wOvHRH7ZE55Q.png" /></figure><p>Now try to build the job, and you will get a notification like this in your teams channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*PdwO4J7fLDpNsGzcWZdtAQ.png" /></figure><p>That’s it, now you don’t need to check every build status in Jenkins, it will be updated to your teams channel.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=067208e3cd0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CI/CD pipeline to Automate Docker-image build with GitHub Actions]]></title>
            <link>https://medium.com/@antonyan009/ci-cd-pipeline-for-automate-docker-image-build-with-github-actions-b669e3ff564e?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/b669e3ff564e</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Wed, 08 Mar 2023 14:44:58 GMT</pubDate>
            <atom:updated>2023-03-08T15:04:30.933Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*2NUneJQVWSVLTEjoDBNhrQ.png" /></figure><p>Whenever you are working on a product you have to ensure that it performs well in the development and test environment before pushing it into a production environment.</p><p>What will be the case of a docker application? you have to ensure the container works fine with every change in the application. It can be checked by running containers with updated docker images.</p><p>But it is a hectic task to create the new images manually based on the changes that we have made in the application, right?</p><p>In this example, we are automating the process using Github actions, whenever you are making an update in your git repo a docker image will be built in the build server and a docker container will be created in the test server by triggering GitHub action.</p><p>So let’s start.</p><p>We are creating a GitHub repository for this project and our repository contains the following files in it.</p><ul><li>Dockerfile</li><li>app.py</li><li>requirement.txt</li></ul><p>Our sample repository contains a basic flask application.</p><p>You can refer to the files <a href="https://github.com/antony-a-n/CI-CD-pipeline-for-Automate-Docker-image-build-with-Github-Actions">here</a></p><p>The Docker file contains the instructions to create our docker image.</p><p>app.py is our sample application which prints “hello world app”.</p><p>requirement.txt refers to the modules required for our application.</p><p>Once you have created the required files in your repository, we can proceed to set up our GitHub actions.</p><p>Inside your repo, you can find an option “<strong>actions</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8I6CvZvCV_3a8CknQUhGw.png" /></figure><p>Now you will be able to view the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tT7jExk8dc1yidMVVWVLLg.png" /></figure><p>Since we need to create a docker image, select the “Docker image “ and click configure.</p><p>You can see that a new file is created inside your repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmM5mhw7wF5J6ToBQUCShA.png" /></figure><p>This is a default workflow, now we are making our required changes in this file.</p><p>We need to set up our pipeline in the following way.</p><ul><li>When there is a commit to the master branch, we need the actions triggered.</li><li>In the dev environment, a docker image should be created based on the latest changes and need to push the image to the docker hub.</li><li>In the test environment, a docker container should be created from the latest image from the docker hub.</li></ul><p>So let’s create the following workflow based on this requirement.</p><pre>name: Docker Image build<br><br>on:<br>  push:<br>    branches: [ &quot;main&quot; ]<br>  pull_request:<br>    branches: [ &quot;main&quot; ]<br><br>jobs:<br><br>  build:<br>    name: Build Docker image and push to repositories<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v3<br>  <br>      - name: login to hub  <br>        uses: docker/login-action@v2<br>        with:<br>          username: ${{ secrets.DOCKER_USERNAME }}<br>          password: ${{ secrets.DOCKER_PASSWORD }}<br>          <br>      - name: Build and push<br>        uses: docker/build-push-action@v4<br>        with:<br>          context: .<br>          push: true<br>          tags: antonyanlinux/myapp:latest<br>          <br>      - name: deploying<br>        uses: appleboy/ssh-action@v0.1.8<br>        with:<br>          host: ${{ secrets.SSH_HOST }}<br>          username: ${{ secrets.SSH_USER }}<br>          password: ${{ secrets.SSH_KEY }}<br>          port: ${{ secrets.SSH_PORT }}<br>          script: |<br>            docker image pull antonyanlinux/myapp:latest<br>            docker container stop my-container<br>            docker container rm my-container<br>            docker container run -d --name my-container -p 80:5000 antonyanlinux/myapp<br>        <br>       </pre><p>Let’s have a deeper look at the code.</p><pre>on:<br>  push:<br>    branches: [ &quot;master&quot; ]<br>  pull_request:<br>    branches: [ &quot;master&quot; ]</pre><p>Whenever a push/pull request occurs on the master branch, it will be triggered.</p><p>In the next step, we are specifying the following actions.</p><ul><li><strong>runs-on: ubuntu-latest</strong> denotes that we are performing the image build action in a virtual environment based on ubuntu latest.</li></ul><p>In our job section, we are using some actions for our workflow.</p><ul><li><strong>actions/checkout@v3 </strong>It is an official GitHub Action used to check out a repository so a workflow can access it.</li><li><strong>docker/login-action@v2 </strong>we need to push our images to images to docker hub, it can be done with help of this action.</li></ul><p>In this action, we need to authenticate the docker hub with our username and password, we are passing these values using the secret option, and we will later check how to add secrets to GitHub.</p><ul><li><strong>docker/build-push-action@v4 </strong>this action will create a docker image based on the Dockerfile and it will be pushed to our docker hub account.</li></ul><p>Now the latest image is pushed to our docker hub account. We need to check the output by running a docker container based on the image that we have pushed into the docker hub.</p><p>So we are setting a test server with docker installed and we have added ec2-user to the docker group.</p><p>Also, we have enabled password authentication for the server and the login details such as username, password, hostname are stored as secrets.</p><ul><li><strong>appleboy/ssh-action@v0.1.8 </strong>this action will be performing ssh actions and creating the docker container, the commands are mentioned in the script section.</li></ul><p>After making the changes commit the file.</p><p>That’s it, We need to add certain secrets here, for that clock on settings &gt;&gt; secrets and variables&gt;&gt; action</p><p>You will be directed to the following interface,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apURm5eob0sbXTT67tOxxA.png" /></figure><p>Click on create new repository secret, and add the secrets.</p><ul><li>docker hub username</li><li>docker hub password</li><li>The IP address of the test server</li><li>ssh user</li><li>ssh port</li><li>ssh password</li></ul><p>We are setting up the test server in amazon Linux, so our ssh user will be ec2-user.</p><p>once you have added the secrets, it will look like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*jR2VmFrVQ0zsxNOHqtgxAQ.png" /></figure><p>Now let’s check our workflow, we are making a change in our application and updating it to version 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*YshDuTNijxbhspCHYlUMdw.png" /></figure><p>If we check the actions tab, we can see that our workflow is running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C42uhdkDs5d6lu68wWTPZQ.png" /></figure><p>If we click on the workflow we can see that it executed successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7SG15NiPnnFD4RUipvpLYQ.png" /></figure><p>Now let’s have a check on our container, it is running at port 80 of our test server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLOA89fuRBVv-HCEUGNYvw.png" /></figure><p>Yes, It changed to version 1 to version 2, Let’s update the version to 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*91OIhGhtvbZqGnHOQShzcw.png" /></figure><p>Now the pipeline triggered and it started executing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhrUzabctTkBRLkWBVSXWw.png" /></figure><p>It is completed now,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8szv2Fx6jE0rtCHZVDP0-g.png" /></figure><p>Let’s check on our container,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qI6vOkr5WhqT6ZrK7tAWZQ.png" /></figure><p>It updated to version 3 now.</p><p>That’s it, we have successfully created the pipeline.</p><p>In this article, we have checked how to automate the Docker image build process on every commit on the Git repo using GitHub actions.</p><p>By following this automation process we can save time and can ensure that every change that we are committing is reflected in the docker container.</p><p>Thank you for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b669e3ff564e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a private docker registry with SSL support and basic authentication on an Amazon…]]></title>
            <link>https://medium.com/@antonyan009/creating-a-private-docker-registry-with-ssl-and-basic-authentication-on-an-amazon-linux-machine-86055caf164c?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/86055caf164c</guid>
            <category><![CDATA[amazon-linux-2]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Wed, 01 Mar 2023 15:21:59 GMT</pubDate>
            <atom:updated>2023-03-10T18:48:06.800Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Create a private docker registry with SSL support and basic authentication on an Amazon Linux</h3><p>Sometimes we must create our own docker registry to keep our docker images safe. In this example, we create a private docker registry secured with SSL and basic authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KdxsWf-6_AGhjBGufnZdBA.png" /></figure><p>So let’s start.</p><p>Here we are using an amazon Linux machine for our project.</p><p>before proceeding, we need to make sure that we have already installed docker, we can use the following command to install docker if it is not installed yet.</p><pre>$ sudo yum install docker -y<br>$ sudo systemctl restart docker<br>$ sudo systemctl enable docker</pre><p>Now we can add our ec2-user to the docker group</p><pre>$ sudo usermod -a -G docker ec2-user</pre><p>Check the version using the following command.</p><pre>$ docker  version<br><br>Client:<br> Version:           20.10.17<br>Server:<br> Engine:<br>  Version:          20.10.17<br>  API version:      1.41 (minimum version 1.12)<br>  Go version:       go1.18.6</pre><p>In the next step, we are installing docker-compose, for that install docker-compose using the following command.</p><pre>sudo curl -SL https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-linux-x86_64 -o /usr/bin/docker-compose</pre><p>Once it is completed, you need to allow execution permission for the location.</p><pre>sudo chmod +x /usr/bin/docker-compose</pre><p>Now verify it is configured correctly.</p><pre>$ docker-compose version<br>Docker Compose version v2.6.0</pre><p>In the next step, we are downloading nginx for setting up the web server, use the following command to install the same.</p><pre>$ sudo amazon-linux-extras install nginx1 -y<br>$ sudo systemctl restart nginx<br>$ sudo systemctl enable nginx</pre><p>We need to configure the server block for our nginx server, we will get back to it, before that we need to install let&#39;s encrypt for securing our private registry.</p><pre>$ sudo yum update<br>$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm<br>$ sudo yum-config-manager --enable epel<br>$ sudo yum install certbot-nginx</pre><p>Make sure that the installation was successful.</p><pre>$ certbot --version<br>certbot 1.11.0</pre><p>Now we need to configure nginx, first, we can create a document root.</p><p>We are setting up the private registry as “registry.antonyan.tech” in this case, so we are creating a document root for that under /var/www/html</p><pre>$ sudo mkdir -p /var/www/html/registry.antonyan.tech <br>$ sudo chown -R $USER:$USER /var/www/html/registry.antonyan.tech</pre><p>Now we need to add our domain to conf.d , for that create a new file under the sites-available section.</p><pre>$ sudo vi /etc/nginx/conf.d/registry.antonyan.tech.conf</pre><p>add a basic server block in the file.</p><pre>server {<br>        listen 80;<br>      <br>        root /var/www/html/registry.antonyan.tech;<br>        index index.html index.htm index.nginx-debian.html;<br><br>        server_name registry.antonyan.tech;<br><br>        location / {<br>                try_files $uri $uri/ =404;<br>        }<br>}</pre><p>Now save and exit from the file.</p><p>You can add a sample index file in the document root to verify it is up and running.</p><p>Now we can install SSL for our registry file, use the following command install SSL. Make sure that you have pointed the domain name to your registry server.Also, replace registry.antonyan.tech with your URL.</p><pre>$ sudo certbot --nginx -d registry.antonyan.tech</pre><p>Complete the installation process, it SSL is issued successfully, you will get the following message.</p><pre><br>Congratulations! You have successfully enabled https://registry.antonyan.tech</pre><p>In the next step, we are setting up our docker-compose file, so create a registry directory for our project.</p><pre>$ mkdir registry</pre><p>Now create a folder in the registry folder to store the images.</p><pre>$ cd registry/<br>$ mkdir data</pre><p>We have to set up nginx port forwarding, our registry is listening to port 5000.</p><p>Update the /etc/nginx/conf.d/registry.antonyan.tech.conf to the following content.</p><pre>server {<br><br>        root /var/www/html/registry.antonyan.tech;<br>        index index.html index.htm index.nginx-debian.html;<br><br>        server_name registry.antonyan.tech;<br><br>        location / {<br>                 # Do not allow connections from docker 1.5 and earlier<br>    # docker pre-1.6.0 did not properly set the user agent on ping, catch &quot;Go *&quot; user agents<br>    if ($http_user_agent ~ &quot;^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$&quot; ) {<br>      return 404;<br>    }<br><br>    proxy_pass                          http://localhost:5000;<br>    proxy_set_header  Host              $http_host;   # required for docker client&#39;s sake<br>    proxy_set_header  X-Real-IP         $remote_addr; # pass on real client&#39;s IP<br>    proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;<br>    proxy_set_header  X-Forwarded-Proto $scheme;<br>    proxy_read_timeout                  900;<br>        }<br><br>    listen 443 ssl; # managed by Certbot<br>    ssl_certificate /etc/letsencrypt/live/registry.antonyan.tech/fullchain.pem; # managed by Certbot<br>    ssl_certificate_key /etc/letsencrypt/live/registry.antonyan.tech/privkey.pem; # managed by Certbot<br>    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot<br>    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot<br><br>}<br>server {<br>    if ($host = registry.antonyan.tech) {<br>        return 301 https://$host$request_uri;<br>    } # managed by Certbot<br><br><br>        listen 80;<br><br>        server_name registry.antonyan.tech;<br>    return 404; # managed by Certbot<br><br><br>}</pre><p>Now let’s set up basic authentication, using htpasswd</p><pre>$ sudo yum install httpd-tools -y</pre><p>Now we need to create a directory for storing the credentials.</p><pre>$ mkdir registry/auth</pre><p>Create your user and password for the registry</p><pre>$ htpasswd -Bbn testuser test@123 &gt; registry/auth/registry.password</pre><p>Here the username will “testuser” with password “test@123”, you can change it as per your choice.</p><p>Once you create the login credentials, we can set up the docker-compose file.</p><pre>$ cd registry/</pre><p>We are using the registry image for setting up our registry, also we are setting up a restart policy as always for our container.</p><pre>$ vi docker-compose.yml</pre><pre>services:<br>  registry:<br>    restart: always<br>    image: registry:2<br>    ports:<br>    - &quot;5000:5000&quot;<br>    environment:<br>      REGISTRY_AUTH: htpasswd<br>      REGISTRY_AUTH_HTPASSWD_REALM: Registry<br>      REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password<br>      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data<br>    volumes:<br>      - ./auth:/auth<br>      - ./data:/data</pre><p>REGISTRY_AUTH defines that we are using htpasswd as our authentication method.</p><p>REGISTRY_AUTH_HTPASSWD_PATH defines the password file.</p><p>Also, we are creating 2 volumes for our data and auth folders. We are tweaking a value here in our nginx.conf. Sometimes our docker images will be large in size, so we are updating the uploading size to 10 GB which will be enough to upload the images.</p><p>Add the following line in nginx.conf in http block.</p><pre>client_max_body_size 10240m;</pre><p>Now restart nginx service, and make sure that there is no issue with the configuration.</p><pre>$ sudo nginx -t<br>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful<br><br>$ sudo systemctl restart nginx</pre><p>Finally, we are starting our container with the following command.</p><pre>$ docker-compose up -d</pre><p>You can see the following output in the console</p><pre>[+] Running 6/6<br> ⠿ registry Pulled                                                                                                                                                          4.7s<br>   ⠿ ef5531b6e74e Pull complete                                                                                                                                             1.0s<br>   ⠿ a52704366974 Pull complete                                                                                                                                             1.2s<br>   ⠿ dda5a8ba6f46 Pull complete                                                                                                                                             1.5s<br>   ⠿ eb9a2e8a8f76 Pull complete                                                                                                                                             1.6s<br>   ⠿ 25bb6825962e Pull complete                                                                                                                                             1.6s<br>[+] Running 2/2<br> ⠿ Network registry_default       Created                                                                                                                                   0.1s<br> ⠿ Container registry-registry-1  Started  </pre><p>Now we can check our container status.</p><pre>$ docker container ls -a<br>CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS          PORTS                                       NAMES<br>3dbbd492959a   registry:2   &quot;/entrypoint.sh /etc…&quot;   16 minutes ago   Up 16 minutes   0.0.0.0:5000-&gt;5000/tcp, :::5000-&gt;5000/tcp   registry-registry-1</pre><p>You can see that our container is running and it listening to port 5000 of our host machine.</p><p>We need to make sure that we can push and pull images to our registry, for testing purposes we are pulling an alpine image from the docker hub.</p><pre>$ docker image pull alpine<br><br>Using default tag: latest<br>latest: Pulling from library/alpine<br>63b65145d645: Pull complete<br>Digest: sha256:69665d02cb32192e52e07644d76bc6f25abeb5410edc1c7a81a10ba3f0efb90a<br>Status: Downloaded newer image for alpine:latest<br>docker.io/library/alpine:latest</pre><p>Now we are updating the tag.</p><pre>$ docker tag alpine  registry.antonyan.tech/newimage</pre><p>Now we can log in to our private registry.</p><pre>$ docker login registry.antonyan.tech<br>Username: testuser<br>Password:<br>WARNING! Your password will be stored unencrypted in /home/ec2-user/.docker/config.json.<br>Configure a credential helper to remove this warning. See<br>https://docs.docker.com/engine/reference/commandline/login/#credentials-store<br><br>Login Succeeded</pre><p>Let’s push the image to the private registry.</p><pre>$ docker push registry.antonyan.tech/newimage<br><br>Using default tag: latest<br>The push refers to repository [registry.antonyan.tech/newimage]<br>7cd52847ad77: Pushed<br>latest: digest: sha256:e2e16842c9b54d985bf1ef9242a313f36b856181f188de21313820e177002501 size: 528</pre><p>Success, the image was pushed to the registry without any issues. Now we are checking the availability of the registry from a client machine.</p><p>Log in to a different server and login to our private registry.</p><pre>[root@client ~]# docker login registry.antonyan.tech<br>Username: testuser<br>Password:<br>WARNING! Your password will be stored unencrypted in /root/.docker/config.json.<br>Configure a credential helper to remove this warning. See<br>https://docs.docker.com/engine/reference/commandline/login/#credentials-store<br><br>Login Succeeded</pre><p>Let’s pull the image now.</p><pre>[root@client ~]# docker image pull registry.antonyan.tech/newimage<br>Using default tag: latest<br>latest: Pulling from newimage<br>63b65145d645: Pull complete<br>Digest: sha256:e2e16842c9b54d985bf1ef9242a313f36b856181f188de21313820e177002501<br>Status: Downloaded newer image for registry.antonyan.tech/newimage:latest<br>registry.antonyan.tech/newimage:latest<br><br>[root@client ~]# docker image ls -a<br>REPOSITORY                        TAG       IMAGE ID       CREATED       SIZE<br>registry.antonyan.tech/newimage   latest    b2aa39c304c2   2 weeks ago   7.05MB</pre><p>We have configured the private registry successfully.</p><p>I hope this document was able to provide a clearcut idea about setting up a private docker registry.</p><p>Thank you for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86055caf164c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Launching AWS resources using Ansible and deploying a website from Git]]></title>
            <link>https://medium.com/@antonyan009/launching-aws-resources-using-ansible-and-deploying-a-website-from-git-6f968eb4831f?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f968eb4831f</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Tue, 28 Feb 2023 17:15:37 GMT</pubDate>
            <atom:updated>2023-02-28T17:15:37.281Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Folks,</p><p>Ansible is a well-known tool for configuration management with its own advantages. We can use ansible for Creating AWS resources too.</p><p>Sounds great, right?</p><p>In this example, we are setting up a basic AWS infrastructure and launching a website from the GitHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*688xpMVfpE2WkUuXCvhjig.png" /></figure><p>Before proceeding you have to make sure that you have installed the latest version of ansible and required python modules such as boto, botocore, boto3.</p><p>If it is not installed, don’t worry. You can use the following commands to install the latest version of ansible and python modules.</p><pre>$ yum install python3 python3-pip<br>$ pip3 install ansible</pre><p>Make sure that the ansible installation was successful.</p><pre>$ ansible --version<br><br>ansible [core 2.11.12]<br>  config file = None<br>  configured module search path = [&#39;/home/ec2-user/.ansible/plugins/modules&#39;, &#39;/usr/share/ansible/plugins/modules&#39;]<br>  ansible python module location = /home/ec2-user/.local/lib/python3.7/site-packages/ansible<br>  ansible collection location = /home/ec2-user/.ansible/collections:/usr/share/ansible/collections<br>  executable location = /home/ec2-user/.local/bin/ansible<br>  python version = 3.7.16 (default, Dec 15 2022, 23:24:54) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)]<br>  jinja version = 3.1.2<br>  libyaml = True</pre><p>Now we can install the required modules using pip.</p><pre>pip3 install boto boto3 botocore</pre><p>Also, we need some additional ansible roles for our code, so we are installing the same using ansible-galaxy.</p><pre>ansible-galaxy collection install amazon.aws</pre><p>Now Let’s review the code, It consists of 2 plays. The second play will be running on a dynamic inventory created by the 1st play.</p><pre>---<br>- name: &quot;Creating AWS resources&quot;<br>  hosts: localhost<br>  become: false<br>  vars_files:<br>    - login.yml<br>  vars:<br>    region: &quot;ap-south-1&quot;<br>    project: &quot;demo&quot;<br>    env: &quot;dev&quot;<br>  tasks:<br>    - name: &quot;SSH Key pair &quot;<br>      amazon.aws.ec2_key:<br>        name: &quot;{{ project }} - {{ env }}&quot;<br>        access_key: &quot;{{ access_key }}&quot;<br>        secret_key: &quot;{{ secret_key }}&quot;<br>        region: &quot;{{ region }}&quot;<br>        state: present<br>      register: key<br>    - name: &quot;keyfile&quot;<br>      debug:<br>        var: key<br>    - name: &quot;Saving Key&quot;<br>      when: key.changed<br>      copy:<br>        content: &quot;{{ key.key.private_key }}&quot;<br>        dest: &quot;{{ project }}-{{ env }}.pem&quot;<br>        mode: 0400<br>    - name: &quot;creating security group&quot;<br>      amazon.aws.ec2_security_group:<br>        name: &quot;{{ project }}-{{ env }}&quot;<br>        description: &quot;{{ project }}-{{ env }}&quot;<br>        access_key: &quot;{{ access_key }}&quot;<br>        secret_key: &quot;{{ secret_key }}&quot;<br>        region: &quot;{{ region }}&quot;<br>        rules:<br>          - proto: tcp<br>            from_port: 80<br>            to_port: 80<br>            cidr_ip: 0.0.0.0/0<br> <br>          - proto: tcp<br>            from_port: 22<br>            to_port: 22<br>            cidr_ip: 0.0.0.0/0<br> <br>          - proto: tcp<br>            from_port: 443<br>            to_port: 443<br>            cidr_ip: 0.0.0.0/0<br> <br>        tags:<br>          Name: &quot;{{ project }}-{{ env }}&quot;<br>          Project: &quot;{{ project }}&quot;<br>          Env: &quot;{{ env }}&quot;<br>      register: sg<br> <br>    - name: &quot;Creating an ec2 instance&quot;<br>      amazon.aws.ec2_instance:<br>        access_key: &quot;{{ access_key }}&quot;<br>        secret_key: &quot;{{ secret_key }}&quot;<br>        region: &quot;{{ region }}&quot;<br>        name: &quot;{{ project }}-{{ env }}-webserver&quot;<br>        key_name: &quot;{{ key.key.name }}&quot;<br>        instance_type: t2.micro<br>        security_groups:<br>          - &quot;{{ sg.group_id }}&quot;<br>        image_id: ami-0e742cca61fb65051<br>        exact_count: 3<br>        tags:<br>          Project: &quot;{{ project }}&quot;<br>          Env: &quot;{{ env }}&quot;<br>    - name: &quot;ec2 instance details&quot;<br>      amazon.aws.ec2_instance_info:<br>        access_key: &quot;{{ access_key }}&quot;<br>        secret_key: &quot;{{ secret_key }}&quot;<br>        region: &quot;{{ region }}&quot;<br>        filters:<br>          &quot;tag:Name&quot;: &quot;{{ project }}-{{ env }}-webserver&quot;<br>          &quot;tag:Project&quot;: &quot;{{ project }}&quot;<br>          &quot;tag:Env&quot;: &quot;{{ env }}&quot;<br>          instance-state-name: [ &quot;running&quot;]<br>      register: aws_details<br> <br>    - name: &quot;Creating Dynamic Inventory&quot;<br>      add_host:<br>        groups: &quot;web&quot;<br>        hostname: &quot;{{ item.public_ip_address  }}&quot;<br>        ansible_ssh_user: &quot;ec2-user&quot;<br>        ansible_ssh_host: &#39;{{ item.public_ip_address  }}&#39;<br>        ansible_ssh_port: &quot;22&quot;<br>        ansible_ssh_private_key_file: &quot;{{ project }}-{{ env }}.pem&quot;<br>        ansible_ssh_common_args: &quot;-o StrictHostKeyChecking=no&quot;<br>      with_items: &quot;{{ aws_details.instances }}&quot;<br> <br>- name: &quot;Deploying Website&quot;<br>  become: true<br>  hosts: web<br>  serial: 1<br>  vars:<br>    repo_url: &quot;https://github.com/antony-a-n/aws-elb-site.git&quot;<br>    owner: &quot;apache&quot;<br>    group: &quot;apache&quot;<br>    port: &quot;80&quot;<br>    domain: &quot;web.antonyan.tech&quot;<br>    health_check_delay: 50<br>    packges:<br>      - httpd<br>      - php<br>      - git<br>    clone_dir: &quot;/var/git/&quot;<br>  tasks:<br>    - name: &quot;Package Installation&quot;<br>      yum:<br>        name: &quot;{{ packges }}&quot;<br>        state: present<br>      notify:<br>        - apache-reload<br> <br>    - name: &quot;Creating httpd.conf file&quot;<br>      template:<br>        src: ./httpd.conf.tmpl<br>        dest: /etc/httpd/conf/httpd.conf<br>        owner: &quot;{{ owner }}&quot;<br>        group: &quot;{{ group }}&quot;<br>      notify:<br>        - apache-reload<br> <br>    - name: &quot;Creating VirtualHost&quot;<br>      template:<br>        src: &quot;./virtual.conf.tmpl&quot;<br>        dest: &quot;/etc/httpd/conf.d/{{ domain }}.conf&quot;<br>        owner: &quot;{{ owner }}&quot;<br>        group: &quot;{{ group }}&quot;<br>      notify:<br>        - apache-reload<br> <br>    - name: &quot;Creating DocRoot }&quot;<br>      file:<br>        path: &quot;/var/www/html/{{ domain }}&quot;<br>        state: directory<br>        owner: &quot;{{ owner }}&quot;<br>        group: &quot;{{ group }}&quot;<br> <br>    - name: &quot;Creating Clone Directory {{ clone_dir }}&quot;<br>      file:<br>        path: &quot;{{ clone_dir }}&quot;<br>        state: directory<br> <br>    - name: &quot;Cloning Website Contents &quot;<br>      git:<br>        repo: &quot;{{ repo_url }}&quot;<br>        dest: &quot;{{ clone_dir }}&quot;<br>      register: clone_status<br>      notify:<br>        - apache-restart<br> <br>    - name: &quot;Copying Website Files &quot;<br>      when: clone_status.changed<br>      copy:<br>        src: &quot;{{ clone_dir }}&quot;<br>        dest: &quot;/var/www/html/{{domain}}&quot;<br>        remote_src: true<br>      notify:<br>        - apache-restart<br> <br>  handlers:<br>    - name: &quot;apache-reload&quot;<br>      service:<br>        name: httpd<br>        state: reloaded<br>        enabled: true<br>    - name: &quot;apache-restart&quot;<br>      service:<br>        name: httpd<br>        state: restarted<br>        enabled: true</pre><p>Now let’s have a deeper look into our code, before executing please make sure that you have created an IAM user with the required permissions.</p><p>We have configured the access_key and secret_key for the API request on a file named login.yml.Also, we have set the region, project &amp;env as variables.</p><p>In the 1st task, we are creating a key pair required for launching our webserver.</p><p>Once it is created we are saving the private key with a .pem extension.</p><p>After creating the keypair, we need to set up a security group. In this example, we are creating a security group with ports 80,22, and 443 open for ingress. By default, all the egress ports are open.</p><p>Now we can set up our instances, and for that, you have to specify the VPC, region, instance type, Key, security group, AMI id, etc.</p><p>We are launching 3 instances here by using exact_count. You can use normal count here, but the issue is that whenever you run the playbook, it will launch new instances based on the number you have mentioned with the count.</p><p>This can be avoided using exact_count, it is working in hand with filters, we are creating new instances based on a few tags, Whenever you run the playbook again, it will 1st check the no of instances with the mentioned tag. If the no of instances matched the no of counts you have provided with exact_count. If they are the same, it won’t launch a new instance.</p><p>Once you have launched the instances, we have to fetch the details of the newly created instances for setting up the dynamic inventory.</p><p>Then we are filtering the instances based on the tag, we are provided with and register the details of instances.</p><p>After fetching all the details, as the last task we are creating a dynamic inventory for running our second play and it includes the ansible_user, port, key file, etc.</p><p>Now we can execute the 2nd play, the group will be the members of the dynamic inventory.</p><p>In the second play we are launching our website, and for that, we have to specify some variables such as git repo URL, HTTP port, HTTP user, group, etc.</p><p>We need to install a few packages for our setup. Including git, httpd &amp; PHP.</p><p>Once the packages are installed and running, we can finish the rest of our tasks such as changing permissions and configuring httpd.conf, virtualhost file etc.</p><p>We are using template format here.Once the required files are reached the destination server, we can create the document root for cloning our website contents.</p><p>Now we can clone the contents using the git module, from the location, we can move the contents to the document root.</p><p>Since we have setup handlers to reload and restart apache, whenever there is a change in the tasks, the handlers will trigger.</p><p>Also we are executing the playbook in serial mode, so it will perform tasks on a single machine at a time.</p><p>Once the task fully executed, you will be able to access the website .</p><p>Use the following command to run the playbook.</p><pre>ansible-playbook main.yml</pre><p>You can find the <a href="https://github.com/antony-a-n/Setting-up-Wordpress-on-LAMP-and-LEMP-stacks-using-ansible-playbook/blob/main/httpd.conf.tmpl">httpd.conf.tmpl</a> and <a href="https://github.com/antony-a-n/Setting-up-Wordpress-on-LAMP-and-LEMP-stacks-using-ansible-playbook/blob/main/virtual.conf.tmpl">virtual.conf.tmpl</a> from the following github repository.</p><p><a href="https://github.com/antony-a-n/Setting-up-Wordpress-on-LAMP-and-LEMP-stacks-using-ansible-playbook">https://github.com/antony-a-n/Setting-up-Wordpress-on-LAMP-and-LEMP-stacks-using-ansible-playbook</a></p><p>Please have a check and Let me know if you are facing any issues.</p><p>Thank you for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f968eb4831f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Docker image and Deploying container based on GitHub code using ansible-playbook]]></title>
            <link>https://medium.com/@antonyan009/creating-docker-image-and-deploying-container-based-on-github-code-using-ansible-playbook-e15118c464fa?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/e15118c464fa</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Sun, 26 Feb 2023 09:15:26 GMT</pubDate>
            <atom:updated>2023-02-26T09:16:49.962Z</atom:updated>
            <content:encoded><![CDATA[<p>While working on a product&#39;s development stage, you will be checking how the changes in the code are reflected in a live environment.</p><p>If the product is running on a docker container, you must create a new docker image and run a container based on the new image to check the changes, right?</p><p>So here I am trying to create a solution for that, whenever you are making an update to your GitHub code, you only need to run the ansible playbook. It will create a docker image and will push the image to the docker hub And it will create a docker container based on the new image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtK_eJkZiCiM88HS7axQYg.png" /></figure><p>So let’s start.</p><p>Before proceeding please make sure that you have installed ansible on your master machine and that you have the key file (key.pem in this example) with the required permissions. We are using an amazon Linux instance here. Our application is a program to display hello world and it is written in python.</p><p>We need to configure the inventory files with the details of the build and test server details.</p><p>Our inventory file will be like the following.</p><pre>$ cat inventory<br><br>[build]<br>&lt;pri_IP&gt; ansible_user=&quot;ec2-user&quot; ansible_ssh_private_key_file=&quot;key.pem&quot;<br>[test]<br>&lt;pri_IP&gt; ansible_user=&quot;ec2-user&quot; ansible_ssh_private_key_file=&quot;key.pem&quot;</pre><p>Also, we need the docker hub’s details such as username and password for authenticating and pushing images to docker hub.</p><p>We are passing the credentials to the playbook from a file, so we are setting the file as dockervars.yml.</p><pre>$ cat dockervars.yml<br>---<br>username: &quot;enter your dockerhub username&quot;<br>password: &quot;enter your dockerhub password&quot;</pre><p>Now let’s check on the playbook.</p><pre>$ cat git.yml<br>---<br>- name: &quot;deploying docker from git&quot;<br>  hosts: build<br>  become: true<br>  vars_files:<br>    - dockervars.yml<br>  vars:<br>    pkg:<br>      - docker<br>      - git<br>      - pip<br>    url: &quot;https://github.com/antony-a-n/devops-flask.git&quot;<br>    clone: &quot;/var/flaskapp&quot;<br>    img: &quot;antonyanlinux/flask&quot;<br><br>  tasks:<br>    - name: &quot;installing packages&quot;<br>      yum:<br>        name: &quot;{{pkg}}&quot;<br>        state: present<br><br>    - name: &quot;adding user to docker group&quot;<br>      user:<br>        name: &quot;ec2-user&quot;<br>        groups:<br>          - docker<br>        append: true<br><br>    - name: &quot;installing python module&quot;<br>      pip:<br>        name: docker-py<br><br>    - name: &quot;restarting service&quot;<br>      service:<br>        name: docker<br>        state: restarted<br>        enabled: true<br><br>    - name: &quot;creating document-root&quot;<br>      file:<br>        path: &quot;{{clone}}&quot;<br>        state: &quot;directory&quot;<br><br>    - name: &quot;cloning-repo&quot;<br>      git:<br>        repo: &quot;{{url}}&quot;<br>        dest: &quot;{{clone}}&quot;<br>      register: clone_state<br>    - name: &quot;login&quot;<br>      when: clone_state.changed<br>      docker_login:<br>        username: &quot;{{username}}&quot;<br>        password: &quot;{{password}}&quot;<br>        state: present<br><br>    - name: &quot;image building&quot;<br>      when: clone_state.changed<br>      docker_image:<br>        source: build<br>        build:<br>          path: &quot;{{clone}}&quot;<br>          pull: true<br>        name: &quot;{{img}}&quot;<br>        tag: &quot;{{item}}&quot;<br>        push: true<br>        force_tag: true<br>        force_source: true<br>      with_items:<br>        - latest<br>        - &quot;{{clone_state.after}}&quot;<br><br>    - name: &quot;removing local image&quot;<br>      when: clone_state.changed<br>      docker_image:<br>        state: absent<br>        name: &quot;{{img}}&quot;<br>        tag: &quot;{{item}}&quot;<br>      with_items:<br>        - latest<br>        - &quot;{{clone_state.after}}&quot;<br><br>    - name: &quot;logout&quot;<br>      when: clone_state.changed<br>      docker_login:<br>        username: &quot;{{username}}&quot;<br>        password: &quot;{{password}}&quot;<br>        state: absent<br><br>- name: &quot;testing image&quot;<br>  hosts: test<br>  become: true<br>  vars:<br>    test_img: &quot;antonyanlinux/flask&quot;<br>    test_pkg:<br>      - docker<br>      - pip<br><br>  tasks:<br>    - name: &quot;package installation&quot;<br>      yum:<br>        name: &quot;{{test_pkg}}&quot;<br>        state: &quot;present&quot;<br>    - name: &quot;attaching user&quot;<br>      user:<br>        name: &quot;ec2-user&quot;<br>        groups:<br>          - docker<br>        append: true<br><br>    - name: &quot;installing module&quot;<br>      pip:<br>        name: docker-py<br>    - name: &quot;restarting service&quot;<br>      service:<br>        name: docker<br>        state: started<br>        enabled: true<br>    - name: &quot;pulling image&quot;<br>      docker_image:<br>        name: &quot;{{test_img}}&quot;<br>        source: pull<br>        force_source: true<br>      register: image_stat<br><br>    - name: &quot;creating docker container&quot;<br>      when: image_stat.changed<br>      docker_container:<br>        name: flaskdemo<br>        image: &quot;{{test_img}}:latest&quot;<br>        recreate: yes<br>        pull : yes<br>        published_ports:<br>          - &quot;80:5000&quot;</pre><p>We are setting up a few variables such as GitHub repo URL, work directory for the application, and image name.</p><p>We are running this as 2 plays, In the 1st play we are installing the required packages and granting permissions to the ec2-user on docker.</p><p>Once you have added ec2-user to the group, we need to restart the service for reflecting the changes.</p><p>Please note that in order to python work with docker, you need to install a python module.</p><p>Once this is done, we are creating the document root, for the project and we are cloning the git repo to the directory which we have created. we are using the git module here.</p><p>When the repo is cloned, we are ready to build a new docker image, before that we need to access the docker hub for pushing the image. docker_login module can be used here.</p><p>In the next build, we are building the image. build refers that we are building a new image and we are adding the necessary tags to the image.</p><p>Once the image is pushed to the hub successfully we can remove the image from the local machine.</p><p>In the next play, we are repeating the procedures for installing packages, grading permissions, etc, Once this is done, we are pulling the image which was created as a part of the previous play.</p><p>And based on the image we are launching a docker container.</p><p>Now let’s execute the playbook.</p><pre>$ ansible-playbook -i inventory git.yml</pre><pre>$ ansible-playbook -i inventory git.yml<br>[WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line<br>lengths<br><br>PLAY [deploying docker from git] *****<br><br>TASK [Gathering Facts] *****<br><br><br>TASK [installing packages] *****<br>changed: [172.31.34.11]<br><br>TASK [adding user to docker group] *****<br>ok: [172.31.34.11]<br><br>TASK [installing python module] ****<br>ok: [172.31.34.11]<br><br>TASK [restarting service] *****<br>changed: [172.31.34.11]<br><br>TASK [creating document-root] ******<br>changed: [172.31.34.11]<br><br>TASK [cloning-repo] *****<br>changed: [172.31.34.11]<br><br>TASK [login] *******<br>changed: [172.31.34.11]<br><br><br><br>--<br>--<br>--<br>TASK [creating docker container] ******<br><br>PLAY RECAP *****<br>172.31.33.88               : ok=7    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0<br>172.31.34.11               : ok=11   changed=8    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0<br><br></pre><p>Once it is executed successfully, you will be able to view the output from the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yig3djy6XNP8a549FHNq9g.png" /></figure><p>Now let’s change the version to 2 and re-run the playbook.</p><pre>$ ansible-playbook -i inventory git.yml</pre><pre>PLAY RECAP **************<br>172.31.33.88               : ok=7    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0<br>172.31.34.11               : ok=11   changed=6    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0</pre><p>Now you will be able to view the newer version in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R6WM6F3ws5uOx9zga2X1QA.png" /></figure><p>Thank you for reading, if you are facing any issues, feel free to ping on LinkedIn :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e15118c464fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Wordpress on LAMP & LEMP stack using ansible-playbook]]></title>
            <link>https://medium.com/@antonyan009/setting-up-wordpress-on-lamp-lemp-stack-using-a-single-ansible-playbook-7bbf06e6a43d?source=rss-73c89003020------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bbf06e6a43d</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[ANTONY A N]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 20:20:41 GMT</pubDate>
            <atom:updated>2023-02-20T12:14:39.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQvcA_FWqm1675hNAFS-EA.png" /></figure><p>Sometimes you may find difficulties while configuring wordpress on your server, but when you need to do the same on multiple servers with multiple operating systems the process may take more time than expected.<br> <br> by using ansible, you don’t need to worry about this anymore. By running a single playbook you can set up wordpress without any worries.<br> <br> So let’s start.<br> <br> In this example, we are setting up wordpress on an amazon Linux machine &amp; ubuntu machine.<br> <br> So we need 3 servers in our lab environment,<br> 1x master server with ansible installed<br> 2x client servers with ubuntu 20.04 &amp; amazon linux installed.<br> <br> You can install ansible using the following command, assuming your master machine is running on amazon Linux.</p><pre> $ sudo amazon-linux-extras install ansible2 -y</pre><p>Once it is installed, you can check the ansible version by the following command,</p><pre> ansible - version</pre><p>Before proceeding to the playbook we need to configure the inventory file. This file keeps the details of the client machine, which includes the IP address, ansible username, ssh port key file, etc.<br> <br> The following file is an example of what an inventory fike looks like.</p><pre>$ cat inventory.txt<br>[amazon]<br>172.31.44.89 ansible_user=&quot;ec2-user&quot; ansible_port=&quot;22&quot; ansible_ssh_private_key_file=&quot;key.pem&quot;<br>[ubuntu]<br>172.31.34.215 ansible_user=&quot;ubuntu&quot; ansible_port=&quot;22&quot; ansible_ssh_private_key_file=&quot;key.pem&quot;</pre><p>let’s break it out.</p><p>[amazon] defines the name of the group, if you add any hosts to the group, they all will be part of the group, this is useful when you need to run the playbook on a specific group from the inventory file.<br>172.31.44.89 is the IP address of your client machine.<br>since these clients are on the same machine, you can configure them with the private IP address.<br>ansible_user defines the user name for ansible to connect to the server via ssh.<br>ansible_port defines the ssh port of the client machine.<br>ansible_ssh_private_key_file defines the key used to connect to the server.</p><p>You can add multiple servers to a group and you can configure multipl groups in the inventory file.</p><p>Our playbook uses some variables for its execution. Instead of adding the variables in the code, you can define them in a different directory called group_vars,</p><p>If you define the variables in this directory, those values will be assigned to the hosts inside the group. The advantage is that you can assign different values for the same variables for different groups,</p><p>To set up this you need to create a directory called group_vars in the master machine. inside the directory, you can create files for specifying the variables and values, in our playbook we are setting up wordpress on LAMp &amp; LEMP stack, so the values to the variables are different. If you specify them in group_vars, they will fetch the values from this file.</p><p>Please note that group_vars follows YAML format, so you need to add — — — at the top of your file.</p><p>The files will be like the following.</p><pre>$ cat group_vars/amazon<br>---<br>port: &quot;8080&quot;<br>owner: &quot;apache&quot;<br>group: &quot;apache&quot;<br>domain: &quot;example.com&quot;<br>mysql_root_password: &quot;mysqlroot@123456&quot;<br>mysql_db: &quot;wordpress&quot;<br>mysql_user: &quot;wordpress&quot;<br>mysql_password: &quot;wordpress@123&quot;<br>wp_url: &quot;https://wordpress.org/wordpress-6.1.1.tar.gz&quot;</pre><pre>$ cat group_vars/ubuntu<br>---<br>port: &quot;8080&quot;<br>owner: &quot;www-data&quot;<br>group: &quot;www-data&quot;<br>domain: &quot;example.com&quot;<br>mysql_root_password: &quot;mysqlroot@123456&quot;<br>mysql_db: &quot;wordpress&quot;<br>mysql_user: &quot;wordpress&quot;<br>mysql_password: &quot;wordpress@123&quot;<br>wp_url: &quot;https://wordpress.org/wordpress-6.1.1.tar.gz&quot;</pre><p>while comparing the files, you can see that the same variables are assigned different values.<br>the port defines the port number.<br>owner defines the owner of the website files, In amazon Linux the owner is apache and in ubuntu, it is www-data, the same values are applicable for group too,<br>domain defines the domain name, in our example, it is example.com<br>mysql_root_password used to specify the root password for our MySQL server.<br>mysql_db defines the database base for our wordpress website and mysql_user defines the wordpress user.<br>wp_url defines the wordpress tar file, which will be used in the wordpress installation.</p><p>As you know, we need to make a few changes to files such as wp-config.php, virtual host file to setting up wordpress, so we are copying modified versions of these files to the servers using the template feature,</p><p>Since we mentioned a few variables in the code, they must be replaced with the corresponding values while copying to the client servers.</p><p>Using the template, we can perform the above-mentioned operation, it will replace the variables with their corresponding values.</p><p>For setting up wordpress on our LAMP stack, we need to copy the following files.</p><p>httpd.conf<br>wp-config.php<br>virtual host</p><p>the extension for these files must be either .tmpl or .j2, in our example, we are using .tmpl format.</p><p>Let’s check on these files.</p><p>httpd.conf — it is the default configuration file of the apache webserver, we are only modifying a small portion, the listen port will be replaced by our “port” variable.</p><pre>$ cat httpd.conf.tmpl | grep port<br><br>Listen &quot;{{port}}&quot;</pre><p>This is the change that we mentioned earlier, the rest of the file will be the same while executing the playbook, the port will be replaced with the corresponding value, in our example, it will be 8080.</p><p>In the wp-config.php file, we are providing the database details as variables, so the database section of the wp-config file will be the following.</p><pre>$ cat wp-config.php.tmpl |DB<br><br>define( &#39;DB_NAME&#39;, &#39;{{mysql_db}}&#39; );<br>define( &#39;DB_USER&#39;, &#39;{{mysql_user}}&#39; );<br>define( &#39;DB_PASSWORD&#39;, &#39;{{mysql_password}}&#39; );<br>define( &#39;DB_HOST&#39;, &#39;localhost&#39; );<br>define( &#39;DB_CHARSET&#39;, &#39;utf8&#39; );<br>define( &#39;DB_COLLATE&#39;, &#39;&#39; );</pre><p>virtual.conf.tmpl defines the virtual host entry for our website.</p><pre>$ cat virtual.conf.tmpl<br><br>&lt;virtualhost *:{{ port }}&gt;<br>  servername {{ domain }}<br>  documentroot /var/www/html/{{ domain }}<br>  directoryindex index.html index.php<br>  &lt;directory &quot;/var/www/html/{{ domain }} &quot;&gt;<br>    allowoverride all<br>  &lt;/directory&gt;<br><br>&lt;/virtualhost&gt;</pre><p>Now regarding the LEMP stack, there are some changes, the wp-config.php.tmpl will remain the same.</p><p>the virtual host entry will be like the following.</p><pre>$ cat nginx-virtualhost.tmpl<br><br>server {<br>listen &quot;{{port}}&quot;;<br>root &quot;/var/www/{{domain}}&quot;;<br>index index.php index.html index.htm;<br>server_name &quot;{{domain}}&quot;;<br>location / {<br>try_files $uri $uri/ =404;<br>}<br>location ~ \.php$ {<br>        include snippets/fastcgi-php.conf;<br>        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;<br>     }<br>}</pre><p>Now let’s proceed with our playbook, in our playbook we are performing the actions are tasks, since the tasks/actions for different operations systems are different, we are adding the tasks using the include_tasks option.</p><p>it is a very useful feature while writing a playbook with more tasks.</p><p>Let’s check on the tasks for Amazon-Linux for setting up the LAMP stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*pC2QNk7E2yeRIC5x6DkJvA.png" /></figure><pre>$cat amazon.yml<br><br>---<br>    - name: &quot;installing apache&quot;<br>      yum:<br>        name: httpd<br>        state: present<br>      tags:<br>        - lamp<br><br>    - name: &quot;installing php&quot;<br>      shell: amazon-linux-extras install php7.4 -y<br>      tags:<br>        - lamp<br><br>    - name: &quot;copying httpd.config&quot;<br>      template:<br>        src: ./httpd.conf.tmpl<br>        dest: /etc/httpd/conf/httpd.conf<br>      tags:<br>        - lamp<br>        - wordpress<br><br>    - name: &quot;creating virtual host&quot;<br>      template:<br>        src: &quot;./virtual.conf.tmpl&quot;<br>        dest: &quot;/etc/httpd/conf.d/{{domain}}.conf&quot;<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>      tags:<br>        - lamp<br>        - wordpress<br>    - name: &quot;creating document root&quot;<br>      file:<br>        path: &quot;/var/www/html/{{domain}}&quot;<br>        state: directory<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>      tags:<br>        - lamp<br><br>    - name: &quot;creating sample files&quot;<br>       copy:<br>        src: &quot;{{item}}&quot;<br>        dest: &quot;/var/www/html/{{domain}}/&quot;<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>      with_items:<br>        - sample.php<br>        - sample.html<br>      tags:<br>        - lamp<br>        - wordpress<br><br>    - name: &quot;installing mariadb package&quot;<br>      yum:<br>        name:<br>          - mariadb-server<br>          - MySQL-python<br>        state: present<br>      tags:<br>        - lamp<br>        - wordpress<br>        - mariadb<br>    - name: &quot;restarting service&quot;<br>      service:<br>        name: mariadb<br>        state: restarted<br>        enabled: true<br>      tags:<br>        - mariadb<br>        - wordpress<br>        - lamp<br>    - name: &quot;updating root password&quot;<br>      ignore_errors: true<br>      mysql_user:<br>        login_user: &quot;root&quot;<br>        login_password: &quot;&quot;<br>        name: &quot;root&quot;<br>        password: &quot;{{mysql_root_password}}&quot;<br>        host_all : true<br>      tags:<br>        - lamp<br>        - wordpress<br>        - mariadb<br><br>    - name: &quot;removing anonymous users&quot;<br>      mysql_user:<br>        login_user: &quot;root&quot;<br>        login_password: &quot;{{mysql_root_password}}&quot;<br>        name: &quot;&quot;<br>        password: &quot;&quot;<br>        host_all: true<br>        state: absent<br>      tags:<br>       - wordpress<br>       - lamp<br>       - mariadb<br><br>    - name: &quot;creating database&quot;<br>      mysql_db:<br>        login_user: &quot;root&quot;<br>        login_password: &quot;{{mysql_root_password}}&quot;<br>        name: &quot;{{mysql_db}}&quot;<br>        state: present<br>      tags:<br>        - lamp<br>        - wordpress<br>        - mariadb<br>    - name: &quot;creating user&quot;<br>      mysql_user:<br>        login_user: &quot;root&quot;<br>        login_password: &quot;{{mysql_root_password}}&quot;<br>        name: &quot;{{mysql_user}}&quot;<br>        password: &quot;{{mysql_password}}&quot;<br>        state: present<br>        host: &quot;%&quot;<br>        priv: &quot;{{mysql_db}}.*:ALL&quot;<br>      tags:<br>       - wordpress<br>       - mariadb<br>       - lamp<br><br>    - name: &quot;downloading wordpress files&quot;<br>      get_url:<br>        url: &quot;{{wp_url}}&quot;<br>        dest: &quot;/tmp/wordpress.tar.gz&quot;<br>      tags:<br>        - wordpress<br>        - lamp<br>        - mariadb<br>    - name: &quot;extracting files&quot;<br>      unarchive:<br>        src: &quot;/tmp/wordpress.tar.gz&quot;<br>        dest: &quot;/tmp/&quot;<br>        remote_src: true<br>      tags:<br>        - lamp<br>        - mariadb<br>        - wordpress<br>    - name: &quot;copying website files&quot;<br>      copy:<br>        src: &quot;/tmp/wordpress/&quot;<br>        dest: &quot;/var/www/html/{{domain}}&quot;<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>        remote_src: yes<br>    - name: &quot;setting up wp-config&quot;<br>      template:<br>        src: ./wp-config.php.tmpl<br>        dest: &quot;/var/www/html/{{domain}}/wp-config.php&quot;<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>    - name: &quot;restarting services&quot;<br>      service:<br>        name: &quot;{{item}}&quot;<br>        state: restarted<br>        enabled: true<br>      with_items:<br>        - httpd<br>        - mariadb<br>      tags:<br>        - httpd<br>        - mariadb<br>    - name: &quot;cleanup&quot;<br>      file:<br>        name: &quot;{{item}}&quot;<br>        state: absent<br>      with_items:<br>        - &quot;/tmp/wordpress/&quot;<br>        - &quot;/tmp/wordpress.tar.gz&quot;<br>      tags:<br>        - Wordpress</pre><p>Let’s have a closer look at the tasks.</p><p>task1 — installation of httpd using yum module<br>task2 — installation of php7.4 using shell module<br>task3 — copying of httpd.conf the updated httpd.conf will be replaced with the default httpd conf.<br>task4 — setting up the virtual host<br>task6 — creating document root for the website. (/var/www/html/example.com)<br>task 7 — copying 2 sample files called sample.html and sample.php for checking the php and apache installation status<br>task 8 — MySQL installation<br>task 9 — restarting MySQL service<br>task 9 — updating the root password of the MySQL server (using the mysql_user module)<br>task 10 — removing anonymous users from MySQL<br>task 11 — creating a database for setting up wordpress (using the mysql_db module)<br>task 12 — creating a wordpress user and granting required privileges.<br>task 13- downloading wordpress files using wget (get_url is used for wget)<br>task 14- extracting wordpress files to /tmp<br>task 15- copying websites files to document root and updating ownership<br>task 16 — setting up wp-config in the document root.<br>task 17- restarting services (apache, MySQL)<br>task 18 — removing unwanted files.</p><p>Now let’s check the tasks for the LEMP stack on the ubuntu server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*jrfg0Bl0m0TJnyMvKJUGzg.png" /></figure><pre>$ cat ubuntu.yml<br><br>---<br>    - name: &quot;installing nginx&quot;<br>      apt:<br>        update_cache: true<br>        name: nginx<br>        state: present<br>      tags:<br>        - lamp<br><br>    - name: &quot;installing php&quot;<br>      apt:<br>        name:<br>          - php-mysql<br>          - php-fpm<br>        update_cache: true<br>        state: present<br>      tags:<br>        - lamp<br><br>    - name: &quot;creating virtual host&quot;<br>      template:<br>        src: &quot;./nginx-virtualhost.tmpl&quot;<br>        dest: &quot;/etc/nginx/sites-available/{{domain}}&quot;<br>      tags:<br>        - lamp<br>        - wordpress<br>    - name: &quot;creating document root&quot;<br>      file:<br>        path: &quot;/var/www/{{domain}}&quot;<br>        state: directory<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>      tags:<br>        - lamp<br><br>    - name: &quot;creating sample files&quot;<br>      copy:<br>        src: &quot;{{item}}&quot;<br>        dest: &quot;/var/www/{{domain}}/&quot;<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>        with_items:<br>        - sample.php<br>        - sample.html<br>      tags:<br>        - lamp<br>        - wordpress<br><br>    - name: &quot;link&quot;<br>      file:<br>        src: &quot;/etc/nginx/sites-available/{{domain}}&quot;<br>        dest: &quot;/etc/nginx/sites-enabled/{{domain}}&quot;<br>        state: link<br><br>    - name: &quot;installing mysql package&quot;<br>      apt:<br>        update_cache: true<br>        name:<br>          - mariadb-server<br>          - python3-pymysql<br>        state: present<br><br>    - name: &quot;updating root password&quot;<br>      ignore_errors: true<br>      mysql_user:<br>        login_unix_socket: /var/run/mysqld/mysqld.sock<br>        login_user: &quot;root&quot;<br>        login_password: &quot;&quot;<br>        name: &quot;root&quot;<br>        password: &quot;{{mysql_root_password}}&quot;<br>        host_all : true<br>      tags:<br>        - lamp<br>        - wordpress<br>        - mariadb<br><br>    - name: &quot;removing anonymous users&quot;<br>      mysql_user:<br>        login_user: &quot;root&quot;<br>        login_password: &quot;{{mysql_root_password}}&quot;<br>        name: &quot;&quot;<br>        password: &quot;&quot;<br>        host_all: true<br>        state: absent<br>         tags:<br>       - wordpress<br>       - lamp<br>       - mariadb<br><br>    - name: &quot;creating database&quot;<br>      mysql_db:<br>        login_user: &quot;root&quot;<br>        login_password: &quot;{{mysql_root_password}}&quot;<br>        name: &quot;{{mysql_db}}&quot;<br>        state: present<br>      tags:<br>        - lamp<br>        - wordpress<br>        - mariadb<br>    - name: &quot;creating user&quot;<br>      mysql_user:<br>        login_user: &quot;root&quot;<br>        login_password: &quot;{{mysql_root_password}}&quot;<br>        name: &quot;{{mysql_user}}&quot;<br>        password: &quot;{{mysql_password}}&quot;<br>        state: present<br>        host: &quot;%&quot;<br>        priv: &quot;{{mysql_db}}.*:ALL&quot;<br>      tags:<br>        - wordpress<br>        - mariadb<br>        - lamp<br><br>    - name: &quot;downloading wordpress files&quot;<br>      get_url:<br>        url: &quot;{{wp_url}}&quot;<br>        dest: &quot;/tmp/wordpress.tar.gz&quot;<br>      tags:<br>        - wordpress<br>        - lamp<br>        - mariadb<br>    - name: &quot;extracting files&quot;<br>      unarchive:<br>        src: &quot;/tmp/wordpress.tar.gz&quot;<br>        dest: &quot;/tmp/&quot;<br>        remote_src: true<br>      tags:<br>        - lamp<br>        - mariadb<br>        - wordpress<br>    - name: &quot;copying website files&quot;<br>      copy:<br>        src: &quot;/tmp/wordpress/&quot;<br>        dest: &quot;/var/www/{{domain}}&quot;<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>        remote_src: yes<br>    - name: &quot;setting up wp-config&quot;<br>      template:<br>        src: ./wp-config.php.tmpl<br>        dest: &quot;/var/www/{{domain}}/wp-config.php&quot;<br>        owner: &quot;{{owner}}&quot;<br>        group: &quot;{{group}}&quot;<br>    - name: &quot;restarting services&quot;<br>      service:<br>        name: &quot;{{item}}&quot;<br>        state: restarted<br>        enabled: true<br>      with_items:<br>        - nginx<br>        - mariadb<br>      tags:<br>        - nginx<br>        - mysql<br>    - name: &quot;cleanup&quot;<br>      file:<br>        name: &quot;{{item}}&quot;<br>        state: absent<br>      with_items:<br>        - &quot;/tmp/wordpress/&quot;<br>        - &quot;/tmp/wordpress.tar.gz&quot;<br>      tags:<br>         - Wordpress</pre><p>The tasks are almost similar here, but there are a few changes.</p><p>Task1 — installing nginx using apt module<br>task3 — creating virtual host in the folder /etc/nginx/sites-available<br>task6 — creating symlink (to sites-enabled)</p><p>All other tasks are similar to LAMP stack installation.</p><p>By using the feature of include_tasks, you are able to run tasks that are written in different files., Which makes the codes easy to manage.</p><p>Also, we are setting up a few conditions for executing the right file, In our example, the playbook fetches the os family and package manager of the client machines from facts gathering and it will execute the playbook based on the result.</p><p>Now let’s have a look at the playbook.</p><p>Please note that the playbooks are using the YAML format.</p><pre>$ cat main.yml<br><br>---<br><br>- name: &quot;wordpress installation&quot;<br>  become: yes<br>  gather_facts: true<br>  hosts: amazon, ubuntu<br><br>  tasks:<br><br>    - include_tasks: &quot;amazon.yml&quot;<br>      when: ansible_distribution == &quot;Amazon&quot; and ansible_pkg_mgr == &quot;yum&quot;<br><br>    - include_tasks: &quot;ubuntu.yml&quot;<br>      when: ansible_distribution == &quot;Ubuntu&quot; and ansible_pkg_mgr == &quot;apt&quot;</pre><p>In this code, you can see that our subcodes amazon.yml and ubuntu.yml as include_tasks. These tasks will be executed when the mentioned condition is satisfied.</p><p>As mentioned before we are fetching the values of ansible_distribution &amp; ansible_pkg_mgr from the setup module, so we are keeping the gather_facts as enabled.</p><p>In order to install packages on the server, you need to have sudo privileges. so we are setting up privilege escalation to true, so the commands will be executed with sudo privileges.</p><p>hosts define the groups to which the code needs to be applied.</p><p>Now let’s proceed with executing the playbook, before that please make sure that there are no syntax errors in the code.</p><p>You can verify the same using the following command.</p><pre>$ ansible-playbook -i inventory.txt main.yml - syntax-check<br>playbook:main.yml</pre><p>If you are getting an output like the above, the code is error-free.</p><p>Now, let’s execute the codes.</p><pre><br>$ ansible-playbook -i inventory.txt main.yml </pre><p>Once it is executed successfully, you can visit the browser and set up wordpress.</p><p>Conclusion<br> — — — — — -<br>As already mentioned earlier, you can easily perform wordpress installation on servers regardless of the number of servers using ansible playbook.</p><p>I hope this document was able to provide a clearcut idea about deploying wordpress on servers using the ansible playbook.</p><p>If you are facing any difficulties or have any doubts, feel free to contact me via LinkedIn.</p><p>Thanks for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bbf06e6a43d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>