How to configure multiple environments with Ansible Automation Platform

🦾 Introduction to environment configuration with Ansible Automation Platform

🔗Related content

You can find repo related in:

🐱‍🏍GitHub

You can connect with me in:

🧬LinkedIn

Resume 🧾

🚀 Ansi…


This content originally appeared on DEV Community and was authored by Lucas M. Ríos

🦾 Introduction to environment configuration with Ansible Automation Platform

🔗Related content

You can find repo related in:

🐱‍🏍GitHub

You can connect with me in:

🧬LinkedIn

Resume 🧾

🚀 Ansible is a powerful configuration management tool that can be used for provisioning infrastructure.

🛠️ Provisioning refers to the process of configuring and setting up remote systems or infrastructure.

📝 Ansible uses Playbooks, which are written in YAML format, to define the desired state of the infrastructure.

📦 Ansible provides many built-in modules for performing provisioning tasks, such as installing packages, configuring network settings, managing users and groups, and more.

Glosary

AAP: Ansible Automation Platform

Introduction

Supose you have an app and need deploy it in three or more enviornment with specific configuration.

Imagine deploy manually all application included configuration is easy and manageble, but in a small organization will have a minimum of ten applications this is tedious but managable configurate in each server.

Now think in twenty applications this is simply unimaginable manage fast and apply configuration correctly.

In my last time, I have worked a lot with Ansible using AAP and solved many problems in deploying and updating applications.

Other times we don't make mistakes just simply the server doesn't have infrastructure settings appropriately.

What we need to fix all of that?

We will use a function called renderize.

  1. I want belive you have this step.
    We need use good practices of development and understand holisticly all system. Included code, data bases, server, settings...

  2. Create a repo with app. I calling app to code.
    Supose this is called as "repo-app".

  3. Create a repo with configuration values by each environment.
    Supose this is called as "repo-config".

  4. Create a repo with ansible code configuration.
    Supose this is called as "repo-ansible".

What we need make in repo-app?

In files where exists configuration specific of each environment like database of develop, qa and master; or values to configure Auth0.
Files can has any format, i.e: json, yaml, xml, etc.

We will write files where:

# appsetings.json
{
  "API": {
    "Endpoint": "**Endpoint-develop**"
  },
  "reCaptcha": {
    "SiteKey": "**SiteKey-develop**",
    "SecretKey": "**SecretKey-develop**",
    "Score": **Score-develop**,
  },  
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

Insted set values set { { NAME_VARIABLE } }, key squares need are join:

# appsetings.json
{
  "API": {
    "Endpoint": "{ { Client.Endpoint } }"
  },
  "reCaptcha": {
    "SiteKey": "{ { Client.SiteKey } }",
    "SecretKey": "{ { Client.SecretKey } }",
    "Score": { { Client.Score } },
  },  
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

What we need make in repo-config?

WARNING: This repo is special, so stay focus. We don't make merge or promote between branchs. We work with each branch as independent.

In my case I use a file in format yaml to set values of configurations.

Here we set values and this values will appear in server where will be app and values where we configurate with { { NAME_VARIABLE } }:

---
# appsetings.yaml
Client:
  Endpoint: Endpoint-develop
  SiteKey: SiteKey-develop
  SecretKey: SecretKey-develop
  Score: Score-develop

In qa:
Insted set values set { { NAME_VARIABLE } }:

---
# appsetings.yaml
Client:
  Endpoint: Endpoint-qa
  SiteKey: SiteKey-qa
  SecretKey: SecretKey-qa
  Score: Score-qa

In master:

---
# appsetings.yaml
Client:
  Endpoint: Endpoint-master
  SiteKey: SiteKey-master
  SecretKey: SecretKey-master
  Score: Score-master

Here you can put some secrets encrypted with vault and later this will be renderize with AAP credentials.

And other file with origin and destination of files to renderize:

---
# templates.yaml
templates:
  - origin: { { local_path } }/appsettings.json
    dest: { { dest_path } }/appsettings.json

And add many origin and dest for files to set values in your server.

What we need make in repo-ansible?

Usually we will have a repo with only a branch that will be used.

The tasks we need use to renderize app are:
Note: Imagine we use group vars.

---
# renderize.yaml
- name: Download app
  git:
    repo: "https://{ { repos.app.url } }"
    dest: "{ { repos.app.dir } }"
    version: "{ { repos.app.branch } }"
    force: no
  delegate_to: localhost
  run_once: true

- name: Download config
  git:
    repo: "https://{ { repos.config.url } }"
    dest: "{ { repos.config.dir } }"
    version: "{ { repos.config.branch } }"
    force: no
  delegate_to: localhost
  run_once: true

# TO WINDOWS
- name: Renderize templates in windows
  win_template:
    src: "{ { repos.app.dir } }/{ { item.origin } }"
    dest: "{ { item.dest } }"
  loop: "{ { templates } }"

# TO LINUX
- name: Renderize templates in linux
  template:
    src: "{ { repos.app.dir } }/{ { item.origin } }"
    dest: "{ { item.dest } }"
  loop: "{ { templates } }"

Say thanks, give like and share if this has been of help/interest 😁🖖


This content originally appeared on DEV Community and was authored by Lucas M. Ríos


Print Share Comment Cite Upload Translate Updates
APA

Lucas M. Ríos | Sciencx (2023-04-02T20:28:48+00:00) How to configure multiple environments with Ansible Automation Platform. Retrieved from https://www.scien.cx/2023/04/02/how-to-configure-multiple-environments-with-ansible-automation-platform/

MLA
" » How to configure multiple environments with Ansible Automation Platform." Lucas M. Ríos | Sciencx - Sunday April 2, 2023, https://www.scien.cx/2023/04/02/how-to-configure-multiple-environments-with-ansible-automation-platform/
HARVARD
Lucas M. Ríos | Sciencx Sunday April 2, 2023 » How to configure multiple environments with Ansible Automation Platform., viewed ,<https://www.scien.cx/2023/04/02/how-to-configure-multiple-environments-with-ansible-automation-platform/>
VANCOUVER
Lucas M. Ríos | Sciencx - » How to configure multiple environments with Ansible Automation Platform. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/04/02/how-to-configure-multiple-environments-with-ansible-automation-platform/
CHICAGO
" » How to configure multiple environments with Ansible Automation Platform." Lucas M. Ríos | Sciencx - Accessed . https://www.scien.cx/2023/04/02/how-to-configure-multiple-environments-with-ansible-automation-platform/
IEEE
" » How to configure multiple environments with Ansible Automation Platform." Lucas M. Ríos | Sciencx [Online]. Available: https://www.scien.cx/2023/04/02/how-to-configure-multiple-environments-with-ansible-automation-platform/. [Accessed: ]
rf:citation
» How to configure multiple environments with Ansible Automation Platform | Lucas M. Ríos | Sciencx | https://www.scien.cx/2023/04/02/how-to-configure-multiple-environments-with-ansible-automation-platform/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.