Try   HackMD

Ansible, Terraform and your first infrastructure

research devops provisioning aws ansible terraform

Hello @everyone, how is this going ? Today, on this blog i happily for exprience with AWS cloud and work with it, So go check and provisioning with me about Terraform, Ansible and AWS

Introduce something interesting about AWS, Terraform and Ansible
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More β†’

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More β†’

  • Terraform and ansible is ones of the best ever tools, which i have to used for my work. That is do the incredible things and jobs, so DevOps and SysOps maybe need to learning and applied this involve into work, best kind ever
  • So with Terraform, It is kind of IaC platform and you can look more thing about detailing of it in this blog
  • But Ansible, Is it the same as like Terraform or not ? That will be many type of questions about that. So with me Ansible, like IaC tools - "absolutely sure" but that more kind than this, with Ansible you can do setup one or more machine in onetime remotely just with your code, If compare with Terraform that will not equivalent because it do such different, so how is that it different, Go to more detail in below. Suppercool
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More β†’

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More β†’
  • And yeah, Go to pro with AWS is incredible thing which everyone in this industry will and should learn about that. AWS is the one of biggest platforms about Cloud, AWS is the best way for you service like secure, fastly, safety, easily to use, …
  • So how to combine three to one, you will learn this in downbelow, that need to understand with 2 of IaC, How you can setup your service in AWS.

Behind this blog
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More β†’

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More β†’

So with blog, i will share about how to use Ansible and Terraform for making the basically infrastructure in AWS. How it can connection and what kind of difficult which you meet and how to resolve that.

Step to setup
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More β†’

Prequirement before you go

  • WSL or Linux Environmnement for Running (Ansible Compile Error in Windows Machine)

  • Machine need python3 and pip3 installed before installing Ansible tools

  • Install Ansible for your machine to running the process referenced with Ansible. Just with pip3 install ansible ansible-lint

  • Install aws-cli for purpose connect your ansible with AWS Cloud via this secret things

    ​​​​​​  #!/bin/bash
    ​​​​​​  curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
    ​​​​​​  unzip awscliv2.zip
    ​​​​​​  sudo ./aws/install
    
  • Feel free your requirements when installing ansible pluggin via ansible-galaxy, that will be provided you many pluggins for multiple purpose of provisioning and managing cloud resources by ansible.

  • You need to having AWS account - Free tier for example. With free-tier, you just need to have credit or debit card with 1$ to verify and you will have it. Go check detail about the free tier on this link

  • Optionally, you can configure some extensions for easily working with ansible on VSCode - IDK another have include or not !

    • redhat.ansible –> That things for detection with you what pluggin work with
    • ansible-lint –> You can also download ansible-lint by pip3 install ansible-lint

Go to detail and analysis what you want

If you complete the list of work above, you are ready to go this step. Free free and try

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More β†’

  1. Create your aws token and access key - Try for find the bestway to verify your account with Ansible - Important.
    Link: Creating access keys for the root user - This is not recommended
  • Fistly, you need to calm mind for doing this job. Because it will not protected your account, but also that easily step for doing such thing with AWS. But have more way you can verify that. Find more than in these link:

  • Secondly, the topic is not diggest inside the aws cloud, but you need to remmembering about doing not to expose your credentials to another. That is not secure for your account - remmember that. Try the best way for suitable with your situation.

  1. So if you got aws verify and connect your aws-cli or ansible with your AWS, the after step is more easily, you just need write a code and applied that.
    Link: Ansible Concept
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More β†’
  • With ansible, you will have something which need to familar with
    • playbook : This is the file which you put the step of your job and task inside for doing that for local or remote machine
    • inventory: This is folder which you can put your hosts file inside , which your define what IP address of remote PC need to be configuration (IDK to much about right construct of Ansible Project
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More β†’
      ). But some how ever you can put the ansible var file where you define multiple varible for each of machine.
    • ansible.cfg: This is file which you give a configuration for your ansible, this will help you ignore something annoy warning, accesslist import modules, … Give a short time to take at this
      Image Not Showing Possible Reasons
      • The image was uploaded to a note which you don't have access to
      • The note which the image was originally uploaded to has been deleted
      Learn More β†’
  • So all that is basically things which you meet them in first time have work with Ansible. Try to find your best version of folder to doing multiple work and configuration with high and performance control
  • Go on the disgest of what the Ansible doing in this project. That kind a simple like include both Ansible and Terraform for working with. Ansible will responsibility for doing the configuration and interact with Terraform inside Runner - Make a runner for ansible in AWS
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More β†’

Source: One-click environment creation with Terraform & Ansible in under 10' - On The Cloud Kostas Gkountakos

  • Ansible have role like 3th party tools, it will do twice job:

    • Provisioning itself, ansible-runner in AWS Cloud and you can connect it directly with Authentication SSH Key. Ideally, When you doing that job you will control and plan for setting up your pipeline CI/CD easier than do it with Terraform.
    • Ansible will not have mission to provision the cloud, So you can interact with Terraform via Terraform install inside Ansible by copy contents terraform and upgrade that into VM and perform the Terraform workflow.
  • Terraform have role work with provision tool (IaC) for provisioning infrastructure with AWS provider
  1. This is how full infromation about script, you can double check and find the way to best applied for your choice.
    You can find more ever about me and repo in this
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More β†’
    link github

Ansible:

  • Ansible will have options create - destroy runner, that is median thing will connect you and aws cloud, so go through and check it

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More β†’
    ec2-folder

    ​​​​​​  Command: ansible-playbook <which_ansible_file_you_want> \
    ​​​​​​                  --tags <which_tag_you_want_to_choice>
    ​​​​​​  Tags (Just need only for create Runner):
    ​​​​​​      1. create-ssh-key: Create ssh key with name default or pass for it
    ​​​​​​      2. create-runner: Create Ansible-Runner in cloud using the t2.micro image
    ​​​​​​      3. view-runner: View and upgrade host for run teraform inside that
    
  • terraform-runner-folder will have options for you install and copy content for terraform and run terraform flow to working with

    ​​​​​​   command: ansible-playbook terraform.yaml --extra-vars <key>=<value> --tags <which_tag_you_want_to_choice>
    
    ​​​​​​  Tags:
    ​​​​​​      1. install-terraform: For install terraform tool for Ansible-Runner
    ​​​​​​      2. copy_content: Copy content from local terraform into remove with sync configuration
    ​​​​​​      3. terraform_init_plan: Init and view plan state of terraform before applied (Need --extra-vars)
    ​​​​​​      4. terraform_apply: applied what terraform plan return (Need --extra-vars)
    ​​​​​​      5. terraform_display_destroy: Init and view plan state of destroy process will be occured after destruction (Need --extra-vars)
    ​​​​​​      6. terraform_destroy: Destroy process with destroy plan (Need --extra-vars)
    

Terraform (This is include in Ansible - Try that for manual if you just only want to use individually):

  • So with terraform be come easily to run, just go to right env and applied terraform work flow

  • With create or update for your infrastructure

    ​​​​​​  1. terraform init or terraform init --reconfigure (if you want to make sure with new configure which new update like upgrade provider version, ...)
    ​​​​​​  2. terraform plan
    ​​​​​​  3. terraform apply -auto-approve
    
  • With destroy for your infrastructure

    ​​​​​​  1. terraform init or terraform init --reconfigure (if you want to make sure with new configure which new update likes upgrade provider version, ...) 
    ​​​​​​  2. terraform plan -destroy
    ​​​​​​  3. terraform destroy -auto-approve
    

Your first infrastructure after the provisioning will be

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More β†’

Conclusion

  • I hope so this new is perfectly for your start with AWS, Ansible and Terraform. Maybe this tool can be your first choice on your career, so hangon and moving to learning more about that
  • This is basically for your knowledge about AWS cloud, so the hard thing will difficultly to exposure with a first biggest cloud and find hardy way to secure that. Difficult but fun
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More β†’