Infrastructure as code is current trend in software development model. This helps to maintain consistency in infrastructure and allows to track changes incorporated in infrastructure over a period.
2. Infrastructure as Code is the practice of describing all software
runtime environment and networking settings and parameters in
simple textual format, that can be stored in your Version Control
System (VCS) and versioned on request.
These text files are called manifests and are used by DevOps
tools like Terraform and Kubernetes to automatically provision
and configure build servers, testing, staging and production
environments.
Most importantly, all these operations are traceable through the
VCS, which ensures the removal of decades-old “works fine on
my computer” problem, where the code that worked in testing
does not work in production.
IaC ensures continuity, as all the environments are provisioned
and configured automatically, with no room for human error,
3. Example for ec2 instance
Resources:
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-063dd30adbb186909 #
Amazon Linux AMI in N.California
Tags:
- Key: Name
4. Resources:
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-063dd30adbb186909 #
Amazon Linux AMI in N.California
UserData:
'Fn::Base64':
6. Why IaC
A long time ago, in a data center, every server,
every route table entry, every database
configuration, and every load balancer was
created and managed by hand.
It was a dark and fearful age: fear of downtime,
fear of accidental misconfiguration, fear of slow
and fragile deployments, and fear of what would
happen if the sysadmins fell to the dark side
(i.e. took a vacation).
7. Deployment
‘Deployment’ is the process of putting a new application, or new
version of an application, onto a prepared application server.
As per developer, it may also mean the process of preparing the
server, perhaps by installing libraries or daemons
8. Provisioning
The word ‘Provisioning’ is normally used by Ops folks to refer to
getting computers or virtual hosts to use, and installing needed
libraries or services on them.
Infrastructure as code (IaC) is the process of managing and
provisioning computer data centers through machine-readable
definition files, rather than physical hardware configuration or
interactive configuration tools. Infrastructure as Code (IaC) is
the management of infrastructure
9. Orchestration
Orchestration means arranging or coordinating multiple
systems. It’s also used to mean “running the same tasks on a
bunch of servers at once, but not necessarily all of them.”
10. Config Management is part of provisioning.
Basically, that’s using a tool like Chef, Puppet or
Ansible to configure our server.
“Provisioning” often implies it’s the first time we
do it.
Config management usually happens
repeatedly.
Configuration management (CM) is a systems
engineering process forestablishing and
maintaining consistency of a product’s
11. The primary benefit of configuration management is consistency
of systems and software.
we no longer guess or hope that a configuration is current. It is
correct because the configuration management system ensures
that it is correct.When combined with automation, configuration
management can improve efficiency because manual
configuration processes are replaced with automated
processes.
Chef, Puppet, Ansible, and SaltStack are all configuration
management tools, which means they are designed to install
and manage software on existing servers.
12. Configuration Orchestration and
Configuration Management
The first thing that should be clarified is the difference between
“configuration orchestration” and “configuration management”
tools, both of which are considered IaC tools and are included
on this list.
Configuration orchestration tools, which include Terraform and
AWS CloudFormation, are designed to automate the
deployment of servers and other infrastructure.
Configuration management tools like Chef, Puppet, and the
others on this list help configure the software and systems on
this infrastructure that has already been provisioned.
14. So we are talking about IT orchestration where
tasks are run in sequence in several different
machines or servers.
Ansible does this by connecting to multiple
machines through SSH and runs the tasks
which have been configured into playbooks and
uses a simple language called YAML (Yet
Another Markup Language).
15. Install Ansible
Ansible can be installed and run from any machine
Typically you will need a Control machine for installation which
should be Linux.
18. Inventory
An inventory is a text file that contains a list of servers or nodes
that you are managing and configuring. Usually, the servers are
listed based on their hostnames or IP addresses.
You can include anywhere from one to several hundred servers
in your inventory file, and hosts can be organized into groups
and subgroups.
The inventory file is also often used to set variables that will be
valid only for specific hosts or groups, in order to be used within
playbooks and templates.
19. 10.200.50.50
10.200.50.51
10.200.50.52
Alternatively, they can be listed using groups.
[webservers]
10.200.50.60
10.200.50.61
[databases]
20. Playbook
A playbook is a set of configuration management scripts that
define how tasks are to be executed on remote hosts or a group
of host machines. The scripts or instructions are written in YAML
format.
---
- name: This installs and starts Apache webserver
hosts: webservers
tasks:
- name: Install Apache Webserver
yum: name=httpd state=latest
21. Variables
If you have a background in programming, then
most likely you have used variables. Basically, a
variable represents a value. A variable can
include letters, numerals, and underscores but
MUST always begin with letters.
Variables are used when instructions vary from
one system to another. This is especially true
during the configuration or various services and
features.
22. Facts
Facts are system properties gathered by Ansible when it
executes a playbook on a host system. The properties include
hostname, OS family, CPU type, and CPU cores to mention a
few.
ansible localhost -m setup
ansible localhost -m setup -a "filter=*ipv4"