What is Ansible?
Ansible is a configuration management tool in the system administrators/Devops Engineer toolkit that is primarily used to automate the provisioning of servers. It is particularly useful when you have huge amounts of servers to manage as it helps with automating tasks. For example, if you were tasked to update one hundred servers, it would be a pain to update them individually. That is where ansible comes in.
In a typical setup, you would have a Control Node and Managed Nodes. The control node is the machine that has Ansible installed on it. Ansible then allows you to add all the hosts (servers, etc) you want to administer to a special file known as an Inventory file on the control node. The managed nodes are added to the inventory file using either their IP address or FQDN. The managed nodes can also be grouped however you want them in the inventory file for easy referencing when running commands. Some common groupings include by region, by function or by type eg: database servers or web servers.
The power of ansible comes out in the use of Playbooks. Playbooks are configuration files which contain plays. Each play is a set of coded instructions which when called perform some action on a server or group of servers. Playbooks can be used to execute very complicated operations. There are also ad-hoc commands which utilize ansible modules to run simple, sometimes one-line commands. The general idea is that playbooks run complicated actions and ad-hoc commands execute simple actions. See an example of each below:
Playbook example
--- name: update web servers
hosts: webservers
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum:
name: httpd
state: latest
- name: write the apache config file
template:
src: /srv/httpd.j2
dest: /etc/httpd.conf
- name: update db servers
hosts: databases
remote_user: root
tasks:
- name: ensure postgresql is at the latest version
yum:
name: postgresql
state: latest
- name: ensure that postgresql is started
service:
name: postgresql
state: started
ad-hoc command example
ansible [pattern] -m [module] -a "[module options]"
ansible atlanta -a "/sbin/reboot" #where atlanta is the name of a grp of svrs
What is Event-Driven Ansible?
We are already familiar with the terms event-driven programming, event-driven microservices and event-driven architecture. However, the new kid is event-driven Ansible.
Event-Driven Ansible offers a new paradigm in the server automation realm. As its name suggests, it is simply the triggering of an automated action by a predetermined event. This automated action may be defined as multiple plays in a playbook or a simple ad-hoc command.
A simple example of how event-driven Ansible can help System Administrators is in the automating of repetitive tasks such as provisioning additional storage when it falls below a specified threshold (the event).
Event-Driven Ansible is currently in the developer preview and should become widely available in the very near future. One of the major benefits of this tool is its flexibility meaning that it can scale to match the size of your infrastructure. Its modularity also allows for on-the-fly modifications.
Conclusion
Ansible as a tool has been solid in its performance and continued development. The addition of event-driven ansible will only increase its future use.
Top comments (0)