Configuration Management Tool Ansible
Ansible is a powerful configuration management tool that enables organizations to automate the provisioning, configuration, and management of IT infrastructure in a simple, efficient, and consistent manner. It uses a declarative language and follows the Infrastructure as Code (IaC) paradigm, allowing administrators to define infrastructure configurations in human-readable YAML files.
Key features and benefits of Ansible as a configuration management tool include:
Agentless Architecture: Ansible operates in an agentless manner, which means it doesn't require any software to be installed on managed nodes. This simplifies deployment and reduces overhead, making it easy to manage a large number of systems.
Simple and Human-Readable Syntax: Ansible playbooks, written in YAML, are easy to read, write, and understand. This enables infrastructure configurations to be managed efficiently by both system administrators and developers.
Idempotent Execution: Ansible ensures idempotent execution, meaning that running the same playbook multiple times will result in the same desired state, regardless of the initial state of the system. This ensures consistency and predictability in configuration management tasks.
Module-Based Architecture: Ansible provides a wide range of modules that abstract common system administration tasks, such as package management, file manipulation, user management, and service control. These modules can be used to configure various aspects of the infrastructure without the need for custom scripting.
Role-Based Organization: Ansible allows administrators to organize playbooks and tasks into reusable units called roles. Roles promote modularity, code reuse, and maintainability, making it easier to manage complex infrastructure configurations.
Integration and Extensibility: Ansible integrates seamlessly with existing tools, systems, and processes, allowing for easy integration into CI/CD pipelines, monitoring systems, and other automation workflows. Additionally, Ansible's modular architecture makes it extensible, allowing users to develop custom modules and plugins to extend its functionality.
Community and Ecosystem: Ansible benefits from a large and active community of users, contributors, and developers. This vibrant ecosystem provides access to a wealth of pre-built roles, modules, and playbooks through Ansible Galaxy, accelerating development and reducing time to value.
Way of using Ansible.
We can use ansible in 2 ways 1- Control Node/Managed Node 2. Ansible Tower/AWX(UI Based helpful to manage large level organization centrally )
In this blog I will be discussing about 1st way of using ansible where we use to have one control node and from control node we use to push the code to all managed nodes. This way of working with ansible was good for a small organization, but there was a drawback that there was not any history of successful and failed job and admin need to run the playbook login from the control node or using CICD tool.
Now we have a tool called Ansible Semaphore using that we can run our playbook from the UI and can keep track of successful and failed jobs.
Configure Ansible Semaphore on your control node.
Installing Semaphore using Snap
root@master:~# apt install snap
root@master:~# snap install semaphore
root@master:~# snap stop semaphore
Add a admin user to to Login to Semaphore UI
root@master:~# sudo semaphore user add --admin --login amit --name=Amit Chaturvedi --email=test@gmail.com --password=1234
root@master:~# snap start semaphore
Lets Login to Semaphore UI
Use the same username and password we created in the above command
We will land to a page where it will ask to create a new project.
Click on new Project and create a new project
I am keeping my playbooks into github repo
Lets run the playbook from UI
Step-1 Create KeyStore to store credential to clone git repo.
Click on key store
Click on New Key
In Username/Password give PAT created in your Github account
Select the type and create
Step-2 Create Environment
In extra variable I am not passing any variable so keeping it empty
Create The Environment
Step-3 Create Environment
Click on Create Inventory
We have to pass the inventory list like list of managed node
We have 3 types 1) via file 2) static 3) Static yml. I am using file type
Click on create Inventory
Step4: Create Repository where you have kept the code so Semaphore will clone the repo locally
Provide the details and save it
Step-5: Lets create Task Template
Click on Create New Template
Provide the details of your repo, credentials and others
Lets Run the Template and see the magic
Click on Run
If every thing configure properly. Your playbook will run successfully.
Now Click on Dashboard to See the Status
Hope Now you will find how easy to manage ansible using Semaphore