Configuration management tool -Ansible

Ashish Rajbhar
3 min readNov 25, 2020

The kinds of virtual infrastructures that define the cloud computing ecosystem demand a high level of automation. As the number of virtual servers used for individual deployments grows, the complexity of that widely distributed automation grows, too. Ansible, a relative newcomer to the IT automation and orchestration market, offers some unique and compelling features.

Newer than Chef or Puppet, Ansible is the best configuration management, deployment, orchestration open source tool and also automation engine. In fact, it’s included in popular Linux distros such as Fedora. It helps with IT infrastructure automation from software provisioning and configuration management to application deployment, providing large productivity gains.

Besides resource provisioning and configuration management, Ansible can also orchestrate complex sequences of events like rolling upgrades and zero-downtime provisioning in a simple or multi-tier application environment. The power of Ansible is not limited to managing servers: it also can manage network switches, firewalls, and load balancers. Ansible has been designed to work seamlessly within cloud environments like AWS, VMWare, and Microsoft Azure.

Ansible Architecture

Ansible architecture is fairly straightforward. Refer to the diagram below to understand the Ansible architecture:

As you can see, in the diagram above, the Ansible automation engine has a direct interaction with the users who write playbooks to execute the Ansible Automation engine. It also interacts with cloud services and Configuration Management Database (CMDB).

Ansible in DevOps

In DevOps, as we know development and operations work is integrated. This integration is very important for modern test-driven application design. Hence, Ansible integrates this by providing a stable environment to both development and operations resulting in smooth orchestration. Refer to the image below to see how Ansible fits into DevOps:

Pros

  1. Simple/Easy-to-Learn.

2. Agentless.

3. YAML-Based Playbooks

4. Ansible Galaxy.

Cons.

  1. UI is Lacking.

2. No Notion of State.

3. Minimal Enterprise Support Experience.

10 Useful Commands of AWS

1. Delete an S3 bucket and all its contents with just one command

aws s3 rb s3://bucket-name –force

2. Recursively copy a directory and its subfolders from your PC to Amazon S3

aws s3 cp MyFolder s3://bucket-name — recursive [–region us-west-2]

3. Display subsets of all available ec2 images

aws ec2 describe-images | grep ubuntu

Warning: this may take a few minutes.

4. List users in a different format

aws iam list-users –output table

5. List the sizes of an S3 bucket and its contents

aws s3api list-objects --bucket BUCKETNAME --output json --query "[sum(Contents[].Size), length(Contents[])]"

6. Move S3 bucket to a different location

aws s3 sync s3://oldbucket s3://newbucket --source-region us-west-1 --region us-west-2

7. List users by ARN

aws iam list-users –output json | jq -r .Users[].Arn

8. List all of your instances that are currently stopped and the reason for the stop

aws ec2 describe-instances --filters Name=instance-state-name,Values=stopped --region eu-west-1 --output json | jq -r .Reservations[].Instances[].StateReason.Message

9. Test one of your public CloudFormation templates

aws cloudformation validate-template --region eu-west-1 --template-url https://s3-eu-west-1.amazonaws.com/ca/ca.cftemplate

10. Other ways to pass input parameters to the AWS CLI with JSON:

aws iam put-user-policy --user-name AWS-Cli-Test --policy-name Power-Access --policy-document '{ "Statement": [ { "Effect": "Allow", "NotAction": "iam:*", "Resource": "*" } ] }'

--

--